Skip to content

Commit 92759ea

Browse files
committed
NetworkPolicy e2e test should wait for Pod ready
The test "should enforce egress policy allowing traffic to a server in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]" is flaky because it doesn't wait for the server Pod to be ready before testing traffic via its service, then even the NetworkPolicy allows it, the SYN packets will be rejected by iptables because the service has no endpoints at that moment. This PR fixes it by making it wait for Pods to be ready like other tests.
1 parent ddd6d66 commit 92759ea

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

test/e2e/network/network_policy.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -918,22 +918,21 @@ var _ = SIGDescribe("NetworkPolicy [LinuxOnly]", func() {
918918

919919
// Creating pods and services in namespace-b
920920
nsBpodServerA, nsBserviceA = createServerPodAndService(f, nsB, "ns-b-server-a", []int{80})
921+
defer cleanupServerPodAndService(f, nsBpodServerA, nsBserviceA)
921922
nsBpodServerB, nsBserviceB = createServerPodAndService(f, nsB, "ns-b-server-b", []int{80})
923+
defer cleanupServerPodAndService(f, nsBpodServerB, nsBserviceB)
922924

923925
// Wait for Server with Service in NS-A to be ready
924-
framework.Logf("Waiting for servers to come up.")
925-
err = e2epod.WaitForPodRunningInNamespace(f.ClientSet, podServer)
926-
framework.ExpectNoError(err, "Error occurred while waiting for pod status in namespace: Running.")
926+
framework.Logf("Waiting for servers to be ready.")
927+
err = e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, podServer.Name, podServer.Namespace, framework.PodStartTimeout)
928+
framework.ExpectNoError(err, "Error occurred while waiting for pod status in namespace: Ready.")
927929

928930
// Wait for Servers with Services in NS-B to be ready
929-
err = e2epod.WaitForPodRunningInNamespace(f.ClientSet, nsBpodServerA)
930-
framework.ExpectNoError(err, "Error occurred while waiting for pod status in namespace: Running.")
931+
err = e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, nsBpodServerA.Name, nsBpodServerA.Namespace, framework.PodStartTimeout)
932+
framework.ExpectNoError(err, "Error occurred while waiting for pod status in namespace: Ready.")
931933

932-
err = e2epod.WaitForPodRunningInNamespace(f.ClientSet, nsBpodServerB)
933-
framework.ExpectNoError(err, "Error occurred while waiting for pod status in namespace: Running.")
934-
935-
defer cleanupServerPodAndService(f, nsBpodServerA, nsBserviceA)
936-
defer cleanupServerPodAndService(f, nsBpodServerB, nsBserviceB)
934+
err = e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, nsBpodServerB.Name, nsBpodServerB.Namespace, framework.PodStartTimeout)
935+
framework.ExpectNoError(err, "Error occurred while waiting for pod status in namespace: Ready.")
937936

938937
ginkgo.By("Creating a network policy for the server which allows traffic only to a server in different namespace.")
939938
protocolUDP := v1.ProtocolUDP

0 commit comments

Comments
 (0)