Skip to content

Commit 844426f

Browse files
committed
e2e tests: Enables should test kubelet managed /etc/hosts file for Windows
We previously skipped this test because Docker did not support mounting individual files in Containers. Since then, support for Docker has been removed, and containerd on Windows supports this feature. We can run this test on Windows.
1 parent 8e5b26b commit 844426f

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
@@ -2221,15 +2221,14 @@
22212221
file: test/e2e/common/node/kubelet.go
22222222
- testname: Kubelet, managed etc hosts
22232223
codename: '[sig-node] KubeletManagedEtcHosts should test kubelet managed /etc/hosts
2224-
file [LinuxOnly] [NodeConformance] [Conformance]'
2224+
file [NodeConformance] [Conformance]'
22252225
description: Create a Pod with containers with hostNetwork set to false, one of
22262226
the containers mounts the /etc/hosts file form the host. Create a second Pod with
22272227
hostNetwork set to true. 1. The Pod with hostNetwork=false MUST have /etc/hosts
22282228
of containers managed by the Kubelet. 2. The Pod with hostNetwork=false but the
22292229
container mounts /etc/hosts file from the host. The /etc/hosts file MUST not be
22302230
managed by the Kubelet. 3. The Pod with hostNetwork=true , /etc/hosts file MUST
2231-
not be managed by the Kubelet. This test is marked LinuxOnly since Windows cannot
2232-
mount individual files in Containers.
2231+
not be managed by the Kubelet.
22332232
release: v1.9
22342233
file: test/e2e/common/node/kubelet_etc_hosts.go
22352234
- 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)