Quellcode durchsuchen

Merge pull request #1392 from thxCode/fix_1391

fix(host-gw): failed to restart if gateway hnsep existed
Rajat Chopra vor 4 Jahren
Ursprung
Commit
06e7635b01
1 geänderte Dateien mit 15 neuen und 5 gelöschten Zeilen
  1. 15 5
      backend/hostgw/hostgw_windows.go

+ 15 - 5
backend/hostgw/hostgw_windows.go

@@ -16,19 +16,21 @@ package hostgw
 
 import (
 	"fmt"
+	"strings"
 	"sync"
 	"time"
 
 	"github.com/Microsoft/hcsshim"
-	"github.com/coreos/flannel/backend"
-	"github.com/coreos/flannel/pkg/ip"
-	"github.com/coreos/flannel/pkg/routing"
-	"github.com/coreos/flannel/subnet"
 	log "github.com/golang/glog"
 	"github.com/pkg/errors"
 	"golang.org/x/net/context"
 	"k8s.io/apimachinery/pkg/util/json"
 	"k8s.io/apimachinery/pkg/util/wait"
+
+	"github.com/coreos/flannel/backend"
+	"github.com/coreos/flannel/pkg/ip"
+	"github.com/coreos/flannel/pkg/routing"
+	"github.com/coreos/flannel/subnet"
 )
 
 func init() {
@@ -222,7 +224,15 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
 	log.Infof("Waiting to attach bridge endpoint %s to host", bridgeEndpointName)
 	waitErr = wait.Poll(500*time.Millisecond, 5*time.Second, func() (done bool, err error) {
 		lastErr = expectedBridgeEndpoint.HostAttach(1)
-		return lastErr == nil, nil
+		if lastErr == nil {
+			return true, nil
+		}
+		// See https://github.com/coreos/flannel/issues/1391 and
+		// hcsshim lacks some validations to detect the error, so we judge it by error message.
+		if strings.Contains(lastErr.Error(), "This endpoint is already attached to the switch.") {
+			return true, nil
+		}
+		return false, nil
 	})
 	if waitErr == wait.ErrWaitTimeout {
 		return nil, errors.Wrapf(lastErr, "failed to hot attach bridge HNSEndpoint %s to host compartment", bridgeEndpointName)