Skip to content

Commit

Permalink
fix(host-gw): failed to restart if gateway hnsep existed
Browse files Browse the repository at this point in the history
  • Loading branch information
thxCode committed Dec 28, 2020
1 parent 4b015d0 commit a85e127
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions backend/hostgw/hostgw_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a85e127

Please sign in to comment.