Skip to content

Commit

Permalink
test: fix race condition of deleting cnp in e2e test
Browse files Browse the repository at this point in the history
There is a flake in e2e test when a test case starts to proceed
before cnp comes to take effect by cilium-agent. The correct way to
delete cnp is to run "kubectl delete" followed by "cilium policy wait",
and kubectl helper already has such wrappers.

Signed-off-by: Zhichuan Liang <gray.liang@isovalent.com>
  • Loading branch information
jschwinger233 authored and julianwiedmann committed Mar 30, 2023
1 parent 22a3743 commit 294bcd1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/k8s/datapath_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,24 @@ func fetchPodsWithOffset(kubectl *helpers.Kubectl, namespace, name, filter, host
return targetPod, targetPodJSON
}

func applyL3Policy(kubectl *helpers.Kubectl, ns string) {
func applyL3Policy(kubectl *helpers.Kubectl, ns string) (withdrawPolicy func()) {
demoPolicyL3 := helpers.ManifestGet(kubectl.BasePath(), "l3-policy-demo.yaml")
By(fmt.Sprintf("Applying policy %s", demoPolicyL3))
_, err := kubectl.CiliumPolicyAction(ns, demoPolicyL3, helpers.KubectlApply, helpers.HelperTimeout)
ExpectWithOffset(1, err).Should(BeNil(), fmt.Sprintf("Error creating resource %s: %s", demoPolicyL3, err))

return func() {
_, err := kubectl.CiliumPolicyAction(ns, demoPolicyL3, helpers.KubectlDelete, helpers.HelperTimeout)
ExpectWithOffset(1, err).Should(BeNil(), fmt.Sprintf("Error deleting resource %s: %s", demoPolicyL3, err))
}
}

func testPodConnectivityAndReturnIP(kubectl *helpers.Kubectl, requireMultiNode bool, callOffset int) (bool, string) {
callOffset++

randomNamespace := deploymentManager.DeployRandomNamespaceShared(DemoDaemonSet)
applyL3Policy(kubectl, randomNamespace)
withdrawPolicy := applyL3Policy(kubectl, randomNamespace)
defer withdrawPolicy()
deploymentManager.WaitUntilReady()

By("Checking pod connectivity between nodes")
Expand Down Expand Up @@ -697,7 +703,8 @@ func testPodHTTPToOutside(kubectl *helpers.Kubectl, outsideURL string, expectNod
}

namespace := deploymentManager.DeployRandomNamespaceShared(DemoDaemonSet)
applyL3Policy(kubectl, namespace)
withdrawPolicy := applyL3Policy(kubectl, namespace)
defer withdrawPolicy()
deploymentManager.WaitUntilReady()

label := "zgroup=testDSClient"
Expand Down

0 comments on commit 294bcd1

Please sign in to comment.