Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: force restarting of Cilium pods #11613

Merged
merged 1 commit into from May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/helpers/kubectl.go
Expand Up @@ -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
tgraf marked this conversation as resolved.
Show resolved Hide resolved
}
}
}()
return
}

func serviceKey(s v1.Service) string {
return s.Namespace + "/" + s.Name
}
Expand Down
25 changes: 18 additions & 7 deletions test/k8sT/fqdn.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down