-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Fix --config-from creation of swarm networks #49521
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
Conversation
1cedccd to
1022118
Compare
1022118 to
499fab8
Compare
integration/internal/network/ops.go
Outdated
| // WithScopeSwarm gives the network swarm scope. | ||
| func WithScopeSwarm() func(*network.CreateOptions) { | ||
| return func(n *network.CreateOptions) { | ||
| n.Scope = scope.Swarm |
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.
Mostly nit, because this is internal and test-utils, but wondered if WithScope(name) would be useful in case we'd need other scopes
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.
Done.
| defer func() { | ||
| if retErr == nil && !skipCfgEpCount { | ||
| if err := configNetwork.getEpCnt().IncEndpointCnt(); err != nil { | ||
| log.G(context.TODO()).Warnf("Failed to update reference count for configuration network %q on creation of network %q: %v", configNetwork.Name(), nw.name, err) |
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.
Perhaps WithFields() for the network name(s) and error?
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.
Oh, never mind, this is just moving an existing log, so out of scope for this PR probably (we can look in a follow-up)
| if n.ipamType != "" && | ||
| n.ipamType != defaultIpamForNetworkType(n.networkType) || | ||
| n.enableIPv4 || n.enableIPv6 || | ||
| !n.enableIPv4 || n.enableIPv6 || |
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.
This could benefit from a short blurb / comment perhaps (I think this is because enableIPv4 = true is the default for IPv4, but enableIPv6 = false is the default for IPv6, so this checks if any of the defaults are changed?
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.
I've added some blurb - hopefully it fits the bill?
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.
Thanks! Yes, I think "anything" is good; as long as it makes clear "it's not a typo that one is ! and the other one isn't; I initially thought to put it on the line itself, but not sure if Go would allow that because it's a multi-line "if" condition.
499fab8 to
a819d07
Compare
thaJeztah
left a comment
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.
LGTM
@akerouanton ptal
For swarm networks, Controller.NewNetwork is called to validate network config ... nothing gets created, but ManagerRedirectError is returned if the config is ok - then swarm does its own thing. So, for a --config-from network, merge config before checking whether it'll have IPv4 enabled. Signed-off-by: Rob Murray <[email protected]>
Creating a swarm network from a config-only network failed
because the new EnableIPv4 wasn't validated/propagated
correctly.
So:
- Always initialise EnableIPv4 to true, including for a config
only network, and on load from the store.
- Treat enableIPv4=true as the no-overridden state when checking
params for a config-from network.
- Propagate settings from the config 'Network' objects attributes
to its generic options, because the network driver only sees
generic options.
- This was happening already for Network.internal, after the
config-only network options were processed. Move that to
'applyConfigurationTo'.
- Add enableIPv4/enableIpv6 - enableIPv6 will normaly be present
anyway. But, for a network created pre-28.x and restored from
the store, there was no entry for 'netlabel.EnableIpv4'.
- Extend TestSwarmScopedNetFromConfig to start a service and
check it's ok.
Signed-off-by: Rob Murray <[email protected]>
a819d07 to
468c2c8
Compare
- What I did
- How I did it
Fix swarm net validation for config-from networks
For swarm networks, Controller.NewNetwork is called to validate network config ... nothing gets created, but
ManagerRedirectErroris returned if the config is ok - then swarm does its own thing.So, for a
--config-fromnetwork, merge config before checking whether it'll have IPv4 enabled.Fix swarm network creation from a config-only network
Creating a swarm network from a config-only network failed because the new EnableIPv4 wasn't validated/propagated correctly.
So:
'applyConfigurationTo'.
- How to verify it
New test
TestSwarmScopedNetFromConfigcreates a swarm network from a--config-onlynetwork (fails without the first commit), and starts a service using it (fails without the second commit).Also, created a config-from network using 27.5.1, upgraded to 28.0.0 to check it didn't work, upgraded to a dev build based on this PR and it started normally.
- Human readable description for the release notes