Skip to content

Commit e766cf6

Browse files
authored
Fix unexpected interface store initialization for FlexibleIPAM uplink internal port (#7389) (#7432)
* Fix unexpected interface store initialization for FlexibleIPAM uplink internal port Signed-off-by: Ran Gu <[email protected]>
1 parent 1ba63f9 commit e766cf6

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

pkg/agent/agent.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,15 @@ func (i *Initializer) initInterfaceStore() error {
339339
case interfacestore.AntreaIPsecTunnel:
340340
intf = parseTunnelInterfaceFunc(port, ovsPort)
341341
case interfacestore.AntreaHost:
342-
if port.Name == i.ovsBridge {
343-
// Need not to load the OVS bridge port to the interfaceStore
344-
intf = nil
345-
} else {
342+
if i.nodeType == config.ExternalNode {
346343
var err error
347344
intf, err = externalnode.ParseHostInterfaceConfig(i.ovsBridgeClient, port, ovsPort)
348345
if err != nil {
349346
return fmt.Errorf("failed to get interfaceConfig by port %s: %v", port.Name, err)
350347
}
348+
} else {
349+
// No need to load the OVS host Interface to the interfaceStore
350+
intf = nil
351351
}
352352
case interfacestore.AntreaContainer:
353353
// The port should be for a container interface.

pkg/agent/agent_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ func TestInitInterfaceStore(t *testing.T) {
9696
interfacestore.NewContainerInterface("p2", uuid2, "pod2", "ns2", "eth0", "netns2", p2NetMAC, []net.IP{p2NetIP}, 0),
9797
)),
9898
}
99-
initOVSPorts := []ovsconfig.OVSPortData{ovsPort1, ovsPort2}
99+
uuid3 := uuid.New().String()
100+
ovsPortUplinkInternal := ovsconfig.OVSPortData{UUID: uuid3, Name: "eth-antrea-test-1", IFName: "eth-antrea-test-1", OFPort: 100,
101+
ExternalIDs: map[string]string{
102+
interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaHost,
103+
},
104+
}
105+
initOVSPorts := []ovsconfig.OVSPortData{ovsPort1, ovsPort2, ovsPortUplinkInternal}
100106

101107
mockOVSBridgeClient.EXPECT().GetPortList().Return(initOVSPorts, ovsconfig.NewTransactionError(fmt.Errorf("Failed to list OVS ports"), true))
102108
initializer.initInterfaceStore()

test/e2e/antreaipam_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@ func TestAntreaIPAM(t *testing.T) {
279279
t.Run("testAntreaIPAMOVSRestartSameNode", func(t *testing.T) {
280280
skipIfNotIPv4Cluster(t)
281281
skipIfHasWindowsNodes(t)
282-
testOVSRestartSameNode(t, data, testAntreaIPAMNamespace)
283-
testOVSRestartSameNode(t, data, testAntreaIPAMNamespace11)
282+
testOVSRestartSameNode(t, data, testAntreaIPAMNamespace, false)
283+
testOVSRestartSameNode(t, data, testAntreaIPAMNamespace11, false)
284+
testOVSRestartSameNode(t, data, testAntreaIPAMNamespace, true)
285+
testOVSRestartSameNode(t, data, testAntreaIPAMNamespace11, true)
284286
checkIPPoolsEmpty(t, data, ipPools)
285287
})
286288
t.Run("testAntreaIPAMOVSFlowReplay", func(t *testing.T) {

test/e2e/connectivity_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestConnectivity(t *testing.T) {
6060
t.Run("testOVSRestartSameNode", func(t *testing.T) {
6161
skipIfNotIPv4Cluster(t)
6262
skipIfHasWindowsNodes(t)
63-
testOVSRestartSameNode(t, data, data.testNamespace)
63+
testOVSRestartSameNode(t, data, data.testNamespace, false)
6464
})
6565
t.Run("testOVSFlowReplay", func(t *testing.T) {
6666
skipIfHasWindowsNodes(t)
@@ -425,7 +425,7 @@ func testPodConnectivityAfterAntreaRestart(t *testing.T, data *TestData, namespa
425425
// testOVSRestartSameNode verifies that datapath flows are not removed when the Antrea Agent Pod is
426426
// stopped gracefully (e.g. as part of a RollingUpdate). The test sends ARP requests every 1s and
427427
// checks that there is no packet loss during the restart.
428-
func testOVSRestartSameNode(t *testing.T, data *TestData, namespace string) {
428+
func testOVSRestartSameNode(t *testing.T, data *TestData, namespace string, force bool) {
429429
workerNode := workerNodeName(1)
430430
t.Logf("Creating two toolbox test Pods on '%s'", workerNode)
431431
podNames, podIPs, cleanupFn := createTestToolboxPods(t, data, 2, namespace, workerNode)
@@ -469,8 +469,24 @@ func testOVSRestartSameNode(t *testing.T, data *TestData, namespace string) {
469469
time.Sleep(3 * time.Second)
470470

471471
t.Logf("Restarting antrea-agent on Node '%s'", workerNode)
472-
if _, err := data.deleteAntreaAgentOnNode(workerNode, 30 /* grace period in seconds */, defaultTimeout); err != nil {
473-
t.Fatalf("Error when restarting antrea-agent on Node '%s': %v", workerNode, err)
472+
if !force {
473+
if _, err := data.deleteAntreaAgentOnNode(workerNode, 30 /* grace period in seconds */, defaultTimeout); err != nil {
474+
t.Fatalf("Error when restarting antrea-agent on Node '%s': %v", workerNode, err)
475+
}
476+
} else {
477+
signalAgent := func(nodeName, signal string) {
478+
cmd := fmt.Sprintf("pkill -%s antrea-agent", signal)
479+
if testOptions.providerName != "kind" {
480+
cmd = "sudo " + cmd
481+
}
482+
rc, stdout, stderr, err := data.RunCommandOnNode(nodeName, cmd)
483+
if rc != 0 || err != nil {
484+
t.Errorf("Error when running command '%s' on Node '%s', rc: %d, stdout: %s, stderr: %s, error: %v",
485+
cmd, nodeName, rc, stdout, stderr, err)
486+
}
487+
}
488+
// Send "KILL" signal to antrea-agent.
489+
signalAgent(workerNode, "KILL")
474490
}
475491

476492
if err := <-resCh; err != nil {

0 commit comments

Comments
 (0)