-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Don't sort plugin mounts slice #36711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't sort plugin mounts slice
This was added as part of a53930a with the intent to sort the mounts in the plugin config, but this was sorting *all* the mounts from the default OCI spec which is problematic. In reality we don't need to sort this because we are only adding a self-binded mount to flag it as rshared. We may want to look at sorting the plugin mounts before they are added to the OCI spec in the future, but for now I think the existing behavior is fine since the plugin author has control of the order (except for the propagated mount). Signed-off-by: Brian Goff <cpuguy83@gmail.com>
- Loading branch information
commit ec90839ca302ca53a7d55e4c7f79e7b4779f5e15
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| package cmd |
This file contains hidden or 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,19 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "net" | ||
| "net/http" | ||
| ) | ||
|
|
||
| func main() { | ||
| l, err := net.Listen("unix", "/run/docker/plugins/plugin.sock") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| server := http.Server{ | ||
| Addr: l.Addr().String(), | ||
| Handler: http.NewServeMux(), | ||
| } | ||
| server.Serve(l) | ||
| } |
This file contains hidden or 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 @@ | ||
| package main |
This file contains hidden or 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,73 @@ | ||
| package volumes | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/docker/docker/api/types" | ||
| "github.com/docker/docker/integration-cli/fixtures/plugin" | ||
| "github.com/docker/docker/pkg/locker" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| var pluginBuildLock = locker.New() | ||
|
|
||
| // ensurePlugin makes the that a plugin binary has been installed on the system. | ||
| // Plugins that have not been installed are built from `cmd/<name>`. | ||
| func ensurePlugin(t *testing.T, name string) string { | ||
| pluginBuildLock.Lock(name) | ||
| defer pluginBuildLock.Unlock(name) | ||
|
|
||
| goPath := os.Getenv("GOPATH") | ||
| if goPath == "" { | ||
| goPath = "/go" | ||
| } | ||
| installPath := filepath.Join(goPath, "bin", name) | ||
| if _, err := os.Stat(installPath); err == nil { | ||
| return installPath | ||
| } | ||
|
|
||
| goBin, err := exec.LookPath("go") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| cmd := exec.Command(goBin, "build", "-o", installPath, "./"+filepath.Join("cmd", name)) | ||
| cmd.Env = append(cmd.Env, "CGO_ENABLED=0") | ||
| if out, err := cmd.CombinedOutput(); err != nil { | ||
| t.Fatal(errors.Wrapf(err, "error building basic plugin bin: %s", string(out))) | ||
| } | ||
|
|
||
| return installPath | ||
| } | ||
|
|
||
| func withSockPath(name string) func(*plugin.Config) { | ||
| return func(cfg *plugin.Config) { | ||
| cfg.Interface.Socket = name | ||
| } | ||
| } | ||
|
|
||
| func createPlugin(t *testing.T, client plugin.CreateClient, alias, bin string, opts ...plugin.CreateOpt) { | ||
| pluginBin := ensurePlugin(t, bin) | ||
|
|
||
| opts = append(opts, withSockPath("plugin.sock")) | ||
| opts = append(opts, plugin.WithBinary(pluginBin)) | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
| err := plugin.Create(ctx, client, alias, opts...) | ||
| cancel() | ||
|
|
||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| func asVolumeDriver(cfg *plugin.Config) { | ||
| cfg.Interface.Types = []types.PluginInterfaceType{ | ||
| {Capability: "volumedriver", Prefix: "docker", Version: "1.0"}, | ||
| } | ||
| } |
This file contains hidden or 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,34 @@ | ||
| package volumes // import "github.com/docker/docker/integration/plugin/volumes" | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/docker/docker/internal/test/environment" | ||
| ) | ||
|
|
||
| var ( | ||
| testEnv *environment.Execution | ||
| ) | ||
|
|
||
| const dockerdBinary = "dockerd" | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| var err error | ||
| testEnv, err = environment.New() | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| os.Exit(1) | ||
| } | ||
| if testEnv.OSType != "linux" { | ||
| os.Exit(0) | ||
| } | ||
| err = environment.EnsureFrozenImagesLinux(testEnv) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| os.Exit(1) | ||
| } | ||
| testEnv.Print() | ||
| os.Exit(m.Run()) | ||
| } |
This file contains hidden or 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,56 @@ | ||
| package volumes | ||
|
|
||
| import ( | ||
| "context" | ||
| "io/ioutil" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/docker/docker/api/types" | ||
| "github.com/docker/docker/integration-cli/daemon" | ||
| "github.com/docker/docker/integration-cli/fixtures/plugin" | ||
| "github.com/gotestyourself/gotestyourself/assert" | ||
| ) | ||
|
|
||
| // TestPluginWithDevMounts tests very specific regression caused by mounts ordering | ||
| // (sorted in the daemon). See #36698 | ||
| func TestPluginWithDevMounts(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| d := daemon.New(t, "", dockerdBinary, daemon.Config{}) | ||
| d.Start(t, "--iptables=false") | ||
| defer d.Stop(t) | ||
|
|
||
| client, err := d.NewClient() | ||
| assert.Assert(t, err) | ||
| ctx := context.Background() | ||
|
|
||
| testDir, err := ioutil.TempDir("", "test-dir") | ||
| assert.Assert(t, err) | ||
| defer os.RemoveAll(testDir) | ||
|
|
||
| createPlugin(t, client, "test", "dummy", asVolumeDriver, func(c *plugin.Config) { | ||
| root := "/" | ||
| dev := "/dev" | ||
| mounts := []types.PluginMount{ | ||
| {Type: "bind", Source: &root, Destination: "/host", Options: []string{"rbind"}}, | ||
| {Type: "bind", Source: &dev, Destination: "/dev", Options: []string{"rbind"}}, | ||
| {Type: "bind", Source: &testDir, Destination: "/etc/foo", Options: []string{"rbind"}}, | ||
| } | ||
| c.PluginConfig.Mounts = append(c.PluginConfig.Mounts, mounts...) | ||
| c.PropagatedMount = "/propagated" | ||
| c.Network = types.PluginConfigNetwork{Type: "host"} | ||
| c.IpcHost = true | ||
| }) | ||
|
|
||
| err = client.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30}) | ||
| assert.Assert(t, err) | ||
| defer func() { | ||
| err := client.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true}) | ||
| assert.Check(t, err) | ||
| }() | ||
|
|
||
| p, _, err := client.PluginInspectWithRaw(ctx, "test") | ||
| assert.Assert(t, err) | ||
| assert.Assert(t, p.Enabled) | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my clarification: So including the OCI defaults in the sort was overwriting the explicit
/devmounts from the plugin with the OCI defaults? Even so, how did it mess up the host/dev?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's adding things like a custom /dev/pts for the plugin, but if the host /dev is mounted in first this causes issues.