Skip to content
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

network create: make --ipv6 optional #5126

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

akerouanton
Copy link
Member

@akerouanton akerouanton commented Jun 6, 2024

- What I did

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.

- How to verify it

Start a daemon from moby/moby master branch:

$ ./build/docker-darwin-arm64 network create testnet
$ docker network inspect --format='{{ (index .IPAM.Config) }}' testnet
[{172.20.0.0/16  172.20.0.1 map[]}]

$ ./build/docker-darwin-arm64 network create --ipv6 testnetv6
$ docker network inspect --format='{{ (index .IPAM.Config) }}' testnetv6
[{172.19.0.0/16  172.19.0.1 map[]} {fdbc:8ec0:bb64::/64  fdbc:8ec0:bb64::1/64 map[]}]

Then restart the daemon with --default-network-opt=bridge=com.docker.network.enable_ipv6=true:

$ ./build/docker-darwin-arm64 network create testnetv6
$ docker network inspect --format='{{ (index .IPAM.Config) }}' testnetv6
[{172.20.0.0/16  172.20.0.1 map[]} {fd8c:5815:be1a::/64  fd8c:5815:be1a::1/64 map[]}]

$ ./build/docker-darwin-arm64 network create --ipv6=false testnet
$ docker network inspect --format='{{ (index .IPAM.Config) }}' testnet
[{172.19.0.0/16  172.19.0.1 map[]}]

- A picture of a cute animal (not mandatory but encouraged)

- api: Make EnableIPv6 optional

full diff: moby/moby@c6aaabc...00f18ef

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 61.34%. Comparing base (9b61bbb) to head (db2672e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5126      +/-   ##
==========================================
- Coverage   61.37%   61.34%   -0.03%     
==========================================
  Files         298      295       -3     
  Lines       20717    20714       -3     
==========================================
- Hits        12715    12707       -8     
- Misses       7102     7104       +2     
- Partials      900      903       +3     

cli/command/network/create.go Outdated Show resolved Hide resolved
cli/command/network/create.go Outdated Show resolved Hide resolved
@@ -61,7 +69,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options")
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.ipv6, "ipv6", false, "Enable IPv6 networking")
flags.BoolVar(options.ipv6, "ipv6", false, "Enable IPv6 networking")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL perhaps we need to create our own "optional bool" so that we could have nil as default. 🤔

Perhaps the flag-description should be updated though; something like "auto" (or "determined by daemon"?);

Suggested change
flags.BoolVar(options.ipv6, "ipv6", false, "Enable IPv6 networking")
flags.BoolVar(options.ipv6, "ipv6", false, "Enable or disable IPv6 networking (default is auto)")

or should we consider the default to be "true"?

Suggested change
flags.BoolVar(options.ipv6, "ipv6", false, "Enable IPv6 networking")
flags.BoolVar(options.ipv6, "ipv6", true, "Enable or disable IPv6 networking (default is enabled, if supported)")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or should we consider the default to be "true"?

I think we shouldn't do that, at least for now. One reason is the discussion we had regarding ip6tables. Another reason, IPv6 isn't supported by all drivers currently (eg. overlay).

If we want to enable IPv6 by default, I think it'd need to be done at the API level, in a new API version.

Comment on lines 57 to 58
f := cmd.Flag("ipv6")
if !f.Changed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f := cmd.Flag("ipv6")
if !f.Changed {
if !cmd.Flag("ipv6").Changed {

or (not sure which one is more performant, but probably won't matter much)

Suggested change
f := cmd.Flag("ipv6")
if !f.Changed {
if !cmd.Flags().Changed("ipv6") {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually; would the reverse work? I see you have the var ipv6 bool added; that one could be set on the flag;

And this code could then do;

if cmd.Flag("ipv6").Changed {
	options.ipv6 = &ipv6
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose cmd.Flag("ipv6").Changed instead of cmd.Flags().Changed("ipv6") as the former will trigger a panic if the flag is renamed / removed, whereas the latter will silently fail (ie. return false).

cli/command/network/create.go Outdated Show resolved Hide resolved
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>
@akerouanton akerouanton requested a review from a team as a code owner June 7, 2024 01:17
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah
Copy link
Member

The only thing I'm wondering is if we need to add more details about what the default is, but we can do in a follow-up.

@thaJeztah thaJeztah merged commit 9683d06 into docker:master Jun 7, 2024
88 checks passed
@akerouanton akerouanton deleted the network-create-ipv6 branch June 7, 2024 08:10
@akerouanton
Copy link
Member Author

@thaJeztah Sorry for the 1st version of this patch, it was crap. I should stop multi-tasking sometimes 😓

The only thing I'm wondering is if we need to add more details about what the default is, but we can do in a follow-up.

I think we need to update the documentation to explain how to set the default daemon-wide, how to disable ipv6 for a specific network, etc... but that's pretty much it. Do you have anything else in mind?

FWIW, we discussed docs updates a bit with @robmry and we decided to wait for at least the rc1 to start working on that -- we'd like to get every PR ready first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants