@@ -31,11 +31,13 @@ import (
31
31
)
32
32
33
33
const (
34
- etcHostsPodName = "test-pod"
35
- etcHostsHostNetworkPodName = "test-host-network-pod"
36
- etcHostsPartialContent = "# Kubernetes-managed hosts file."
37
- etcHostsPath = "/etc/hosts"
38
- etcHostsOriginalPath = "/etc/hosts-original"
34
+ etcHostsPodName = "test-pod"
35
+ etcHostsHostNetworkPodName = "test-host-network-pod"
36
+ etcHostsPartialContent = "# Kubernetes-managed hosts file."
37
+ etcHostsPathLinux = "/etc/hosts"
38
+ etcHostsPathWindows = `C:\Windows\System32\drivers\etc\hosts`
39
+ etcHostsOriginalPathLinux = "/etc/hosts-original"
40
+ etcHostsOriginalPathWindows = `C:\Windows\System32\drivers\etc\hosts-original`
39
41
)
40
42
41
43
// KubeletManagedHostConfig defines the types for running managed etc hosts test cases
@@ -59,9 +61,8 @@ var _ = SIGDescribe("KubeletManagedEtcHosts", func() {
59
61
1. The Pod with hostNetwork=false MUST have /etc/hosts of containers managed by the Kubelet.
60
62
2. The Pod with hostNetwork=false but the container mounts /etc/hosts file from the host. The /etc/hosts file MUST not be managed by the Kubelet.
61
63
3. The Pod with hostNetwork=true , /etc/hosts file MUST not be managed by the Kubelet.
62
- This test is marked LinuxOnly since Windows cannot mount individual files in Containers.
63
64
*/
64
- framework .ConformanceIt ("should test kubelet managed /etc/hosts file [LinuxOnly] " , f .WithNodeConformance (), func (ctx context.Context ) {
65
+ framework .ConformanceIt ("should test kubelet managed /etc/hosts file" , f .WithNodeConformance (), func (ctx context.Context ) {
65
66
ginkgo .By ("Setting up the test" )
66
67
config .setup (ctx )
67
68
@@ -112,6 +113,7 @@ func assertManagedStatus(
112
113
113
114
retryCount := 0
114
115
etcHostsContent := ""
116
+ etcHostsPath , etcHostsOriginalPath := getEtcHostsPath ()
115
117
116
118
for startTime := time .Now (); time .Since (startTime ) < retryTimeout ; {
117
119
etcHostsContent = config .getFileContents (podName , name , etcHostsPath )
@@ -155,6 +157,7 @@ func (config *KubeletManagedHostConfig) getFileContents(podName, containerName,
155
157
func (config * KubeletManagedHostConfig ) createPodSpec (podName string ) * v1.Pod {
156
158
hostPathType := new (v1.HostPathType )
157
159
* hostPathType = v1 .HostPathType (string (v1 .HostPathFileOrCreate ))
160
+ etcHostsPath , etcHostsOriginalPath := getEtcHostsPath ()
158
161
mounts := []v1.VolumeMount {
159
162
{
160
163
Name : "host-etc-hosts" ,
@@ -198,6 +201,7 @@ func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {
198
201
func (config * KubeletManagedHostConfig ) createPodSpecWithHostNetwork (podName string ) * v1.Pod {
199
202
hostPathType := new (v1.HostPathType )
200
203
* hostPathType = v1 .HostPathType (string (v1 .HostPathFileOrCreate ))
204
+ etcHostsPath , etcHostsOriginalPath := getEtcHostsPath ()
201
205
mounts := []v1.VolumeMount {
202
206
{
203
207
Name : "host-etc-hosts" ,
@@ -230,3 +234,10 @@ func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName str
230
234
}
231
235
return pod
232
236
}
237
+
238
+ func getEtcHostsPath () (string , string ) {
239
+ if framework .NodeOSDistroIs ("windows" ) {
240
+ return etcHostsPathWindows , etcHostsOriginalPathWindows
241
+ }
242
+ return etcHostsPathLinux , etcHostsOriginalPathLinux
243
+ }
0 commit comments