Skip to content

Commit 362d41b

Browse files
authored
Merge pull request #775 from l1b0k/feat/link_not_found
fix: cni tolerate eni not found
2 parents 6af5b5a + ce214a7 commit 362d41b

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

pkg/link/interface_linux_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package link
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestGetDeviceNumber(t *testing.T) {
11+
id, err := GetDeviceNumber("00")
12+
assert.True(t, errors.Is(err, ErrNotFound))
13+
assert.Equal(t, int32(0), id)
14+
}

plugin/datapath/ipvlan_linux.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (d *IPvlanDriver) Teardown(ctx context.Context, cfg *types.TeardownCfg, net
323323
return err
324324
}
325325

326-
if cfg.EnableNetworkPriority {
326+
if cfg.EnableNetworkPriority && cfg.ENIIndex > 0 {
327327
link, err := netlink.LinkByIndex(cfg.ENIIndex)
328328
if err != nil {
329329
if _, ok := err.(netlink.LinkNotFoundError); !ok {
@@ -338,6 +338,9 @@ func (d *IPvlanDriver) Teardown(ctx context.Context, cfg *types.TeardownCfg, net
338338
}
339339

340340
err = func() error {
341+
if cfg.ENIIndex <= 0 {
342+
return nil
343+
}
341344
link, err := netlink.LinkByIndex(cfg.ENIIndex)
342345
if err != nil {
343346
if _, ok := err.(netlink.LinkNotFoundError); !ok {

plugin/datapath/ipvlan_linux_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,15 @@ func TestDataPathIPvlanL2(t *testing.T) {
304304
})
305305
assert.NoError(t, err)
306306
assert.Equal(t, 0, len(routes))
307+
308+
err = d.Teardown(context.Background(), &types2.TeardownCfg{
309+
HostVETHName: cfg.HostVETHName,
310+
ContainerIfName: cfg.ContainerIfName,
311+
ContainerIPNet: &types.IPNetSet{
312+
IPv4: containerIPNet,
313+
IPv6: containerIPNetIPv6,
314+
},
315+
ENIIndex: 0,
316+
}, containerNS)
317+
assert.NoError(t, err)
307318
}

plugin/datapath/policy_router_linux.go

+3
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ func (d *PolicyRoute) Teardown(ctx context.Context, cfg *types.TeardownCfg, netN
476476
}
477477
}
478478

479+
if cfg.ENIIndex <= 0 {
480+
return nil
481+
}
479482
link, err := netlink.LinkByIndex(cfg.ENIIndex)
480483
if err != nil {
481484
if _, ok := err.(netlink.LinkNotFoundError); !ok {

plugin/datapath/policy_router_linux_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,15 @@ func TestDataPathPolicyRoute(t *testing.T) {
202202
for _, r := range rules {
203203
t.Logf("%s %#v ", r, r)
204204
}
205+
206+
err = d.Teardown(context.Background(), &types.TeardownCfg{
207+
HostVETHName: cfg.HostVETHName,
208+
ContainerIfName: cfg.ContainerIfName,
209+
ContainerIPNet: &terwayTypes.IPNetSet{
210+
IPv4: containerIPNet,
211+
IPv6: containerIPNetIPv6,
212+
},
213+
ENIIndex: 0,
214+
}, containerNS)
215+
assert.NoError(t, err)
205216
}

plugin/terway/cni.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,12 @@ func parseTearDownConf(alloc *rpc.NetConf, conf *types.CNIConf, ipType rpc.IPTyp
418418
if alloc.GetENIInfo() != nil {
419419
mac := alloc.GetENIInfo().GetMAC()
420420
if mac != "" {
421-
eniIndex, _ = link.GetDeviceNumber(mac)
421+
eniIndex, err = link.GetDeviceNumber(mac)
422+
if err != nil {
423+
if !errors.Is(err, link.ErrNotFound) {
424+
return nil, err
425+
}
426+
}
422427
}
423428
}
424429

0 commit comments

Comments
 (0)