report external network not found when swarm is disabled
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
fd7847f2ac
commit
00f72cb553
@ -24,6 +24,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/distribution/distribution/v3/reference"
|
"github.com/distribution/distribution/v3/reference"
|
||||||
@ -33,6 +34,7 @@ import (
|
|||||||
"github.com/docker/cli/cli/streams"
|
"github.com/docker/cli/cli/streams"
|
||||||
moby "github.com/docker/docker/api/types"
|
moby "github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -262,3 +264,23 @@ func (s *composeService) actualNetworks(ctx context.Context, projectName string)
|
|||||||
}
|
}
|
||||||
return actual, nil
|
return actual, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var swarmEnabled = struct {
|
||||||
|
once sync.Once
|
||||||
|
val bool
|
||||||
|
err error
|
||||||
|
}{}
|
||||||
|
|
||||||
|
func (s *composeService) isSWarmEnabled(ctx context.Context) (bool, error) {
|
||||||
|
swarmEnabled.once.Do(func() {
|
||||||
|
info, err := s.apiClient().Info(ctx)
|
||||||
|
if err != nil {
|
||||||
|
swarmEnabled.err = err
|
||||||
|
}
|
||||||
|
if info.Swarm.LocalNodeState == swarm.LocalNodeStateInactive {
|
||||||
|
swarmEnabled.val = info.Swarm.LocalNodeState == swarm.LocalNodeStateInactive
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return swarmEnabled.val, swarmEnabled.err
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1103,8 +1103,14 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi
|
|||||||
// Here we assume `driver` is relevant for a network we don't manage
|
// Here we assume `driver` is relevant for a network we don't manage
|
||||||
// which is a non-sense, but this is our legacy ¯\(ツ)/¯
|
// which is a non-sense, but this is our legacy ¯\(ツ)/¯
|
||||||
// networkAttach will later fail anyway if network actually doesn't exists
|
// networkAttach will later fail anyway if network actually doesn't exists
|
||||||
|
enabled, err := s.isSWarmEnabled(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if enabled {
|
||||||
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)
|
||||||
}
|
}
|
||||||
var ipam *network.IPAM
|
var ipam *network.IPAM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user