From ba221c03281aadc21e8941cd2fb7d94181ea08bb Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Thu, 18 May 2017 18:14:01 -0700 Subject: [PATCH] Properly identify ingress network created with older swarm - otherwise docker network prune will remove it Signed-off-by: Alessandro Boch Upstream-commit: 93763f11eeec5e9b1d0308a3ad85bbf069f9107f Component: engine --- .../engine/daemon/cluster/convert/network.go | 14 ++++++++++++-- .../daemon/cluster/executor/container/container.go | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/components/engine/daemon/cluster/convert/network.go b/components/engine/daemon/cluster/convert/network.go index 0ce450b749c..143869a117a 100644 --- a/components/engine/daemon/cluster/convert/network.go +++ b/components/engine/daemon/cluster/convert/network.go @@ -29,7 +29,7 @@ func networkFromGRPC(n *swarmapi.Network) types.Network { IPv6Enabled: n.Spec.Ipv6Enabled, Internal: n.Spec.Internal, Attachable: n.Spec.Attachable, - Ingress: n.Spec.Ingress, + Ingress: IsIngressNetwork(n), IPAMOptions: ipamFromGRPC(n.Spec.IPAM), Scope: netconst.SwarmScope, }, @@ -165,7 +165,7 @@ func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource { IPAM: ipam, Internal: spec.Internal, Attachable: spec.Attachable, - Ingress: spec.Ingress, + Ingress: IsIngressNetwork(&n), Labels: n.Spec.Annotations.Labels, } @@ -225,3 +225,13 @@ func BasicNetworkCreateToGRPC(create basictypes.NetworkCreateRequest) swarmapi.N } return ns } + +// IsIngressNetwork check if the swarm network is an ingress network +func IsIngressNetwork(n *swarmapi.Network) bool { + if n.Spec.Ingress { + return true + } + // Check if legacy defined ingress network + _, ok := n.Spec.Annotations.Labels["com.docker.swarm.internal"] + return ok && n.Spec.Annotations.Name == "ingress" +} diff --git a/components/engine/daemon/cluster/executor/container/container.go b/components/engine/daemon/cluster/executor/container/container.go index 44d5f1df2c8..bc98e539551 100644 --- a/components/engine/daemon/cluster/executor/container/container.go +++ b/components/engine/daemon/cluster/executor/container/container.go @@ -18,6 +18,7 @@ import ( enginemount "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/network" volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/daemon/cluster/convert" executorpkg "github.com/docker/docker/daemon/cluster/executor" clustertypes "github.com/docker/docker/daemon/cluster/provider" "github.com/docker/go-connections/nat" @@ -590,7 +591,7 @@ func (c *containerConfig) networkCreateRequest(name string) (clustertypes.Networ Labels: na.Network.Spec.Annotations.Labels, Internal: na.Network.Spec.Internal, Attachable: na.Network.Spec.Attachable, - Ingress: na.Network.Spec.Ingress, + Ingress: convert.IsIngressNetwork(na.Network), EnableIPv6: na.Network.Spec.Ipv6Enabled, CheckDuplicate: true, Scope: netconst.SwarmScope,