network create: make --ipv6 optional

The API field `EnableIPv6` was marked as optional in our Swagger docs,
and its default value in the Go client came from that field being a
bool, thus defaulting to its zero value. That's not the case anymore.

This field is now a `*bool` as to let daemon's config define the default
value. IPv6 can still be enabled / disabled by explicitly specifying the
`--ipv6` flag when doing `docker network create`.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
Albin Kerouanton 2024-06-06 21:02:49 +02:00
parent 0ed8a7e310
commit db2672e685
2 changed files with 11 additions and 5 deletions

View File

@ -23,7 +23,7 @@ type createOptions struct {
driverOpts opts.MapOpts driverOpts opts.MapOpts
labels opts.ListOpts labels opts.ListOpts
internal bool internal bool
ipv6 bool ipv6 *bool
attachable bool attachable bool
ingress bool ingress bool
configOnly bool configOnly bool
@ -38,6 +38,7 @@ type createOptions struct {
} }
func newCreateCommand(dockerCli command.Cli) *cobra.Command { func newCreateCommand(dockerCli command.Cli) *cobra.Command {
var ipv6 bool
options := createOptions{ options := createOptions{
driverOpts: *opts.NewMapOpts(nil, nil), driverOpts: *opts.NewMapOpts(nil, nil),
labels: opts.NewListOpts(opts.ValidateLabel), labels: opts.NewListOpts(opts.ValidateLabel),
@ -51,6 +52,11 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
Args: cli.ExactArgs(1), Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
options.name = args[0] options.name = args[0]
if cmd.Flag("ipv6").Changed {
options.ipv6 = &ipv6
}
return runCreate(cmd.Context(), dockerCli, options) return runCreate(cmd.Context(), dockerCli, options)
}, },
ValidArgsFunction: completion.NoComplete, ValidArgsFunction: completion.NoComplete,
@ -61,7 +67,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options") flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options")
flags.Var(&options.labels, "label", "Set metadata on a network") flags.Var(&options.labels, "label", "Set metadata on a network")
flags.BoolVar(&options.internal, "internal", false, "Restrict external access to the network") flags.BoolVar(&options.internal, "internal", false, "Restrict external access to the network")
flags.BoolVar(&options.ipv6, "ipv6", false, "Enable IPv6 networking") flags.BoolVar(&ipv6, "ipv6", false, "Enable or disable IPv6 networking")
flags.BoolVar(&options.attachable, "attachable", false, "Enable manual container attachment") flags.BoolVar(&options.attachable, "attachable", false, "Enable manual container attachment")
flags.SetAnnotation("attachable", "version", []string{"1.25"}) flags.SetAnnotation("attachable", "version", []string{"1.25"})
flags.BoolVar(&options.ingress, "ingress", false, "Create swarm routing-mesh network") flags.BoolVar(&options.ingress, "ingress", false, "Create swarm routing-mesh network")
@ -107,7 +113,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
Options: options.ipamOpt.GetAll(), Options: options.ipamOpt.GetAll(),
}, },
Internal: options.internal, Internal: options.internal,
EnableIPv6: &options.ipv6, EnableIPv6: options.ipv6,
Attachable: options.attachable, Attachable: options.attachable,
Ingress: options.ingress, Ingress: options.ingress,
Scope: options.scope, Scope: options.scope,

View File

@ -18,7 +18,7 @@ Create a network
| `--ip-range` | `stringSlice` | | Allocate container ip from a sub-range | | `--ip-range` | `stringSlice` | | Allocate container ip from a sub-range |
| `--ipam-driver` | `string` | `default` | IP Address Management Driver | | `--ipam-driver` | `string` | `default` | IP Address Management Driver |
| `--ipam-opt` | `map` | `map[]` | Set IPAM driver specific options | | `--ipam-opt` | `map` | `map[]` | Set IPAM driver specific options |
| `--ipv6` | | | Enable IPv6 networking | | `--ipv6` | | | Enable or disable IPv6 networking |
| `--label` | `list` | | Set metadata on a network | | `--label` | `list` | | Set metadata on a network |
| `-o`, `--opt` | `map` | `map[]` | Set driver specific options | | `-o`, `--opt` | `map` | `map[]` | Set driver specific options |
| `--scope` | `string` | | Control the network's scope | | `--scope` | `string` | | Control the network's scope |
@ -170,7 +170,7 @@ flags used for the docker0 bridge:
| `--gateway` | - | IPv4 or IPv6 Gateway for the master subnet | | `--gateway` | - | IPv4 or IPv6 Gateway for the master subnet |
| `--ip-range` | `--fixed-cidr` | Allocate IPs from a range | | `--ip-range` | `--fixed-cidr` | Allocate IPs from a range |
| `--internal` | - | Restrict external access to the network | | `--internal` | - | Restrict external access to the network |
| `--ipv6` | `--ipv6` | Enable IPv6 networking | | `--ipv6` | `--ipv6` | Enable or disable IPv6 networking |
| `--subnet` | `--bip` | Subnet for network | | `--subnet` | `--bip` | Subnet for network |
For example, let's use `-o` or `--opt` options to specify an IP address binding For example, let's use `-o` or `--opt` options to specify an IP address binding