diff --git a/test/e2e/network/dns.go b/test/e2e/network/dns.go index 7f41ced62f1..a6ffc7f47b9 100644 --- a/test/e2e/network/dns.go +++ b/test/e2e/network/dns.go @@ -318,4 +318,5 @@ var _ = SIGDescribe("DNS", func() { // TODO: Add more test cases for other DNSPolicies. }) + }) diff --git a/test/e2e/network/dns_common.go b/test/e2e/network/dns_common.go index 1400f42e0ed..2e6bd200c7a 100644 --- a/test/e2e/network/dns_common.go +++ b/test/e2e/network/dns_common.go @@ -110,6 +110,9 @@ func (t *dnsTestCommon) runDig(dnsName, target string) []string { default: panic(fmt.Errorf("invalid target: " + target)) } + if strings.HasSuffix(dnsName, "in-addr.arpa") || strings.HasSuffix(dnsName, "in-addr.arpa.") { + cmd = append(cmd, []string{"-t", "ptr"}...) + } cmd = append(cmd, dnsName) stdout, stderr, err := t.f.ExecWithOptions(framework.ExecOptions{ @@ -266,8 +269,8 @@ func generateDNSServerPod(aRecords map[string]string) *v1.Pod { return pod } -func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) { - t.dnsServerPod = generateDNSServerPod(aRecords) +func (t *dnsTestCommon) createDNSPodFromObj(pod *v1.Pod) { + t.dnsServerPod = pod var err error t.dnsServerPod, err = t.c.CoreV1().Pods(t.f.Namespace.Name).Create(t.dnsServerPod) @@ -280,6 +283,40 @@ func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) { Expect(err).NotTo(HaveOccurred()) } +func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) { + t.createDNSPodFromObj(generateDNSServerPod(aRecords)) +} + +func (t *dnsTestCommon) createDNSServerWithPtrRecord() { + pod := &v1.Pod{ + TypeMeta: metav1.TypeMeta{ + Kind: "Pod", + }, + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "e2e-dns-configmap-dns-server-", + }, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "dns", + Image: imageutils.GetE2EImage(imageutils.DNSMasq), + Command: []string{ + "/usr/sbin/dnsmasq", + "-u", "root", + "-k", + "--log-facility", "-", + "--host-record=my.test,192.0.2.123", + "-q", + }, + }, + }, + DNSPolicy: "Default", + }, + } + + t.createDNSPodFromObj(pod) +} + func (t *dnsTestCommon) deleteDNSServerPod() { podClient := t.c.CoreV1().Pods(t.f.Namespace.Name) if err := podClient.Delete(t.dnsServerPod.Name, metav1.NewDeleteOptions(0)); err != nil { diff --git a/test/e2e/network/dns_configmap.go b/test/e2e/network/dns_configmap.go index 3e11edc08b7..8c981402426 100644 --- a/test/e2e/network/dns_configmap.go +++ b/test/e2e/network/dns_configmap.go @@ -34,10 +34,10 @@ type dnsFederationsConfigMapTest struct { } var _ = SIGDescribe("DNS configMap federations", func() { - t := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()} - BeforeEach(func() { t.c = t.f.ClientSet }) It("should be able to change federation configuration [Slow][Serial]", func() { + t := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()} + t.c = t.f.ClientSet t.run() }) }) @@ -185,11 +185,50 @@ func (t *dnsNameserverTest) run() { moreForeverTestTimeout) } +type dnsPtrFwdTest struct { + dnsTestCommon +} + +func (t *dnsPtrFwdTest) run() { + t.init() + + t.createUtilPod() + defer t.deleteUtilPod() + + t.createDNSServerWithPtrRecord() + defer t.deleteDNSServerPod() + + t.setConfigMap(&v1.ConfigMap{Data: map[string]string{ + "upstreamNameservers": fmt.Sprintf(`["%v"]`, t.dnsServerPod.Status.PodIP), + }}) + + moreForeverTestTimeout := 2 * 60 * time.Second + + t.checkDNSRecordFrom( + "123.2.0.192.in-addr.arpa", + func(actual []string) bool { return len(actual) == 1 && actual[0] == "my.test." }, + "dnsmasq", + moreForeverTestTimeout) + + t.c.CoreV1().ConfigMaps(t.ns).Delete(t.name, nil) + t.checkDNSRecordFrom( + "123.2.0.192.in-addr.arpa", + func(actual []string) bool { return len(actual) == 0 }, + "dnsmasq", + moreForeverTestTimeout) +} + var _ = SIGDescribe("DNS configMap nameserver", func() { - t := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()} - BeforeEach(func() { t.c = t.f.ClientSet }) It("should be able to change stubDomain configuration [Slow][Serial]", func() { - t.run() + nsTest := &dnsNameserverTest{dnsTestCommon: newDnsTestCommon()} + nsTest.c = nsTest.f.ClientSet + nsTest.run() + }) + + It("should forward PTR records lookup to upstream nameserver [Slow][Serial]", func() { + fwdTest := &dnsPtrFwdTest{dnsTestCommon: newDnsTestCommon()} + fwdTest.c = fwdTest.f.ClientSet + fwdTest.run() }) })