Skip to content

Commit a7598c7

Browse files
committed
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.
1 parent 5b47a92 commit a7598c7

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

test/e2e/framework/util.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,6 +4873,25 @@ func (f *Framework) NewTestPod(name string, requests v1.ResourceList, limits v1.
48734873
}
48744874
}
48754875

4876+
// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
4877+
// that behave the same, no matter the underlying OS.
4878+
func (f *Framework) NewAgnhostPod(name string, args ...string) *v1.Pod {
4879+
return &v1.Pod{
4880+
ObjectMeta: metav1.ObjectMeta{
4881+
Name: name,
4882+
},
4883+
Spec: v1.PodSpec{
4884+
Containers: []v1.Container{
4885+
{
4886+
Name: "agnhost",
4887+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
4888+
Args: args,
4889+
},
4890+
},
4891+
},
4892+
}
4893+
}
4894+
48764895
// CreateEmptyFileOnPod creates empty file at given path on the pod.
48774896
func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error {
48784897
_, err := RunKubectl("exec", fmt.Sprintf("--namespace=%s", namespace), podName, "--", "/bin/sh", "-c", fmt.Sprintf("touch %s", filePath))

test/e2e/network/dns.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,54 @@ var _ = SIGDescribe("DNS", func() {
361361
validateTargetedProbeOutput(f, pod3, []string{wheezyFileName, jessieFileName}, svc.Spec.ClusterIP)
362362
})
363363

364+
It("should support configurable pod DNS nameservers", func() {
365+
By("Creating a pod with dnsPolicy=None and customized dnsConfig...")
366+
testServerIP := "1.1.1.1"
367+
testSearchPath := "resolv.conf.local"
368+
testAgnhostPod := f.NewAgnhostPod(f.Namespace.Name, "pause")
369+
testAgnhostPod.Spec.DNSPolicy = v1.DNSNone
370+
testAgnhostPod.Spec.DNSConfig = &v1.PodDNSConfig{
371+
Nameservers: []string{testServerIP},
372+
Searches: []string{testSearchPath},
373+
}
374+
testAgnhostPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(testAgnhostPod)
375+
Expect(err).NotTo(HaveOccurred(), "failed to create pod: %s", testAgnhostPod.Name)
376+
framework.Logf("Created pod %v", testAgnhostPod)
377+
defer func() {
378+
framework.Logf("Deleting pod %s...", testAgnhostPod.Name)
379+
if err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(testAgnhostPod.Name, metav1.NewDeleteOptions(0)); err != nil {
380+
framework.Failf("Failed to delete pod %s: %v", testAgnhostPod.Name, err)
381+
}
382+
}()
383+
Expect(f.WaitForPodRunning(testAgnhostPod.Name)).NotTo(HaveOccurred(), "failed to wait for pod %s to be running", testAgnhostPod.Name)
384+
385+
runCommand := func(arg string) string {
386+
cmd := []string{"/agnhost", arg}
387+
stdout, stderr, err := f.ExecWithOptions(framework.ExecOptions{
388+
Command: cmd,
389+
Namespace: f.Namespace.Name,
390+
PodName: testAgnhostPod.Name,
391+
ContainerName: "agnhost",
392+
CaptureStdout: true,
393+
CaptureStderr: true,
394+
})
395+
Expect(err).NotTo(HaveOccurred(), "failed to run command '/agnhost %s' on pod, stdout: %v, stderr: %v, err: %v", arg, stdout, stderr, err)
396+
return stdout
397+
}
398+
399+
By("Verifying customized DNS suffix list is configured on pod...")
400+
stdout := runCommand("dns-suffix")
401+
if !strings.Contains(stdout, testSearchPath) {
402+
framework.Failf("customized DNS suffix list not found configured in pod, expected to contain: %s, got: %s", testSearchPath, stdout)
403+
}
404+
405+
By("Verifying customized DNS server is configured on pod...")
406+
stdout = runCommand("dns-server-list")
407+
if !strings.Contains(stdout, testServerIP) {
408+
framework.Failf("customized DNS server not found in configured in pod, expected to contain: %s, got: %s", testServerIP, stdout)
409+
}
410+
})
411+
364412
It("should support configurable pod resolv.conf", func() {
365413
By("Preparing a test DNS service with injected DNS names...")
366414
testInjectedIP := "1.1.1.1"

0 commit comments

Comments
 (0)