don't check external network existence when swarm is enabled

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2024-01-25 15:56:31 +01:00 committed by Guillaume Lours
parent cdb6eb55d5
commit da1a34a8f2

View File

@ -1246,20 +1246,17 @@ func (s *composeService) resolveExternalNetwork(ctx context.Context, n *types.Ne
n.Name = networks[0].ID n.Name = networks[0].ID
return nil return nil
case 0: case 0:
if n.Driver == "overlay" {
// Swarm nodes do not register overlay networks that were
// created on a different node unless they're in use.
// Here we assume `driver` is relevant for a network we don't manage
// which is a non-sense, but this is our legacy ¯\(ツ)/¯
// networkAttach will later fail anyway if network actually doesn't exists
enabled, err := s.isSWarmEnabled(ctx) enabled, err := s.isSWarmEnabled(ctx)
if err != nil { if err != nil {
return err return err
} }
if enabled { if enabled {
// Swarm nodes do not register overlay networks that were
// created on a different node unless they're in use.
// So we can't preemptively check network exists, but
// networkAttach will later fail anyway if network actually doesn't exists
return nil return nil
} }
}
return fmt.Errorf("network %s declared as external, but could not be found", n.Name) return fmt.Errorf("network %s declared as external, but could not be found", n.Name)
default: default:
return fmt.Errorf("multiple networks with name %q were found. Use network ID as `name` to avoid ambiguity", n.Name) return fmt.Errorf("multiple networks with name %q were found. Use network ID as `name` to avoid ambiguity", n.Name)