From a7598c791fbcd9862fd7e209f72948ec57a2d20e Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Thu, 11 Apr 2019 22:50:51 -0700 Subject: [PATCH] tests: Adds configurable pod DNS nameservers and search list test This test creates a pod with custom DNS configurations and expects them to be set in the containers. The test pod is using the agnhost image, which can output the container's DNS configurations that the test checks. --- test/e2e/framework/util.go | 19 +++++++++++++++ test/e2e/network/dns.go | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 36c1711627a..32f4173788a 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -4873,6 +4873,25 @@ func (f *Framework) NewTestPod(name string, requests v1.ResourceList, limits v1. } } +// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands +// that behave the same, no matter the underlying OS. +func (f *Framework) NewAgnhostPod(name string, args ...string) *v1.Pod { + return &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "agnhost", + Image: imageutils.GetE2EImage(imageutils.Agnhost), + Args: args, + }, + }, + }, + } +} + // CreateEmptyFileOnPod creates empty file at given path on the pod. func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error { _, err := RunKubectl("exec", fmt.Sprintf("--namespace=%s", namespace), podName, "--", "/bin/sh", "-c", fmt.Sprintf("touch %s", filePath)) diff --git a/test/e2e/network/dns.go b/test/e2e/network/dns.go index c3ed46ac40e..2dc756df528 100644 --- a/test/e2e/network/dns.go +++ b/test/e2e/network/dns.go @@ -361,6 +361,54 @@ var _ = SIGDescribe("DNS", func() { validateTargetedProbeOutput(f, pod3, []string{wheezyFileName, jessieFileName}, svc.Spec.ClusterIP) }) + It("should support configurable pod DNS nameservers", func() { + By("Creating a pod with dnsPolicy=None and customized dnsConfig...") + testServerIP := "1.1.1.1" + testSearchPath := "resolv.conf.local" + testAgnhostPod := f.NewAgnhostPod(f.Namespace.Name, "pause") + testAgnhostPod.Spec.DNSPolicy = v1.DNSNone + testAgnhostPod.Spec.DNSConfig = &v1.PodDNSConfig{ + Nameservers: []string{testServerIP}, + Searches: []string{testSearchPath}, + } + testAgnhostPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(testAgnhostPod) + Expect(err).NotTo(HaveOccurred(), "failed to create pod: %s", testAgnhostPod.Name) + framework.Logf("Created pod %v", testAgnhostPod) + defer func() { + framework.Logf("Deleting pod %s...", testAgnhostPod.Name) + if err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(testAgnhostPod.Name, metav1.NewDeleteOptions(0)); err != nil { + framework.Failf("Failed to delete pod %s: %v", testAgnhostPod.Name, err) + } + }() + Expect(f.WaitForPodRunning(testAgnhostPod.Name)).NotTo(HaveOccurred(), "failed to wait for pod %s to be running", testAgnhostPod.Name) + + runCommand := func(arg string) string { + cmd := []string{"/agnhost", arg} + stdout, stderr, err := f.ExecWithOptions(framework.ExecOptions{ + Command: cmd, + Namespace: f.Namespace.Name, + PodName: testAgnhostPod.Name, + ContainerName: "agnhost", + CaptureStdout: true, + CaptureStderr: true, + }) + Expect(err).NotTo(HaveOccurred(), "failed to run command '/agnhost %s' on pod, stdout: %v, stderr: %v, err: %v", arg, stdout, stderr, err) + return stdout + } + + By("Verifying customized DNS suffix list is configured on pod...") + stdout := runCommand("dns-suffix") + if !strings.Contains(stdout, testSearchPath) { + framework.Failf("customized DNS suffix list not found configured in pod, expected to contain: %s, got: %s", testSearchPath, stdout) + } + + By("Verifying customized DNS server is configured on pod...") + stdout = runCommand("dns-server-list") + if !strings.Contains(stdout, testServerIP) { + framework.Failf("customized DNS server not found in configured in pod, expected to contain: %s, got: %s", testServerIP, stdout) + } + }) + It("should support configurable pod resolv.conf", func() { By("Preparing a test DNS service with injected DNS names...") testInjectedIP := "1.1.1.1"