diff --git a/test/helpers/kubectl.go b/test/helpers/kubectl.go index 85b9dcf8ea8b..f910d271ddde 100644 --- a/test/helpers/kubectl.go +++ b/test/helpers/kubectl.go @@ -3405,6 +3405,34 @@ func (kub *Kubectl) WaitForIPCacheEntry(node, ipAddr string) error { &TimeoutConfig{Timeout: HelperTimeout}) } +// RepeatCommandInBackground runs command on repeat in goroutine until quit channel +// is closed and closes run channel when command is first run +func (kub *Kubectl) RepeatCommandInBackground(cmd string) (quit, run chan struct{}) { + quit = make(chan struct{}) + run = make(chan struct{}) + go func() { + firstRun := true + for { + select { + case <-quit: + return + default: + res := kub.Exec(cmd) + if !res.WasSuccessful() { + kub.Logger().WithFields(logrus.Fields{ + "cmd": cmd, + }).Warning("Command failed running in the background") + } + if firstRun { + close(run) + } + firstRun = false + } + } + }() + return +} + func serviceKey(s v1.Service) string { return s.Namespace + "/" + s.Name } diff --git a/test/k8sT/fqdn.go b/test/k8sT/fqdn.go index 0cd911125b41..0c045e8738f8 100644 --- a/test/k8sT/fqdn.go +++ b/test/k8sT/fqdn.go @@ -108,7 +108,7 @@ var _ = Describe("K8sFQDNTest", func() { _ = kubectl.Exec(fmt.Sprintf("%s delete --all cnp", helpers.KubectlCmd)) }) - PIt("Restart Cilium validate that FQDN is still working", func() { + It("Restart Cilium validate that FQDN is still working", func() { // Test functionality: // - When Cilium is running) Connectivity from App2 application can // connect to DNS because dns-proxy filter the DNS request. If the @@ -161,14 +161,22 @@ var _ = Describe("K8sFQDNTest", func() { Expect(err).To(BeNil(), "Cannot install fqdn proxy policy") connectivityTest() - By("Deleting cilium pods") - - res := kubectl.Exec(fmt.Sprintf("%s -n %s delete pods -l k8s-app=cilium", - helpers.KubectlCmd, helpers.CiliumNamespace)) - res.ExpectSuccess() + By("restarting cilium pods") + + // kill pid 1 in each cilium pod + cmd := fmt.Sprintf("%[1]s get pods -l k8s-app=cilium -n %[2]s | tail -n +2 | cut -d ' ' -f 1 | xargs -I{} %[1]s exec -n %[2]s {} -- kill 1", + helpers.KubectlCmd, helpers.CiliumNamespace) + quit, run := kubectl.RepeatCommandInBackground(cmd) + channelClosed := false + defer func() { + if !channelClosed { + close(quit) + } + }() + <-run // waiting for first run to finish By("Testing connectivity when cilium is restoring using IPS without DNS") - res = kubectl.ExecPodCmd( + res := kubectl.ExecPodCmd( helpers.DefaultNamespace, appPods[helpers.App2], helpers.CurlFail(worldTargetIP)) res.ExpectSuccess("%q cannot curl to %q during restart", helpers.App2, worldTargetIP) @@ -178,6 +186,9 @@ var _ = Describe("K8sFQDNTest", func() { helpers.CurlFail(worldInvalidTargetIP)) res.ExpectFail("%q can connect when it should not work", helpers.App2) + channelClosed = true + close(quit) + ExpectAllPodsTerminated(kubectl) ExpectCiliumReady(kubectl)