Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@robmry
Copy link
Contributor

@robmry robmry commented Feb 22, 2025

- 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 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.

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:

  • 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'.

- How to verify it

New test TestSwarmScopedNetFromConfig creates a swarm network from a --config-only network (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

Fix creation of a swarm-scoped network from a `--config-only` network.

@robmry robmry added this to the 28.0.1 milestone Feb 22, 2025
@robmry robmry self-assigned this Feb 22, 2025
@robmry robmry force-pushed the swarm_net_from_config branch from 1cedccd to 1022118 Compare February 22, 2025 19:27
@robmry robmry marked this pull request as ready for review February 22, 2025 19:27
@robmry robmry force-pushed the swarm_net_from_config branch from 1022118 to 499fab8 Compare February 22, 2025 20:16
Comment on lines 75 to 78
// WithScopeSwarm gives the network swarm scope.
func WithScopeSwarm() func(*network.CreateOptions) {
return func(n *network.CreateOptions) {
n.Scope = scope.Swarm
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Member

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)

Comment on lines -378 to +381
if n.ipamType != "" &&
n.ipamType != defaultIpamForNetworkType(n.networkType) ||
n.enableIPv4 || n.enableIPv6 ||
!n.enableIPv4 || n.enableIPv6 ||
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@robmry robmry force-pushed the swarm_net_from_config branch from 499fab8 to a819d07 Compare February 24, 2025 17:37
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

@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]>
@robmry robmry force-pushed the swarm_net_from_config branch from a819d07 to 468c2c8 Compare February 24, 2025 17:48
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.

Swarm scoped from config networks broken

4 participants