Skip to content

Commit 571af91

Browse files
committed
Don't enforce new validation rules for existing networks
Non-swarm networks created before network-creation-time validation was added in 25.0.0 continued working, because the checks are not re-run. But, swarm creates networks when needed (with 'agent=true'), to ensure they exist on each agent - ignoring the NetworkNameError that says the network already existed. By ignoring validation errors on creation of a network with agent=true, pre-existing swarm networks with IPAM config that would fail the new checks will continue to work too. New swarm (overlay) networks are still validated, because they are initially created with 'agent=false'. Signed-off-by: Rob Murray <rob.murray@docker.com>
1 parent 9e075f3 commit 571af91

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

daemon/network.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,27 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
332332
}
333333

334334
if err := network.ValidateIPAM(create.IPAM, create.EnableIPv6); err != nil {
335-
return nil, errdefs.InvalidParameter(err)
335+
if agent {
336+
// This function is called with agent=false for all networks. For swarm-scoped
337+
// networks, the configuration is validated but ManagerRedirectError is returned
338+
// and the network is not created. Then, each time a swarm-scoped network is
339+
// needed, this function is called again with agent=true.
340+
//
341+
// Non-swarm networks created before ValidateIPAM was introduced continue to work
342+
// as they did before-upgrade, even if they would fail the new checks on creation
343+
// (for example, by having host-bits set in their subnet). Those networks are not
344+
// seen again here.
345+
//
346+
// By dropping errors for agent networks, existing swarm-scoped networks also
347+
// continue to behave as they did before upgrade - but new networks are still
348+
// validated.
349+
log.G(context.TODO()).WithFields(log.Fields{
350+
"error": err,
351+
"network": create.Name,
352+
}).Warn("Continuing with validation errors in agent IPAM")
353+
} else {
354+
return nil, errdefs.InvalidParameter(err)
355+
}
336356
}
337357

338358
if create.IPAM != nil {

0 commit comments

Comments
 (0)