@@ -19,6 +19,7 @@ package network
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "regexp"
22
23
"strings"
23
24
"time"
24
25
@@ -40,6 +41,9 @@ import (
40
41
"github.com/onsi/gomega"
41
42
)
42
43
44
+ // Windows output can contain additional \r
45
+ var newLineRegexp = regexp .MustCompile ("\r ?\n " )
46
+
43
47
type dnsTestCommon struct {
44
48
f * framework.Framework
45
49
c clientset.Interface
@@ -104,7 +108,7 @@ func (t *dnsTestCommon) checkDNSRecordFrom(name string, predicate func([]string)
104
108
105
109
// runDig queries for `dnsName`. Returns a list of responses.
106
110
func (t * dnsTestCommon ) runDig (dnsName , target string ) []string {
107
- cmd := []string {"/usr/bin/ dig" , "+short" }
111
+ cmd := []string {"dig" , "+short" }
108
112
switch target {
109
113
case "coredns" :
110
114
cmd = append (cmd , "@" + t .dnsPod .Status .PodIP )
@@ -135,7 +139,7 @@ func (t *dnsTestCommon) runDig(dnsName, target string) []string {
135
139
if stdout == "" {
136
140
return []string {}
137
141
}
138
- return strings .Split (stdout , " \n " )
142
+ return newLineRegexp .Split (stdout , - 1 )
139
143
}
140
144
141
145
func (t * dnsTestCommon ) setConfigMap (cm * v1.ConfigMap ) {
@@ -208,7 +212,7 @@ func (t *dnsTestCommon) createUtilPodLabel(baseName string) {
208
212
Containers : []v1.Container {
209
213
{
210
214
Name : "util" ,
211
- Image : imageutils .GetE2EImage (imageutils .Dnsutils ),
215
+ Image : imageutils .GetE2EImage (imageutils .Agnhost ),
212
216
Command : []string {"sleep" , "10000" },
213
217
Ports : []v1.ContainerPort {
214
218
{ContainerPort : servicePort , Protocol : v1 .ProtocolTCP },
@@ -274,38 +278,70 @@ func (t *dnsTestCommon) deleteCoreDNSPods() {
274
278
}
275
279
}
276
280
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 {
279
283
TypeMeta : metav1.TypeMeta {
280
284
Kind : "Pod" ,
281
285
},
282
286
ObjectMeta : metav1.ObjectMeta {
283
287
GenerateName : "e2e-dns-configmap-dns-server-" ,
284
288
},
285
289
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
+ },
286
302
Containers : []v1.Container {
287
303
{
288
304
Name : "dns" ,
289
- Image : imageutils .GetE2EImage (imageutils .Dnsutils ),
305
+ Image : imageutils .GetE2EImage (imageutils .Agnhost ),
290
306
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
+ },
296
316
},
297
317
},
298
318
},
299
319
DNSPolicy : "Default" ,
300
320
},
301
321
}
322
+ }
302
323
324
+ func generateCoreDNSConfigmap (namespaceName string , aRecords map [string ]string ) * v1.ConfigMap {
325
+ entries := ""
303
326
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
+ },
307
344
}
308
- return pod
309
345
}
310
346
311
347
func (t * dnsTestCommon ) createDNSPodFromObj (pod * v1.Pod ) {
@@ -322,47 +358,26 @@ func (t *dnsTestCommon) createDNSPodFromObj(pod *v1.Pod) {
322
358
framework .ExpectNoError (err , "failed to get pod: %s" , t .dnsServerPod .Name )
323
359
}
324
360
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 )
353
366
}
354
367
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
355
375
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" }
359
377
} 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" }
363
379
}
364
-
365
- t .createDNSPodFromObj (pod )
380
+ t .createDNSServer (namespace , aRecords )
366
381
}
367
382
368
383
func (t * dnsTestCommon ) deleteDNSServerPod () {
@@ -413,7 +428,7 @@ func createDNSPod(namespace, wheezyProbeCmd, jessieProbeCmd, podHostName, servic
413
428
},
414
429
{
415
430
Name : "querier" ,
416
- Image : imageutils .GetE2EImage (imageutils .Dnsutils ),
431
+ Image : imageutils .GetE2EImage (imageutils .Agnhost ),
417
432
Command : []string {"sh" , "-c" , wheezyProbeCmd },
418
433
VolumeMounts : []v1.VolumeMount {
419
434
{
@@ -622,7 +637,7 @@ func generateDNSUtilsPod() *v1.Pod {
622
637
Containers : []v1.Container {
623
638
{
624
639
Name : "util" ,
625
- Image : imageutils .GetE2EImage (imageutils .Dnsutils ),
640
+ Image : imageutils .GetE2EImage (imageutils .Agnhost ),
626
641
Command : []string {"sleep" , "10000" },
627
642
},
628
643
},
0 commit comments