@@ -361,6 +361,54 @@ var _ = SIGDescribe("DNS", func() {
361
361
validateTargetedProbeOutput (f , pod3 , []string {wheezyFileName , jessieFileName }, svc .Spec .ClusterIP )
362
362
})
363
363
364
+ It ("should support configurable pod DNS nameservers" , func () {
365
+ By ("Creating a pod with dnsPolicy=None and customized dnsConfig..." )
366
+ testServerIP := "1.1.1.1"
367
+ testSearchPath := "resolv.conf.local"
368
+ testAgnhostPod := f .NewAgnhostPod (f .Namespace .Name , "pause" )
369
+ testAgnhostPod .Spec .DNSPolicy = v1 .DNSNone
370
+ testAgnhostPod .Spec .DNSConfig = & v1.PodDNSConfig {
371
+ Nameservers : []string {testServerIP },
372
+ Searches : []string {testSearchPath },
373
+ }
374
+ testAgnhostPod , err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (testAgnhostPod )
375
+ Expect (err ).NotTo (HaveOccurred (), "failed to create pod: %s" , testAgnhostPod .Name )
376
+ framework .Logf ("Created pod %v" , testAgnhostPod )
377
+ defer func () {
378
+ framework .Logf ("Deleting pod %s..." , testAgnhostPod .Name )
379
+ if err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Delete (testAgnhostPod .Name , metav1 .NewDeleteOptions (0 )); err != nil {
380
+ framework .Failf ("Failed to delete pod %s: %v" , testAgnhostPod .Name , err )
381
+ }
382
+ }()
383
+ Expect (f .WaitForPodRunning (testAgnhostPod .Name )).NotTo (HaveOccurred (), "failed to wait for pod %s to be running" , testAgnhostPod .Name )
384
+
385
+ runCommand := func (arg string ) string {
386
+ cmd := []string {"/agnhost" , arg }
387
+ stdout , stderr , err := f .ExecWithOptions (framework.ExecOptions {
388
+ Command : cmd ,
389
+ Namespace : f .Namespace .Name ,
390
+ PodName : testAgnhostPod .Name ,
391
+ ContainerName : "agnhost" ,
392
+ CaptureStdout : true ,
393
+ CaptureStderr : true ,
394
+ })
395
+ Expect (err ).NotTo (HaveOccurred (), "failed to run command '/agnhost %s' on pod, stdout: %v, stderr: %v, err: %v" , arg , stdout , stderr , err )
396
+ return stdout
397
+ }
398
+
399
+ By ("Verifying customized DNS suffix list is configured on pod..." )
400
+ stdout := runCommand ("dns-suffix" )
401
+ if ! strings .Contains (stdout , testSearchPath ) {
402
+ framework .Failf ("customized DNS suffix list not found configured in pod, expected to contain: %s, got: %s" , testSearchPath , stdout )
403
+ }
404
+
405
+ By ("Verifying customized DNS server is configured on pod..." )
406
+ stdout = runCommand ("dns-server-list" )
407
+ if ! strings .Contains (stdout , testServerIP ) {
408
+ framework .Failf ("customized DNS server not found in configured in pod, expected to contain: %s, got: %s" , testServerIP , stdout )
409
+ }
410
+ })
411
+
364
412
It ("should support configurable pod resolv.conf" , func () {
365
413
By ("Preparing a test DNS service with injected DNS names..." )
366
414
testInjectedIP := "1.1.1.1"
0 commit comments