Skip to content

Commit f5c5384

Browse files
authored
Merge pull request kubernetes#124852 from claudiubelu/e2e-etc-hosts-test
e2e tests: Enables should test kubelet managed /etc/hosts file for Windows
2 parents 14ff551 + 844426f commit f5c5384

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

test/conformance/testdata/conformance.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,15 +2229,14 @@
22292229
file: test/e2e/common/node/kubelet.go
22302230
- testname: Kubelet, managed etc hosts
22312231
codename: '[sig-node] KubeletManagedEtcHosts should test kubelet managed /etc/hosts
2232-
file [LinuxOnly] [NodeConformance] [Conformance]'
2232+
file [NodeConformance] [Conformance]'
22332233
description: Create a Pod with containers with hostNetwork set to false, one of
22342234
the containers mounts the /etc/hosts file form the host. Create a second Pod with
22352235
hostNetwork set to true. 1. The Pod with hostNetwork=false MUST have /etc/hosts
22362236
of containers managed by the Kubelet. 2. The Pod with hostNetwork=false but the
22372237
container mounts /etc/hosts file from the host. The /etc/hosts file MUST not be
22382238
managed by the Kubelet. 3. The Pod with hostNetwork=true , /etc/hosts file MUST
2239-
not be managed by the Kubelet. This test is marked LinuxOnly since Windows cannot
2240-
mount individual files in Containers.
2239+
not be managed by the Kubelet.
22412240
release: v1.9
22422241
file: test/e2e/common/node/kubelet_etc_hosts.go
22432242
- testname: lease API should be available

test/e2e/common/node/kubelet_etc_hosts.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import (
3131
)
3232

3333
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`
3941
)
4042

4143
// KubeletManagedHostConfig defines the types for running managed etc hosts test cases
@@ -59,9 +61,8 @@ var _ = SIGDescribe("KubeletManagedEtcHosts", func() {
5961
1. The Pod with hostNetwork=false MUST have /etc/hosts of containers managed by the Kubelet.
6062
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.
6163
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.
6364
*/
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) {
6566
ginkgo.By("Setting up the test")
6667
config.setup(ctx)
6768

@@ -112,6 +113,7 @@ func assertManagedStatus(
112113

113114
retryCount := 0
114115
etcHostsContent := ""
116+
etcHostsPath, etcHostsOriginalPath := getEtcHostsPath()
115117

116118
for startTime := time.Now(); time.Since(startTime) < retryTimeout; {
117119
etcHostsContent = config.getFileContents(podName, name, etcHostsPath)
@@ -155,6 +157,7 @@ func (config *KubeletManagedHostConfig) getFileContents(podName, containerName,
155157
func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {
156158
hostPathType := new(v1.HostPathType)
157159
*hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate))
160+
etcHostsPath, etcHostsOriginalPath := getEtcHostsPath()
158161
mounts := []v1.VolumeMount{
159162
{
160163
Name: "host-etc-hosts",
@@ -198,6 +201,7 @@ func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {
198201
func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName string) *v1.Pod {
199202
hostPathType := new(v1.HostPathType)
200203
*hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate))
204+
etcHostsPath, etcHostsOriginalPath := getEtcHostsPath()
201205
mounts := []v1.VolumeMount{
202206
{
203207
Name: "host-etc-hosts",
@@ -230,3 +234,10 @@ func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName str
230234
}
231235
return pod
232236
}
237+
238+
func getEtcHostsPath() (string, string) {
239+
if framework.NodeOSDistroIs("windows") {
240+
return etcHostsPathWindows, etcHostsOriginalPathWindows
241+
}
242+
return etcHostsPathLinux, etcHostsOriginalPathLinux
243+
}

0 commit comments

Comments
 (0)