Skip to content

Commit

Permalink
test: Wait for kube-dns before starting test
Browse files Browse the repository at this point in the history
Wait for kube-dns to become reachable before running test in fqdn.go.

Fixes: #16409
Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme committed Jun 3, 2021
1 parent 7a4184f commit 82ec0b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4560,3 +4560,19 @@ func (kub *Kubectl) ensureKubectlVersion() error {
}
return nil
}

// NslookupInPod executes 'nslookup' in the given pod until it succeeds or times out.
func (kub *Kubectl) NslookupInPod(namespace, pod string, target string) (err error) {
err2 := WithTimeout(func() bool {
res := kub.ExecPodCmd(namespace, pod, fmt.Sprintf("nslookup %s", target))
if res.WasSuccessful() {
return true
}
err = fmt.Errorf("error looking up %s from %s/%s: %s", target, namespace, pod, res.CombineOutput().String())
return false
}, "Could not resolve target name", &TimeoutConfig{Timeout: HelperTimeout})
if err2 != nil {
return err
}
return nil
}
4 changes: 4 additions & 0 deletions test/k8sT/fqdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ var _ = SkipDescribeIf(helpers.RunsOn54Kernel, "K8sFQDNTest", func() {
Expect(err).Should(BeNil(), "Testapp is not ready after timeout")

appPods = helpers.GetAppPods(apps, helpers.DefaultNamespace, kubectl, "id")

// Validate that coredns is reachable from test pods
err = kubectl.NslookupInPod(helpers.DefaultNamespace, appPods[helpers.App2], "kube-dns.kube-system.svc.cluster.local")
Expect(err).Should(BeNil(), "Error reaching kube-dns before test: %s", err)
})

AfterFailed(func() {
Expand Down

0 comments on commit 82ec0b9

Please sign in to comment.