Skip to content

Commit c57f20b

Browse files
committed
tests: Replaces dnsutils image used with agnhost (part 4)
Quite a few images are only used a few times in a few tests. Thus, the images are being centralized into the agnhost image, reducing the number of images that have to be pulled and used. This PR replaces the usage of the following images with agnhost: - dnsutils dnsmasq is a Linux specific binary. In order for the tests to also pass on Windows, CoreDNS should be used instead.
1 parent f692f5c commit c57f20b

File tree

5 files changed

+88
-65
lines changed

5 files changed

+88
-65
lines changed

test/e2e/network/dns.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,20 @@ var _ = SIGDescribe("DNS", func() {
460460
testSearchPath := "resolv.conf.local"
461461
testDNSNameFull := fmt.Sprintf("%s.%s", testDNSNameShort, testSearchPath)
462462

463-
testServerPod := generateDNSServerPod(map[string]string{
463+
corednsConfig := generateCoreDNSConfigmap(f.Namespace.Name, map[string]string{
464464
testDNSNameFull: testInjectedIP,
465465
})
466-
testServerPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), testServerPod, metav1.CreateOptions{})
466+
corednsConfig, err := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), corednsConfig, metav1.CreateOptions{})
467+
framework.ExpectNoError(err, "unable to create test configMap %s", corednsConfig.Name)
468+
469+
defer func() {
470+
framework.Logf("Deleting configmap %s...", corednsConfig.Name)
471+
err := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Delete(context.TODO(), corednsConfig.Name, nil)
472+
framework.ExpectNoError(err, "Failed to delete configmap %s: %v", corednsConfig.Name)
473+
}()
474+
475+
testServerPod := generateCoreDNSServerPod(corednsConfig)
476+
testServerPod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), testServerPod, metav1.CreateOptions{})
467477
framework.ExpectNoError(err, "failed to create pod: %s", testServerPod.Name)
468478
framework.Logf("Created pod %v", testServerPod)
469479
defer func() {
@@ -528,7 +538,7 @@ var _ = SIGDescribe("DNS", func() {
528538
// This verifies both:
529539
// - Custom search path is appended.
530540
// - DNS query is sent to the specified server.
531-
cmd = []string{"/usr/bin/dig", "+short", "+search", testDNSNameShort}
541+
cmd = []string{"dig", "+short", "+search", testDNSNameShort}
532542
digFunc := func() (bool, error) {
533543
stdout, stderr, err := f.ExecWithOptions(framework.ExecOptions{
534544
Command: cmd,

test/e2e/network/dns_common.go

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package network
1919
import (
2020
"context"
2121
"fmt"
22+
"regexp"
2223
"strings"
2324
"time"
2425

@@ -40,6 +41,9 @@ import (
4041
"github.com/onsi/gomega"
4142
)
4243

44+
// Windows output can contain additional \r
45+
var newLineRegexp = regexp.MustCompile("\r?\n")
46+
4347
type dnsTestCommon struct {
4448
f *framework.Framework
4549
c clientset.Interface
@@ -104,7 +108,7 @@ func (t *dnsTestCommon) checkDNSRecordFrom(name string, predicate func([]string)
104108

105109
// runDig queries for `dnsName`. Returns a list of responses.
106110
func (t *dnsTestCommon) runDig(dnsName, target string) []string {
107-
cmd := []string{"/usr/bin/dig", "+short"}
111+
cmd := []string{"dig", "+short"}
108112
switch target {
109113
case "coredns":
110114
cmd = append(cmd, "@"+t.dnsPod.Status.PodIP)
@@ -135,7 +139,7 @@ func (t *dnsTestCommon) runDig(dnsName, target string) []string {
135139
if stdout == "" {
136140
return []string{}
137141
}
138-
return strings.Split(stdout, "\n")
142+
return newLineRegexp.Split(stdout, -1)
139143
}
140144

141145
func (t *dnsTestCommon) setConfigMap(cm *v1.ConfigMap) {
@@ -208,7 +212,7 @@ func (t *dnsTestCommon) createUtilPodLabel(baseName string) {
208212
Containers: []v1.Container{
209213
{
210214
Name: "util",
211-
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
215+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
212216
Command: []string{"sleep", "10000"},
213217
Ports: []v1.ContainerPort{
214218
{ContainerPort: servicePort, Protocol: v1.ProtocolTCP},
@@ -274,38 +278,70 @@ func (t *dnsTestCommon) deleteCoreDNSPods() {
274278
}
275279
}
276280

277-
func generateDNSServerPod(aRecords map[string]string) *v1.Pod {
278-
pod := &v1.Pod{
281+
func generateCoreDNSServerPod(corednsConfig *v1.ConfigMap) *v1.Pod {
282+
return &v1.Pod{
279283
TypeMeta: metav1.TypeMeta{
280284
Kind: "Pod",
281285
},
282286
ObjectMeta: metav1.ObjectMeta{
283287
GenerateName: "e2e-dns-configmap-dns-server-",
284288
},
285289
Spec: v1.PodSpec{
290+
Volumes: []v1.Volume{
291+
{
292+
Name: "coredns-config",
293+
VolumeSource: v1.VolumeSource{
294+
ConfigMap: &v1.ConfigMapVolumeSource{
295+
LocalObjectReference: v1.LocalObjectReference{
296+
Name: corednsConfig.Name,
297+
},
298+
},
299+
},
300+
},
301+
},
286302
Containers: []v1.Container{
287303
{
288304
Name: "dns",
289-
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
305+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
290306
Command: []string{
291-
"/usr/sbin/dnsmasq",
292-
"-u", "root",
293-
"-k",
294-
"--log-facility", "-",
295-
"-q",
307+
"/coredns",
308+
"-conf", "/etc/coredns/Corefile",
309+
},
310+
VolumeMounts: []v1.VolumeMount{
311+
{
312+
Name: "coredns-config",
313+
MountPath: "/etc/coredns",
314+
ReadOnly: true,
315+
},
296316
},
297317
},
298318
},
299319
DNSPolicy: "Default",
300320
},
301321
}
322+
}
302323

324+
func generateCoreDNSConfigmap(namespaceName string, aRecords map[string]string) *v1.ConfigMap {
325+
entries := ""
303326
for name, ip := range aRecords {
304-
pod.Spec.Containers[0].Command = append(
305-
pod.Spec.Containers[0].Command,
306-
fmt.Sprintf("-A/%v/%v", name, ip))
327+
entries += fmt.Sprintf("\n\t\t%v %v", ip, name)
328+
}
329+
330+
corefileData := fmt.Sprintf(`. {
331+
hosts {%s
332+
}
333+
log
334+
}`, entries)
335+
336+
return &v1.ConfigMap{
337+
ObjectMeta: metav1.ObjectMeta{
338+
Namespace: namespaceName,
339+
GenerateName: "e2e-coredns-configmap-",
340+
},
341+
Data: map[string]string{
342+
"Corefile": corefileData,
343+
},
307344
}
308-
return pod
309345
}
310346

311347
func (t *dnsTestCommon) createDNSPodFromObj(pod *v1.Pod) {
@@ -322,47 +358,26 @@ func (t *dnsTestCommon) createDNSPodFromObj(pod *v1.Pod) {
322358
framework.ExpectNoError(err, "failed to get pod: %s", t.dnsServerPod.Name)
323359
}
324360

325-
func (t *dnsTestCommon) createDNSServer(aRecords map[string]string) {
326-
t.createDNSPodFromObj(generateDNSServerPod(aRecords))
327-
}
328-
329-
func (t *dnsTestCommon) createDNSServerWithPtrRecord(isIPv6 bool) {
330-
pod := &v1.Pod{
331-
TypeMeta: metav1.TypeMeta{
332-
Kind: "Pod",
333-
},
334-
ObjectMeta: metav1.ObjectMeta{
335-
GenerateName: "e2e-dns-configmap-dns-server-",
336-
},
337-
Spec: v1.PodSpec{
338-
Containers: []v1.Container{
339-
{
340-
Name: "dns",
341-
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
342-
Command: []string{
343-
"/usr/sbin/dnsmasq",
344-
"-u", "root",
345-
"-k",
346-
"--log-facility", "-",
347-
"-q",
348-
},
349-
},
350-
},
351-
DNSPolicy: "Default",
352-
},
361+
func (t *dnsTestCommon) createDNSServer(namespace string, aRecords map[string]string) {
362+
corednsConfig := generateCoreDNSConfigmap(namespace, aRecords)
363+
corednsConfig, err := t.c.CoreV1().ConfigMaps(namespace).Create(context.TODO(), corednsConfig, metav1.CreateOptions{})
364+
if err != nil {
365+
framework.Failf("unable to create test configMap %s: %v", corednsConfig.Name, err)
353366
}
354367

368+
t.createDNSPodFromObj(generateCoreDNSServerPod(corednsConfig))
369+
}
370+
371+
func (t *dnsTestCommon) createDNSServerWithPtrRecord(namespace string, isIPv6 bool) {
372+
// NOTE: PTR records are generated automatically by CoreDNS. So, if we're creating A records, we're
373+
// going to also have PTR records. See: https://coredns.io/plugins/hosts/
374+
var aRecords map[string]string
355375
if isIPv6 {
356-
pod.Spec.Containers[0].Command = append(
357-
pod.Spec.Containers[0].Command,
358-
fmt.Sprintf("--host-record=my.test,2001:db8::29"))
376+
aRecords = map[string]string{"my.test": "2001:db8::29"}
359377
} else {
360-
pod.Spec.Containers[0].Command = append(
361-
pod.Spec.Containers[0].Command,
362-
fmt.Sprintf("--host-record=my.test,192.0.2.123"))
378+
aRecords = map[string]string{"my.test": "192.0.2.123"}
363379
}
364-
365-
t.createDNSPodFromObj(pod)
380+
t.createDNSServer(namespace, aRecords)
366381
}
367382

368383
func (t *dnsTestCommon) deleteDNSServerPod() {
@@ -413,7 +428,7 @@ func createDNSPod(namespace, wheezyProbeCmd, jessieProbeCmd, podHostName, servic
413428
},
414429
{
415430
Name: "querier",
416-
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
431+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
417432
Command: []string{"sh", "-c", wheezyProbeCmd},
418433
VolumeMounts: []v1.VolumeMount{
419434
{
@@ -622,7 +637,7 @@ func generateDNSUtilsPod() *v1.Pod {
622637
Containers: []v1.Container{
623638
{
624639
Name: "util",
625-
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
640+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
626641
Command: []string{"sleep", "10000"},
627642
},
628643
},

test/e2e/network/dns_configmap.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ func (t *dnsNameserverTest) run(isIPv6 bool) {
221221
defer t.restoreDNSConfigMap(originalConfigMapData)
222222

223223
if isIPv6 {
224-
t.createDNSServer(map[string]string{
224+
t.createDNSServer(t.f.Namespace.Name, map[string]string{
225225
"abc.acme.local": "2606:4700:4700::1111",
226226
"def.acme.local": "2606:4700:4700::2222",
227227
"widget.local": "2606:4700:4700::3333",
228228
})
229229
} else {
230-
t.createDNSServer(map[string]string{
230+
t.createDNSServer(t.f.Namespace.Name, map[string]string{
231231
"abc.acme.local": "1.1.1.1",
232232
"def.acme.local": "2.2.2.2",
233233
"widget.local": "3.3.3.3",
@@ -317,7 +317,7 @@ func (t *dnsPtrFwdTest) run(isIPv6 bool) {
317317
originalConfigMapData := t.fetchDNSConfigMapData()
318318
defer t.restoreDNSConfigMap(originalConfigMapData)
319319

320-
t.createDNSServerWithPtrRecord(isIPv6)
320+
t.createDNSServerWithPtrRecord(t.f.Namespace.Name, isIPv6)
321321
defer t.deleteDNSServerPod()
322322

323323
// Should still be able to lookup public nameserver without explicit upstream nameserver set.
@@ -401,11 +401,11 @@ func (t *dnsExternalNameTest) run(isIPv6 bool) {
401401

402402
fooHostname := "foo.example.com"
403403
if isIPv6 {
404-
t.createDNSServer(map[string]string{
404+
t.createDNSServer(t.f.Namespace.Name, map[string]string{
405405
fooHostname: "2001:db8::29",
406406
})
407407
} else {
408-
t.createDNSServer(map[string]string{
408+
t.createDNSServer(t.f.Namespace.Name, map[string]string{
409409
fooHostname: "192.0.2.123",
410410
})
411411
}

test/e2e/windows/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func generateDNSUtilsPod() *v1.Pod {
102102
Containers: []v1.Container{
103103
{
104104
Name: "util",
105-
Image: imageutils.GetE2EImage(imageutils.Dnsutils),
105+
Image: imageutils.GetE2EImage(imageutils.Agnhost),
106106
Command: []string{"sleep", "10000"},
107107
},
108108
},

test/utils/image/manifest.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func initReg() RegistryList {
7070
DockerLibraryRegistry: "docker.io/library",
7171
DockerGluster: "docker.io/gluster",
7272
E2eRegistry: "gcr.io/kubernetes-e2e-test-images",
73+
// TODO: After the domain flip, this should instead be k8s.gcr.io/k8s-artifacts-prod/e2e-test-images
7374
PromoterE2eRegistry: "us.gcr.io/k8s-artifacts-prod/e2e-test-images",
7475
InvalidRegistry: "invalid.com/invalid",
7576
GcRegistry: "k8s.gcr.io",
@@ -139,8 +140,6 @@ const (
139140
CudaVectorAdd
140141
// CudaVectorAdd2 image
141142
CudaVectorAdd2
142-
// Dnsutils image
143-
Dnsutils
144143
// EchoServer image
145144
EchoServer
146145
// Etcd image
@@ -216,7 +215,6 @@ func initImageConfigs() map[int]Config {
216215
configs[CheckMetadataConcealment] = Config{e2eRegistry, "metadata-concealment", "1.2"}
217216
configs[CudaVectorAdd] = Config{e2eRegistry, "cuda-vector-add", "1.0"}
218217
configs[CudaVectorAdd2] = Config{e2eRegistry, "cuda-vector-add", "2.0"}
219-
configs[Dnsutils] = Config{e2eRegistry, "dnsutils", "1.1"}
220218
configs[EchoServer] = Config{e2eRegistry, "echoserver", "2.2"}
221219
configs[Etcd] = Config{gcRegistry, "etcd", "3.4.3"}
222220
configs[GlusterDynamicProvisioner] = Config{dockerGluster, "glusterdynamic-provisioner", "v1.0"}

0 commit comments

Comments
 (0)