Skip to content

Commit 02ff7bc

Browse files
fix: address comment
1 parent 21254db commit 02ff7bc

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

network/endpoint.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ func (nw *network) deleteEndpoint(nl netlink.NetlinkInterface, plc platform.Exec
218218
// Call the platform implementation.
219219
// Pass nil for epClient and will be initialized in deleteEndpointImpl
220220
err = nw.deleteEndpointImpl(nl, plc, nil, nioc, nsc, iptc, dhcpc, ep)
221-
if err != nil {
221+
if err == ErrMissingHNSID {
222+
logger.Info("HNS ID is missing, skipping endpoint deletion")
223+
} else if err != nil {
222224
return err
223225
}
224226

network/endpoint_windows_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func TestNewAndDeleteEndpointImplHnsV2(t *testing.T) {
8181
}
8282

8383
err = nw.deleteEndpointImplHnsV2(ep)
84-
8584
if err != nil {
8685
fmt.Printf("+%v", err)
8786
t.Fatal(err)
@@ -137,8 +136,8 @@ func TestDeleteEndpointImplHnsV2WithEmptyHNSID(t *testing.T) {
137136
mockCli := NewMockEndpointClient(nil)
138137
err := nw.deleteEndpointImpl(netlink.NewMockNetlink(false, ""), platform.NewMockExecClient(false), mockCli,
139138
netio.NewMockNetIO(false, 0), NewMockNamespaceClient(), iptables.NewClient(), &mockDHCP{}, &ep)
140-
if err != nil {
141-
t.Fatal("endpoint deletion gets executed")
139+
if err != ErrMissingHNSID {
140+
t.Fatalf("unexpected error when deleting endpoint with empty HNS ID: %v", err)
142141
}
143142
}
144143

network/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ var (
88
ErrEndpointStateNotFound = errors.New("endpoint state could not be found in the statefile")
99
ErrConnectionFailure = errors.New("couldn't connect to CNS")
1010
ErrGetEndpointStateFailure = errors.New("failure to obtain the endpoint state")
11+
ErrMissingHNSID = errors.New("HNS ID missing")
1112
)

network/manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ func (nm *networkManager) DeleteEndpointState(networkID string, epInfo *Endpoint
542542
logger.Info("Deleting endpoint with", zap.String("Endpoint Info: ", epInfo.PrettyString()), zap.String("HNISID : ", ep.HnsId))
543543

544544
err := nw.deleteEndpointImpl(netlink.NewNetlink(), platform.NewExecClient(logger), nil, nil, nil, nil, nil, ep)
545-
if err != nil {
545+
if err == ErrMissingHNSID {
546+
logger.Info("HNS ID is missing, skipping endpoint deletion")
547+
} else if err != nil {
546548
return err
547549
}
548550

0 commit comments

Comments
 (0)