Skip to content

Commit

Permalink
Accumulate driver opts with the same key in "docker network connect"
Browse files Browse the repository at this point in the history
Similar to the "--network driver-opt=", accumulate options with the
same label in "docker network connect --driver-opt=".

Signed-off-by: Rob Murray <rob.murray@docker.com>
  • Loading branch information
robmry committed May 8, 2024
1 parent 30102bb commit 8570197
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cli/command/filename
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "dTA6cDA="
},
"server1.io": {
"auth": "dTE6cDE="
}
}
}
6 changes: 5 additions & 1 deletion cli/command/network/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func convertDriverOpt(options []string) (map[string]string, error) {
if !ok || k == "" {
return nil, fmt.Errorf("invalid key/value pair format in driver options")
}
driverOpt[k] = strings.TrimSpace(v)
v = strings.TrimSpace(v)
if oldval, ok := driverOpt[k]; ok {
v = oldval + "," + v
}
driverOpt[k] = v
}
return driverOpt, nil
}
7 changes: 5 additions & 2 deletions cli/command/network/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func TestNetworkConnectWithFlags(t *testing.T) {
Links: []string{"otherctr"},
Aliases: []string{"poor-yorick"},
DriverOpts: map[string]string{
"adriveropt": "anoptval",
"driveropt1": "optval1,optval2",
"driveropt2": "optval3",
},
}
cli := test.NewFakeCli(&fakeClient{
Expand All @@ -67,7 +68,9 @@ func TestNetworkConnectWithFlags(t *testing.T) {
cmd.SetArgs(args)
for _, opt := range []struct{ name, value string }{
{"alias", "poor-yorick"},
{"driver-opt", "adriveropt=anoptval"},
{"driver-opt", "driveropt1=optval1"},
{"driver-opt", "driveropt1=optval2"},
{"driver-opt", "driveropt2=optval3"},
{"ip", "192.168.4.1"},
{"ip6", "fdef:f401:8da0:1234::5678"},
{"link", "otherctr"},
Expand Down

0 comments on commit 8570197

Please sign in to comment.