Merge pull request #124852 from claudiubelu/e2e-etc-hosts-test

e2e tests: Enables should test kubelet managed /etc/hosts file for Windows
This commit is contained in:
Kubernetes Prow Robot 2024-09-07 03:55:02 +01:00 committed by GitHub
commit f5c5384181
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View File

@ -2229,15 +2229,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

View File

@ -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
}