@@ -26,7 +26,9 @@ import (
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
27
"k8s.io/apimachinery/pkg/util/wait"
28
28
"k8s.io/kubernetes/test/e2e/framework"
29
+ e2enode "k8s.io/kubernetes/test/e2e/framework/node"
29
30
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
31
+ e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
30
32
e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
31
33
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
32
34
"k8s.io/kubernetes/test/e2e/network/common"
@@ -642,4 +644,51 @@ var _ = common.SIGDescribe("DNS HostNetwork", func() {
642
644
validateDNSResults (ctx , f , pod , append (wheezyFileNames , jessieFileNames ... ))
643
645
})
644
646
647
+ // https://issues.k8s.io/67019
648
+ ginkgo .It ("spec.Hostname field is not silently ignored and is used for hostname for a Pod" , func (ctx context.Context ) {
649
+ ginkgo .By ("Creating a pod by setting a hostname" )
650
+
651
+ testAgnhostPod := e2epod .NewAgnhostPod (f .Namespace .Name , "test-dns-hostname" , nil , nil , nil )
652
+ testAgnhostPod .Spec .Hostname = dnsTestPodHostName
653
+ testAgnhostPod , err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (ctx , testAgnhostPod , metav1.CreateOptions {})
654
+ framework .ExpectNoError (err , "failed to created pod: %s" , testAgnhostPod .Name )
655
+
656
+ err = e2epod .WaitTimeoutForPodReadyInNamespace (ctx , f .ClientSet , testAgnhostPod .Name , f .Namespace .Name , framework .PodStartTimeout )
657
+ framework .ExpectNoError (err , "failed to wait for pod %s to be running" , testAgnhostPod .Name )
658
+
659
+ stdout , err := e2eoutput .RunHostCmd (testAgnhostPod .Namespace , testAgnhostPod .Name , "hostname" )
660
+ framework .ExpectNoError (err , "failed to run command hostname: %s" , stdout )
661
+ hostname := strings .TrimSpace (stdout )
662
+ if testAgnhostPod .Spec .Hostname != hostname {
663
+ framework .Failf ("expected hostname: %s, got: %s" , testAgnhostPod .Spec .Hostname , hostname )
664
+ }
665
+ })
666
+
667
+ // https://issues.k8s.io/67019
668
+ ginkgo .It ("spec.Hostname field is silently ignored and the node hostname is used when hostNetwork is set to true for a Pod" , func (ctx context.Context ) {
669
+ ginkgo .By ("Creating a pod by setting a hostNetwork to true" )
670
+
671
+ testAgnhostPod := e2epod .NewAgnhostPod (f .Namespace .Name , "test-dns-hostnetwork" , nil , nil , nil )
672
+ testAgnhostPod .Spec .Hostname = dnsTestPodHostName
673
+ testAgnhostPod .Spec .HostNetwork = true
674
+ node , err := e2enode .GetRandomReadySchedulableNode (ctx , f .ClientSet )
675
+ framework .ExpectNoError (err )
676
+ nodeSelection := e2epod.NodeSelection {}
677
+ e2epod .SetAffinity (& nodeSelection , node .Name )
678
+ e2epod .SetNodeSelection (& testAgnhostPod .Spec , nodeSelection )
679
+
680
+ testAgnhostPod , err = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (ctx , testAgnhostPod , metav1.CreateOptions {})
681
+ framework .ExpectNoError (err , "failed to created pod: %s" , testAgnhostPod .Name )
682
+
683
+ err = e2epod .WaitTimeoutForPodReadyInNamespace (ctx , f .ClientSet , testAgnhostPod .Name , f .Namespace .Name , framework .PodStartTimeout )
684
+ framework .ExpectNoError (err , "failed to wait for pod %s to be running" , testAgnhostPod .Name )
685
+
686
+ stdout , err := e2eoutput .RunHostCmd (testAgnhostPod .Namespace , testAgnhostPod .Name , "hostname" )
687
+ framework .ExpectNoError (err , "failed to run command hostname: %s" , stdout )
688
+ hostname := strings .TrimSpace (stdout )
689
+ if node .Name != hostname {
690
+ framework .Failf ("expected hostname: %s, got: %s" , node .Name , hostname )
691
+ }
692
+ })
693
+
645
694
})
0 commit comments