Skip to content

Commit e3f4842

Browse files
committed
Use ListOpt for docker network create --label and docker volume create --label
This fix is related to 27049 and 27047. For `--label` flag, if string slice is used (like 27047), then quote can not be used in command and will result in an error : ``` line 1, column 14: bare " in non-quoted-field ``` The issue 27047 has been fixed by 27049. Recently I found out that both `docker network create --label` and `docker volume create --label` still use string slice and will return the same error when quotes are used. This fix fixes `docker network create --label` and `docker volume create --label` by using `ListOpt` (as 27049) as well. This fix has been tested and verified manually. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
1 parent 32f93fd commit e3f4842

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cli/command/network/create.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type createOptions struct {
2020
name string
2121
driver string
2222
driverOpts opts.MapOpts
23-
labels []string
23+
labels opts.ListOpts
2424
internal bool
2525
ipv6 bool
2626
attachable bool
@@ -36,6 +36,7 @@ type createOptions struct {
3636
func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
3737
opts := createOptions{
3838
driverOpts: *opts.NewMapOpts(nil, nil),
39+
labels: opts.NewListOpts(runconfigopts.ValidateEnv),
3940
ipamAux: *opts.NewMapOpts(nil, nil),
4041
ipamOpt: *opts.NewMapOpts(nil, nil),
4142
}
@@ -53,7 +54,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
5354
flags := cmd.Flags()
5455
flags.StringVarP(&opts.driver, "driver", "d", "bridge", "Driver to manage the Network")
5556
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
56-
flags.StringSliceVar(&opts.labels, "label", []string{}, "Set metadata on a network")
57+
flags.Var(&opts.labels, "label", "Set metadata on a network")
5758
flags.BoolVar(&opts.internal, "internal", false, "Restrict external access to the network")
5859
flags.BoolVar(&opts.ipv6, "ipv6", false, "Enable IPv6 networking")
5960
flags.BoolVar(&opts.attachable, "attachable", false, "Enable manual container attachment")
@@ -90,7 +91,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
9091
Internal: opts.internal,
9192
EnableIPv6: opts.ipv6,
9293
Attachable: opts.attachable,
93-
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels),
94+
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()),
9495
}
9596

9697
resp, err := client.NetworkCreate(context.Background(), opts.name, nc)

cli/command/volume/create.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ type createOptions struct {
1717
name string
1818
driver string
1919
driverOpts opts.MapOpts
20-
labels []string
20+
labels opts.ListOpts
2121
}
2222

2323
func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
2424
opts := createOptions{
2525
driverOpts: *opts.NewMapOpts(nil, nil),
26+
labels: opts.NewListOpts(runconfigopts.ValidateEnv),
2627
}
2728

2829
cmd := &cobra.Command{
@@ -46,7 +47,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
4647
flags.StringVar(&opts.name, "name", "", "Specify volume name")
4748
flags.Lookup("name").Hidden = true
4849
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
49-
flags.StringSliceVar(&opts.labels, "label", []string{}, "Set metadata for a volume")
50+
flags.Var(&opts.labels, "label", "Set metadata for a volume")
5051

5152
return cmd
5253
}
@@ -58,7 +59,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
5859
Driver: opts.driver,
5960
DriverOpts: opts.driverOpts.GetAll(),
6061
Name: opts.name,
61-
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels),
62+
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()),
6263
}
6364

6465
vol, err := client.VolumeCreate(context.Background(), volReq)

0 commit comments

Comments
 (0)