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