Browse Source

Merge pull request #1716 from aboch/gwf

Remove gw endpoint on gw nw join failure
Madhu Venugopal 8 năm trước cách đây
mục cha
commit
de0926bf39

+ 12 - 1
libnetwork/default_gateway.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"fmt"
 	"strings"
 	"strings"
 
 
+	"github.com/Sirupsen/logrus"
 	"github.com/docker/libnetwork/netlabel"
 	"github.com/docker/libnetwork/netlabel"
 	"github.com/docker/libnetwork/types"
 	"github.com/docker/libnetwork/types"
 )
 )
@@ -72,9 +73,19 @@ func (sb *sandbox) setupDefaultGW() error {
 	if err != nil {
 	if err != nil {
 		return fmt.Errorf("container %s: endpoint create on GW Network failed: %v", sb.containerID, err)
 		return fmt.Errorf("container %s: endpoint create on GW Network failed: %v", sb.containerID, err)
 	}
 	}
+
+	defer func() {
+		if err != nil {
+			if err2 := newEp.Delete(true); err2 != nil {
+				logrus.Warnf("Failed to remove gw endpoint for container %s after failing to join the gateway network: %v",
+					sb.containerID, err2)
+			}
+		}
+	}()
+
 	epLocal := newEp.(*endpoint)
 	epLocal := newEp.(*endpoint)
 
 
-	if err := epLocal.sbJoin(sb); err != nil {
+	if err = epLocal.sbJoin(sb); err != nil {
 		return fmt.Errorf("container %s: endpoint join on GW Network failed: %v", sb.containerID, err)
 		return fmt.Errorf("container %s: endpoint join on GW Network failed: %v", sb.containerID, err)
 	}
 	}
 
 

+ 2 - 1
libnetwork/endpoint.go

@@ -528,7 +528,8 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error {
 	}()
 	}()
 
 
 	if sb.needDefaultGW() && sb.getEndpointInGWNetwork() == nil {
 	if sb.needDefaultGW() && sb.getEndpointInGWNetwork() == nil {
-		return sb.setupDefaultGW()
+		err = sb.setupDefaultGW()
+		return err
 	}
 	}
 
 
 	moveExtConn := sb.getGatewayEndpoint() != extEp
 	moveExtConn := sb.getGatewayEndpoint() != extEp