Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Adds configurable pod DNS nameservers and search list test #76508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to note that long term we need to decouple the framework from the parent folder (test).
this utility function seems fine for now, but are there going to be other consumers of this image apart from It("should support configurable pod DNS....?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping in mind that this image is supposed to be extendable and used whenever we have significant differences between Windows and Linux (especially commands), yes.

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))
Expand Down
48 changes: 48 additions & 0 deletions test/e2e/network/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down