Skip to content

Commit 930a132

Browse files
committed
DNS e2e tests differentiate between IP family
The e2e DNS tests differentiate between IP family to avoid false positives with dual stack clusters.
1 parent 766d79b commit 930a132

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

test/e2e/network/dns.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ var _ = SIGDescribe("DNS", func() {
4949
namesToResolve := []string{
5050
fmt.Sprintf("kubernetes.default.svc.%s", framework.TestContext.ClusterDNSDomain),
5151
}
52-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
53-
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
52+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
53+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
54+
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
5455
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
5556
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
5657

@@ -70,8 +71,9 @@ var _ = SIGDescribe("DNS", func() {
7071
namesToResolve = append(namesToResolve, "metadata")
7172
}
7273

73-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
74-
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
74+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
75+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
76+
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
7577
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
7678
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
7779

@@ -91,8 +93,9 @@ var _ = SIGDescribe("DNS", func() {
9193
}
9294
hostFQDN := fmt.Sprintf("%s.%s.%s.svc.%s", dnsTestPodHostName, dnsTestServiceName, f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
9395
hostEntries := []string{hostFQDN, dnsTestPodHostName}
94-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, hostEntries, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
95-
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, hostEntries, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
96+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
97+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, hostEntries, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
98+
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, hostEntries, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
9699
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
97100
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
98101

@@ -110,8 +113,9 @@ var _ = SIGDescribe("DNS", func() {
110113
framework.ConformanceIt("should provide /etc/hosts entries for the cluster [LinuxOnly]", func() {
111114
hostFQDN := fmt.Sprintf("%s.%s.%s.svc.%s", dnsTestPodHostName, dnsTestServiceName, f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
112115
hostEntries := []string{hostFQDN, dnsTestPodHostName}
113-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(nil, hostEntries, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
114-
jessieProbeCmd, jessieFileNames := createProbeCommand(nil, hostEntries, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
116+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
117+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(nil, hostEntries, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
118+
jessieProbeCmd, jessieFileNames := createProbeCommand(nil, hostEntries, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
115119
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
116120
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
117121

@@ -162,8 +166,9 @@ var _ = SIGDescribe("DNS", func() {
162166
fmt.Sprintf("_http._tcp.%s.%s.svc.%s", regularService.Name, f.Namespace.Name, framework.TestContext.ClusterDNSDomain),
163167
}
164168

165-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
166-
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
169+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
170+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
171+
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
167172
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
168173
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
169174

@@ -212,8 +217,9 @@ var _ = SIGDescribe("DNS", func() {
212217
fmt.Sprintf("_http._tcp.%s.%s.svc", regularService.Name, f.Namespace.Name),
213218
}
214219

215-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
216-
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
220+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
221+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
222+
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, regularService.Spec.ClusterIP, "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
217223
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
218224
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
219225

@@ -251,8 +257,9 @@ var _ = SIGDescribe("DNS", func() {
251257

252258
hostFQDN := fmt.Sprintf("%s.%s.%s.svc.%s", podHostname, serviceName, f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
253259
hostNames := []string{hostFQDN, podHostname}
254-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(nil, hostNames, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
255-
jessieProbeCmd, jessieFileNames := createProbeCommand(nil, hostNames, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
260+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
261+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(nil, hostNames, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
262+
jessieProbeCmd, jessieFileNames := createProbeCommand(nil, hostNames, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
256263
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
257264
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
258265

@@ -293,8 +300,9 @@ var _ = SIGDescribe("DNS", func() {
293300
hostFQDN := fmt.Sprintf("%s.%s.%s.svc.%s", podHostname, serviceName, f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
294301
subdomain := fmt.Sprintf("%s.%s.svc.%s", serviceName, f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
295302
namesToResolve := []string{hostFQDN, subdomain}
296-
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
297-
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain)
303+
// TODO: Validate both IPv4 and IPv6 families for dual-stack
304+
wheezyProbeCmd, wheezyFileNames := createProbeCommand(namesToResolve, nil, "", "wheezy", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
305+
jessieProbeCmd, jessieFileNames := createProbeCommand(namesToResolve, nil, "", "jessie", f.Namespace.Name, framework.TestContext.ClusterDNSDomain, framework.ClusterIsIPv6())
298306
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
299307
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
300308

@@ -365,8 +373,14 @@ var _ = SIGDescribe("DNS", func() {
365373
}
366374
})
367375
framework.ExpectNoError(err, "failed to change service type to ClusterIP for service: %s", serviceName)
368-
wheezyProbeCmd, wheezyFileName = createTargetedProbeCommand(hostFQDN, "A", "wheezy")
369-
jessieProbeCmd, jessieFileName = createTargetedProbeCommand(hostFQDN, "A", "jessie")
376+
targetRecord := "A"
377+
if framework.ClusterIsIPv6() {
378+
targetRecord = "AAAA"
379+
}
380+
// TODO: For dual stack we can run from here two createTargetedProbeCommand()
381+
// one looking for an A record and another one for an AAAA record
382+
wheezyProbeCmd, wheezyFileName = createTargetedProbeCommand(hostFQDN, targetRecord, "wheezy")
383+
jessieProbeCmd, jessieFileName = createTargetedProbeCommand(hostFQDN, targetRecord, "jessie")
370384
ginkgo.By("Running these commands on wheezy: " + wheezyProbeCmd + "\n")
371385
ginkgo.By("Running these commands on jessie: " + jessieProbeCmd + "\n")
372386

test/e2e/network/dns_common.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,18 @@ func createDNSPod(namespace, wheezyProbeCmd, jessieProbeCmd, podHostName, servic
447447
return dnsPod
448448
}
449449

450-
func createProbeCommand(namesToResolve []string, hostEntries []string, ptrLookupIP string, fileNamePrefix, namespace, dnsDomain string) (string, []string) {
450+
func createProbeCommand(namesToResolve []string, hostEntries []string, ptrLookupIP string, fileNamePrefix, namespace, dnsDomain string, isIPv6 bool) (string, []string) {
451451
fileNames := make([]string, 0, len(namesToResolve)*2)
452452
probeCmd := "for i in `seq 1 600`; do "
453+
dnsRecord := "A"
454+
if isIPv6 {
455+
dnsRecord = "AAAA"
456+
}
453457
for _, name := range namesToResolve {
454458
// Resolve by TCP and UDP DNS. Use $$(...) because $(...) is
455459
// expanded by kubernetes (though this won't expand so should
456460
// remain a literal, safe > sorry).
457-
lookup := fmt.Sprintf("%s A %s AAAA", name, name)
461+
lookup := fmt.Sprintf("%s %s", name, dnsRecord)
458462
if strings.HasPrefix(name, "_") {
459463
lookup = fmt.Sprintf("%s SRV", name)
460464
}
@@ -475,13 +479,16 @@ func createProbeCommand(namesToResolve []string, hostEntries []string, ptrLookup
475479
podARecByUDPFileName := fmt.Sprintf("%s_udp@PodARecord", fileNamePrefix)
476480
podARecByTCPFileName := fmt.Sprintf("%s_tcp@PodARecord", fileNamePrefix)
477481

478-
if framework.TestContext.IPFamily == "ipv6" {
479-
probeCmd += fmt.Sprintf(`podARec=$$(getent hosts $$(hostname | awk '{print $1}') | tr ":." "-" | awk '{print $$1".%s.pod.%s"}');`, namespace, dnsDomain)
482+
// getent doesn't work properly on Windows hosts and hostname -i doesn't return an IPv6 address
483+
// so we have to use a different command per IP family
484+
if isIPv6 {
485+
probeCmd += fmt.Sprintf(`podARec=$$(getent hosts $$(hostname -s) | tr ":." "-" | awk '{print $$1".%s.pod.%s"}');`, namespace, dnsDomain)
480486
} else {
481487
probeCmd += fmt.Sprintf(`podARec=$$(hostname -i| awk -F. '{print $$1"-"$$2"-"$$3"-"$$4".%s.pod.%s"}');`, namespace, dnsDomain)
482488
}
483-
probeCmd += fmt.Sprintf(`check="$$(dig +notcp +noall +answer +search $${podARec} A $${podARec} AAAA)" && test -n "$$check" && echo OK > /results/%s;`, podARecByUDPFileName)
484-
probeCmd += fmt.Sprintf(`check="$$(dig +tcp +noall +answer +search $${podARec} A $${podARec} AAAA)" && test -n "$$check" && echo OK > /results/%s;`, podARecByTCPFileName)
489+
490+
probeCmd += fmt.Sprintf(`check="$$(dig +notcp +noall +answer +search $${podARec} %s)" && test -n "$$check" && echo OK > /results/%s;`, dnsRecord, podARecByUDPFileName)
491+
probeCmd += fmt.Sprintf(`check="$$(dig +tcp +noall +answer +search $${podARec} %s)" && test -n "$$check" && echo OK > /results/%s;`, dnsRecord, podARecByTCPFileName)
485492
fileNames = append(fileNames, podARecByUDPFileName)
486493
fileNames = append(fileNames, podARecByTCPFileName)
487494

@@ -506,9 +513,6 @@ func createProbeCommand(namesToResolve []string, hostEntries []string, ptrLookup
506513
func createTargetedProbeCommand(nameToResolve string, lookup string, fileNamePrefix string) (string, string) {
507514
fileName := fmt.Sprintf("%s_udp@%s", fileNamePrefix, nameToResolve)
508515
nameLookup := fmt.Sprintf("%s %s", nameToResolve, lookup)
509-
if lookup == "A" {
510-
nameLookup = fmt.Sprintf("%s A %s AAAA", nameToResolve, nameToResolve)
511-
}
512516
probeCmd := fmt.Sprintf("for i in `seq 1 30`; do dig +short %s > /results/%s; sleep 1; done", nameLookup, fileName)
513517
return probeCmd, fileName
514518
}

0 commit comments

Comments
 (0)