Merge pull request #76508 from bclau/tests/agnhost-custom-dns-test

tests: Adds configurable pod DNS nameservers and search list test
This commit is contained in:
Kubernetes Prow Robot 2019-05-07 14:30:49 -07:00 committed by GitHub
commit eacae8540a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View File

@ -4865,6 +4865,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))

View File

@ -362,6 +362,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"