Procházet zdrojové kódy

Remove only the endpoint owned interfaces

Only remove the interfaces owned by the endpoint from
the sandbox when the container leaves the endpoint.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Jana Radhakrishnan před 10 roky
rodič
revize
ea8580d1e2
1 změnil soubory, kde provedl 19 přidání a 3 odebrání
  1. 19 3
      libnetwork/endpoint.go

+ 19 - 3
libnetwork/endpoint.go

@@ -326,6 +326,19 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) error {
 	return nil
 }
 
+func (ep *endpoint) hasInterface(iName string) bool {
+	ep.Lock()
+	defer ep.Unlock()
+
+	for _, iface := range ep.iFaces {
+		if iface.srcName == iName {
+			return true
+		}
+	}
+
+	return false
+}
+
 func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {
 	var err error
 
@@ -361,9 +374,12 @@ func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {
 
 	sb := ctrlr.sandboxGet(container.data.SandboxKey)
 	for _, i := range sb.Interfaces() {
-		err = sb.RemoveInterface(i)
-		if err != nil {
-			logrus.Debugf("Remove interface failed: %v", err)
+		// Only remove the interfaces owned by this endpoint from the sandbox.
+		if ep.hasInterface(i.SrcName) {
+			err = sb.RemoveInterface(i)
+			if err != nil {
+				logrus.Debugf("Remove interface failed: %v", err)
+			}
 		}
 	}