From 27362011378d81669801e5fe9b467f6a80608a6c Mon Sep 17 00:00:00 2001 From: Gavin Xin Date: Fri, 10 Jun 2022 14:37:55 +0800 Subject: [PATCH] Fix random NPL unit test failure (#3855) The failed case has updated both Service and Pod. The issue happens when Service update is processed by NPL controller before Pod update. In this case, the pod2 annotation was fully removed firstly. Then NPL controller added a new nodeport with both tcp and udp rules to pod2 by service update. As the result, the pod2 annotation was: '[{80 10.10.10.10 61002 tcp [tcp]} {80 10.10.10.10 61002 udp [udp]}]'. The fix removes unnecessary label update for pod2 to avoid unexpected annotation in race condition. Annotation after fix: '[{80 10.10.10.10 61001 tcp [tcp]} {80 10.10.10.10 61001 udp [udp]}]' Fixes #3847 Signed-off-by: Shuyang Xin --- pkg/agent/nodeportlocal/npl_agent_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/agent/nodeportlocal/npl_agent_test.go b/pkg/agent/nodeportlocal/npl_agent_test.go index 2c1efbf0579..3cc5957e4d2 100644 --- a/pkg/agent/nodeportlocal/npl_agent_test.go +++ b/pkg/agent/nodeportlocal/npl_agent_test.go @@ -700,20 +700,17 @@ func TestMultipleProtocols(t *testing.T) { assert.NotEqual(t, pod1Value[0].NodePort, pod2Value[0].NodePort) assert.True(t, testData.portTable.RuleExists(testPod2.Status.PodIP, defaultPort, protocolUDP)) - // Update testSvc2 to serve TCP/80 and UDP/81 both, so pod1 is + // Update testSvc2 to serve TCP/80 and UDP/81 both, so pod2 is // exposed on both TCP and UDP, with the same NodePort. - testPod2.Labels = tcpUdpSvcLabel - testData.updatePodOrFail(testPod2) testSvc2.Spec.Ports = append(testSvc2.Spec.Ports, corev1.ServicePort{ - Port: 81, - Protocol: corev1.ProtocolUDP, + Port: 80, + Protocol: corev1.ProtocolTCP, TargetPort: intstr.IntOrString{ Type: intstr.Int, IntVal: 80, }, }) - testSvc2.Spec.Selector = tcpUdpSvcLabel testData.updateServiceOrFail(testSvc2) pod2ValueUpdate, err := testData.pollForPodAnnotation(testPod2.Name, true)