This repository has been archived by the owner on Jun 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from ibuildthecloud/new-net
Delete unneeded code in new networking design
- Loading branch information
Showing
21 changed files
with
153 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// +build linux freebsd solaris openbsd darwin | ||
|
||
package compute | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/client" | ||
) | ||
|
||
// This approach was adopted from Weave's weaveproxy component. Proper credit goes to them. | ||
|
||
var ( | ||
waitProg = "/.r/r" | ||
waitVolume = "rancher-cni" | ||
waitVolumeTarget = "/.r" | ||
) | ||
|
||
func modifyForCNI(c *client.Client, container *container.Config, hostConfig *container.HostConfig) error { | ||
if container.Labels[cniWaitLabel] != "true" { | ||
return nil | ||
} | ||
if err := setWaitEntrypoint(c, container); err != nil { | ||
return err | ||
} | ||
return setWaitVolume(hostConfig, waitVolume, waitVolumeTarget, "ro") | ||
} | ||
|
||
func setWaitVolume(hostConfig *container.HostConfig, source, target, mode string) error { | ||
var binds []string | ||
for _, bind := range hostConfig.Binds { | ||
s := strings.Split(bind, ":") | ||
if len(s) >= 2 && s[1] == target { | ||
continue | ||
} | ||
binds = append(binds, bind) | ||
} | ||
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s:%s:%s", source, target, mode)) | ||
return nil | ||
} | ||
|
||
func setWaitEntrypoint(c *client.Client, container *container.Config) error { | ||
if len(container.Entrypoint) == 0 { | ||
image, _, err := c.ImageInspectWithRaw(context.Background(), container.Image) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(container.Cmd) == 0 { | ||
container.Cmd = image.Config.Cmd | ||
} | ||
|
||
if container.Entrypoint == nil { | ||
container.Entrypoint = image.Config.Entrypoint | ||
} | ||
} | ||
|
||
if len(container.Entrypoint) == 0 && len(container.Cmd) == 0 { | ||
// No command, just let docker complain about it on start | ||
return nil | ||
} | ||
|
||
if len(container.Entrypoint) == 0 || container.Entrypoint[0] != waitProg { | ||
container.Entrypoint = append(container.Entrypoint, waitProg) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.