Skip to content

Commit eacae85

Browse files
authored
Merge pull request kubernetes#76508 from bclau/tests/agnhost-custom-dns-test
tests: Adds configurable pod DNS nameservers and search list test
2 parents 089e5a7 + a7598c7 commit eacae85

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
@@ -4865,6 +4865,25 @@ func (f *Framework) NewTestPod(name string, requests v1.ResourceList, limits v1.
48654865
}
48664866
}
48674867

4868+
// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
4869+
// that behave the same, no matter the underlying OS.
4870+
func (f *Framework) NewAgnhostPod(name string, args ...string) *v1.Pod {
4871+
return &v1.Pod{
4872+
ObjectMeta: metav1.ObjectMeta{
4873+
Name: name,
4874+
},
4875+
Spec: v1.PodSpec{
4876+
Containers: []v1.Container{
4877+
{
4878+
Name: "agnhost",
4879+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
4880+
Args: args,
4881+
},
4882+
},
4883+
},
4884+
}
4885+
}
4886+
48684887
// CreateEmptyFileOnPod creates empty file at given path on the pod.
48694888
func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error {
48704889
_, 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
@@ -362,6 +362,54 @@ var _ = SIGDescribe("DNS", func() {
362362
validateTargetedProbeOutput(f, pod3, []string{wheezyFileName, jessieFileName}, svc.Spec.ClusterIP)
363363
})
364364

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

0 commit comments

Comments
 (0)