Skip to content

Commit 9d15415

Browse files
authored
Merge pull request moby#47361 from robmry/47331_swarm_ipam_validation
Don't enforce new validation rules for existing networks
2 parents 7bf8d26 + a26c953 commit 9d15415

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

api/server/router/network/network_routes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
213213
return libnetwork.NetworkNameError(create.Name)
214214
}
215215

216+
// For a Swarm-scoped network, this call to backend.CreateNetwork is used to
217+
// validate the configuration. The network will not be created but, if the
218+
// configuration is valid, ManagerRedirectError will be returned and handled
219+
// below.
216220
nw, err := n.backend.CreateNetwork(create)
217221
if err != nil {
218222
if _, ok := err.(libnetwork.ManagerRedirectError); !ok {

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)