Skip to content

Commit 4dd9c06

Browse files
authored
Merge pull request #1716 from aboch/gwf
Remove gw endpoint on gw nw join failure
2 parents b13e060 + 27fc51c commit 4dd9c06

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

default_gateway.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/Sirupsen/logrus"
78
"github.com/docker/libnetwork/netlabel"
89
"github.com/docker/libnetwork/types"
910
)
@@ -72,9 +73,19 @@ func (sb *sandbox) setupDefaultGW() error {
7273
if err != nil {
7374
return fmt.Errorf("container %s: endpoint create on GW Network failed: %v", sb.containerID, err)
7475
}
76+
77+
defer func() {
78+
if err != nil {
79+
if err2 := newEp.Delete(true); err2 != nil {
80+
logrus.Warnf("Failed to remove gw endpoint for container %s after failing to join the gateway network: %v",
81+
sb.containerID, err2)
82+
}
83+
}
84+
}()
85+
7586
epLocal := newEp.(*endpoint)
7687

77-
if err := epLocal.sbJoin(sb); err != nil {
88+
if err = epLocal.sbJoin(sb); err != nil {
7889
return fmt.Errorf("container %s: endpoint join on GW Network failed: %v", sb.containerID, err)
7990
}
8091

endpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error {
528528
}()
529529

530530
if sb.needDefaultGW() && sb.getEndpointInGWNetwork() == nil {
531-
return sb.setupDefaultGW()
531+
err = sb.setupDefaultGW()
532+
return err
532533
}
533534

534535
moveExtConn := sb.getGatewayEndpoint() != extEp

0 commit comments

Comments
 (0)