diff --git a/backend/hostgw/hostgw_windows.go b/backend/hostgw/hostgw_windows.go index b47df3e9ad..80428f7908 100644 --- a/backend/hostgw/hostgw_windows.go +++ b/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)