Skip to content

Commit ea43a60

Browse files
authored
fix: pass right interface name to generate hns endpoint name as expected (#2915)
* fix endpointNames * fix comments * fix an linter issue * remove network import on UT * fix linter: rename local var * remove the UT * fix UTs * start endpointIndex from 1
1 parent a39d8c4 commit ea43a60

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

cni/network/network.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
605605
}()
606606

607607
infraSeen := false
608-
endpointIndex := 0
608+
endpointIndex := 1
609609
for key := range ipamAddResult.interfaceInfo {
610610
ifInfo := ipamAddResult.interfaceInfo[key]
611611

@@ -732,7 +732,6 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
732732
// populate endpoint info
733733
epDNSInfo, err := getEndpointDNSSettings(opt.nwCfg, opt.ifInfo.DNS, opt.k8sNamespace) // Probably won't panic if given bad values
734734
if err != nil {
735-
736735
err = plugin.Errorf("Failed to getEndpointDNSSettings: %v", err)
737736
return nil, err
738737
}
@@ -753,13 +752,16 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
753752
}
754753

755754
// generate endpoint info
756-
var endpointID string
755+
var endpointID, ifName string
756+
757757
if opt.ifInfo.NICType == cns.InfraNIC && !*opt.infraSeen {
758758
// so we do not break existing scenarios, only the first infra gets the original endpoint id generation
759-
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, opt.args.IfName)
759+
ifName = opt.args.IfName
760+
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, ifName)
760761
*opt.infraSeen = true
761762
} else {
762-
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, strconv.Itoa(opt.endpointIndex))
763+
ifName = "eth" + strconv.Itoa(opt.endpointIndex)
764+
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, ifName)
763765
}
764766

765767
endpointInfo := network.EndpointInfo{
@@ -777,7 +779,7 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
777779
EndpointID: endpointID,
778780
ContainerID: opt.args.ContainerID,
779781
NetNsPath: opt.args.Netns, // probably same value as epInfo.NetNs
780-
IfName: opt.args.IfName,
782+
IfName: ifName,
781783
Data: make(map[string]interface{}),
782784
EndpointDNS: epDNSInfo,
783785
// endpoint policies are populated later

cni/network/network_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,12 +1392,12 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
13921392
Plugin: plugin,
13931393
nm: acnnetwork.NewMockNetworkmanager(acnnetwork.NewMockEndpointClient(nil)),
13941394
ipamInvoker: NewCustomMockIpamInvoker(map[string]acnnetwork.InterfaceInfo{
1395-
"eth0-1": {
1396-
NICType: cns.NodeNetworkInterfaceFrontendNIC,
1397-
},
13981395
"eth0": {
13991396
NICType: cns.InfraNIC,
14001397
},
1398+
"eth2": {
1399+
NICType: cns.NodeNetworkInterfaceFrontendNIC,
1400+
},
14011401
}),
14021402
report: &telemetry.CNIReport{},
14031403
tb: &telemetry.TelemetryBuffer{},
@@ -1417,7 +1417,7 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
14171417
Plugin: plugin,
14181418
nm: acnnetwork.NewMockNetworkmanager(acnnetwork.NewMockEndpointClient(nil)),
14191419
ipamInvoker: NewCustomMockIpamInvoker(map[string]acnnetwork.InterfaceInfo{
1420-
"eth0-1": {
1420+
"eth1": {
14211421
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
14221422
},
14231423
"eth0": {
@@ -1442,15 +1442,15 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
14421442
Plugin: plugin,
14431443
nm: acnnetwork.NewMockNetworkmanager(acnnetwork.NewMockEndpointClient(nil)),
14441444
ipamInvoker: NewCustomMockIpamInvoker(map[string]acnnetwork.InterfaceInfo{
1445-
"eth0-2": {
1445+
"eth0": {
1446+
NICType: cns.InfraNIC,
1447+
},
1448+
"eth1": {
14461449
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
14471450
},
1448-
"eth0-1": {
1451+
"eth2": {
14491452
NICType: cns.NodeNetworkInterfaceFrontendNIC,
14501453
},
1451-
"eth0": {
1452-
NICType: cns.InfraNIC,
1453-
},
14541454
}),
14551455
report: &telemetry.CNIReport{},
14561456
tb: &telemetry.TelemetryBuffer{},
@@ -1470,12 +1470,12 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
14701470
Plugin: plugin,
14711471
nm: acnnetwork.NewMockNetworkmanager(acnnetwork.NewMockEndpointClient(nil)),
14721472
ipamInvoker: NewCustomMockIpamInvoker(map[string]acnnetwork.InterfaceInfo{
1473-
"eth0-1": {
1474-
NICType: cns.BackendNIC,
1475-
},
14761473
"eth0": {
14771474
NICType: cns.InfraNIC,
14781475
},
1476+
"eth1": {
1477+
NICType: cns.BackendNIC,
1478+
},
14791479
}),
14801480
report: &telemetry.CNIReport{},
14811481
tb: &telemetry.TelemetryBuffer{},
@@ -1495,10 +1495,10 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
14951495
Plugin: plugin,
14961496
nm: acnnetwork.NewMockNetworkmanager(acnnetwork.NewMockEndpointClient(nil)),
14971497
ipamInvoker: NewCustomMockIpamInvoker(map[string]acnnetwork.InterfaceInfo{
1498-
"eth0": {
1498+
"eth1": {
14991499
NICType: cns.NodeNetworkInterfaceFrontendNIC,
15001500
},
1501-
"eth0-1": {
1501+
"eth2": {
15021502
NICType: cns.NodeNetworkInterfaceFrontendNIC,
15031503
},
15041504
}),
@@ -1520,10 +1520,10 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
15201520
Plugin: plugin,
15211521
nm: acnnetwork.NewMockNetworkmanager(acnnetwork.NewMockEndpointClient(nil)),
15221522
ipamInvoker: NewCustomMockIpamInvoker(map[string]acnnetwork.InterfaceInfo{
1523-
"eth0": {
1523+
"eth1": {
15241524
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
15251525
},
1526-
"eth0-1": {
1526+
"eth2": {
15271527
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
15281528
},
15291529
}),
@@ -1556,7 +1556,7 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
15561556
"eth0": {
15571557
NICType: cns.InfraNIC,
15581558
},
1559-
"eth0-1": {
1559+
"eth1": {
15601560
NICType: cns.NodeNetworkInterfaceFrontendNIC,
15611561
},
15621562
}),
@@ -1588,7 +1588,7 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
15881588
"eth0": {
15891589
NICType: cns.NodeNetworkInterfaceFrontendNIC,
15901590
},
1591-
"eth0-1": {
1591+
"eth1": {
15921592
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
15931593
},
15941594
}),
@@ -1620,7 +1620,7 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
16201620
"eth0": {
16211621
NICType: cns.InfraNIC,
16221622
},
1623-
"eth0-1": {
1623+
"eth1": {
16241624
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
16251625
},
16261626
}),
@@ -1655,7 +1655,7 @@ func TestPluginSwiftV2MultipleAddDelete(t *testing.T) {
16551655
if ep.NICType == cns.InfraNIC {
16561656
require.Equal(t, "test-con-"+tt.args.IfName, ep.EndpointID, "infra nic must use ifname for its endpoint id")
16571657
} else {
1658-
require.Regexp(t, `test-con-\d+$`, ep.EndpointID, "other nics must use an index for their endpoint ids")
1658+
require.Regexp(t, `\d+$`, ep.EndpointID, "other nics must use an index for their endpoint ids")
16591659
}
16601660
}
16611661

0 commit comments

Comments
 (0)