From 844426f5e0e397996d2d19b1d90db4130c7f01c5 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Mon, 13 May 2024 17:22:30 +0000 Subject: [PATCH] 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. --- test/conformance/testdata/conformance.yaml | 5 ++--- test/e2e/common/node/kubelet_etc_hosts.go | 25 ++++++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/test/conformance/testdata/conformance.yaml b/test/conformance/testdata/conformance.yaml index 57f23a37e3f..183f70f8c31 100755 --- a/test/conformance/testdata/conformance.yaml +++ b/test/conformance/testdata/conformance.yaml @@ -2221,15 +2221,14 @@ file: test/e2e/common/node/kubelet.go - testname: Kubelet, managed etc hosts codename: '[sig-node] KubeletManagedEtcHosts should test kubelet managed /etc/hosts - file [LinuxOnly] [NodeConformance] [Conformance]' + file [NodeConformance] [Conformance]' description: Create a Pod with containers with hostNetwork set to false, one of the containers mounts the /etc/hosts file form the host. Create a second Pod with hostNetwork set to true. 1. The Pod with hostNetwork=false MUST have /etc/hosts of containers managed by the Kubelet. 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. 3. The Pod with hostNetwork=true , /etc/hosts file MUST - not be managed by the Kubelet. This test is marked LinuxOnly since Windows cannot - mount individual files in Containers. + not be managed by the Kubelet. release: v1.9 file: test/e2e/common/node/kubelet_etc_hosts.go - testname: lease API should be available diff --git a/test/e2e/common/node/kubelet_etc_hosts.go b/test/e2e/common/node/kubelet_etc_hosts.go index 3b783ddcd34..eb6a23dc826 100644 --- a/test/e2e/common/node/kubelet_etc_hosts.go +++ b/test/e2e/common/node/kubelet_etc_hosts.go @@ -31,11 +31,13 @@ import ( ) const ( - etcHostsPodName = "test-pod" - etcHostsHostNetworkPodName = "test-host-network-pod" - etcHostsPartialContent = "# Kubernetes-managed hosts file." - etcHostsPath = "/etc/hosts" - etcHostsOriginalPath = "/etc/hosts-original" + etcHostsPodName = "test-pod" + etcHostsHostNetworkPodName = "test-host-network-pod" + etcHostsPartialContent = "# Kubernetes-managed hosts file." + etcHostsPathLinux = "/etc/hosts" + etcHostsPathWindows = `C:\Windows\System32\drivers\etc\hosts` + etcHostsOriginalPathLinux = "/etc/hosts-original" + etcHostsOriginalPathWindows = `C:\Windows\System32\drivers\etc\hosts-original` ) // KubeletManagedHostConfig defines the types for running managed etc hosts test cases @@ -59,9 +61,8 @@ var _ = SIGDescribe("KubeletManagedEtcHosts", func() { 1. The Pod with hostNetwork=false MUST have /etc/hosts of containers managed by the Kubelet. 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. 3. The Pod with hostNetwork=true , /etc/hosts file MUST not be managed by the Kubelet. - This test is marked LinuxOnly since Windows cannot mount individual files in Containers. */ - framework.ConformanceIt("should test kubelet managed /etc/hosts file [LinuxOnly]", f.WithNodeConformance(), func(ctx context.Context) { + framework.ConformanceIt("should test kubelet managed /etc/hosts file", f.WithNodeConformance(), func(ctx context.Context) { ginkgo.By("Setting up the test") config.setup(ctx) @@ -112,6 +113,7 @@ func assertManagedStatus( retryCount := 0 etcHostsContent := "" + etcHostsPath, etcHostsOriginalPath := getEtcHostsPath() for startTime := time.Now(); time.Since(startTime) < retryTimeout; { etcHostsContent = config.getFileContents(podName, name, etcHostsPath) @@ -155,6 +157,7 @@ func (config *KubeletManagedHostConfig) getFileContents(podName, containerName, func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod { hostPathType := new(v1.HostPathType) *hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate)) + etcHostsPath, etcHostsOriginalPath := getEtcHostsPath() mounts := []v1.VolumeMount{ { Name: "host-etc-hosts", @@ -198,6 +201,7 @@ func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod { func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName string) *v1.Pod { hostPathType := new(v1.HostPathType) *hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate)) + etcHostsPath, etcHostsOriginalPath := getEtcHostsPath() mounts := []v1.VolumeMount{ { Name: "host-etc-hosts", @@ -230,3 +234,10 @@ func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName str } return pod } + +func getEtcHostsPath() (string, string) { + if framework.NodeOSDistroIs("windows") { + return etcHostsPathWindows, etcHostsOriginalPathWindows + } + return etcHostsPathLinux, etcHostsOriginalPathLinux +}