mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #26585 from yongtang/24538-better-error-remove-internal-networks
Improve error message for removing pre-defined (e.g., `ingress`) network
This commit is contained in:
commit
4ae7d8ef4d
3 changed files with 17 additions and 2 deletions
|
@ -143,7 +143,7 @@ clone git github.com/docker/docker-credential-helpers v0.3.0
|
|||
clone git github.com/docker/containerd 2545227b0357eb55e369fa0072baef9ad91cdb69
|
||||
|
||||
# cluster
|
||||
clone git github.com/docker/swarmkit 191acc1bbdb13d8ea3b8059dda14a12f8c3903f2
|
||||
clone git github.com/docker/swarmkit 7b202f058db2f3a7d41351a56e5ef720c9b5a45d
|
||||
clone git github.com/golang/mock bd3c8e81be01eef76d4b503f5e687d2d1354d2d9
|
||||
clone git github.com/gogo/protobuf v0.3
|
||||
clone git github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a
|
||||
|
|
|
@ -264,3 +264,13 @@ func (s *DockerSwarmSuite) TestSwarmContainerAutoStart(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmRemoveInternalNetwork(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "ingress"
|
||||
out, err := d.Cmd("network", "rm", name)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, name)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "is a pre-defined network and cannot be removed")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package controlapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/docker/libnetwork/ipamapi"
|
||||
|
@ -186,7 +187,11 @@ func (s *Server) RemoveNetwork(ctx context.Context, request *api.RemoveNetworkRe
|
|||
err = s.store.Update(func(tx store.Tx) error {
|
||||
nw := store.GetNetwork(tx, request.NetworkID)
|
||||
if _, ok := nw.Spec.Annotations.Labels["com.docker.swarm.internal"]; ok {
|
||||
return grpc.Errorf(codes.PermissionDenied, "%s is a pre-defined network and cannot be removed", request.NetworkID)
|
||||
networkDescription := nw.ID
|
||||
if nw.Spec.Annotations.Name != "" {
|
||||
networkDescription = fmt.Sprintf("%s (%s)", nw.Spec.Annotations.Name, nw.ID)
|
||||
}
|
||||
return grpc.Errorf(codes.PermissionDenied, "%s is a pre-defined network and cannot be removed", networkDescription)
|
||||
}
|
||||
return store.DeleteNetwork(tx, request.NetworkID)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue