mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
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:
commit
f5c5384181
5
test/conformance/testdata/conformance.yaml
vendored
5
test/conformance/testdata/conformance.yaml
vendored
@ -2229,15 +2229,14 @@
|
|||||||
file: test/e2e/common/node/kubelet.go
|
file: test/e2e/common/node/kubelet.go
|
||||||
- testname: Kubelet, managed etc hosts
|
- testname: Kubelet, managed etc hosts
|
||||||
codename: '[sig-node] KubeletManagedEtcHosts should test 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
|
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
|
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
|
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
|
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
|
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
|
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
|
not be managed by the Kubelet.
|
||||||
mount individual files in Containers.
|
|
||||||
release: v1.9
|
release: v1.9
|
||||||
file: test/e2e/common/node/kubelet_etc_hosts.go
|
file: test/e2e/common/node/kubelet_etc_hosts.go
|
||||||
- testname: lease API should be available
|
- testname: lease API should be available
|
||||||
|
@ -31,11 +31,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
etcHostsPodName = "test-pod"
|
etcHostsPodName = "test-pod"
|
||||||
etcHostsHostNetworkPodName = "test-host-network-pod"
|
etcHostsHostNetworkPodName = "test-host-network-pod"
|
||||||
etcHostsPartialContent = "# Kubernetes-managed hosts file."
|
etcHostsPartialContent = "# Kubernetes-managed hosts file."
|
||||||
etcHostsPath = "/etc/hosts"
|
etcHostsPathLinux = "/etc/hosts"
|
||||||
etcHostsOriginalPath = "/etc/hosts-original"
|
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
|
// 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.
|
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.
|
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.
|
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")
|
ginkgo.By("Setting up the test")
|
||||||
config.setup(ctx)
|
config.setup(ctx)
|
||||||
|
|
||||||
@ -112,6 +113,7 @@ func assertManagedStatus(
|
|||||||
|
|
||||||
retryCount := 0
|
retryCount := 0
|
||||||
etcHostsContent := ""
|
etcHostsContent := ""
|
||||||
|
etcHostsPath, etcHostsOriginalPath := getEtcHostsPath()
|
||||||
|
|
||||||
for startTime := time.Now(); time.Since(startTime) < retryTimeout; {
|
for startTime := time.Now(); time.Since(startTime) < retryTimeout; {
|
||||||
etcHostsContent = config.getFileContents(podName, name, etcHostsPath)
|
etcHostsContent = config.getFileContents(podName, name, etcHostsPath)
|
||||||
@ -155,6 +157,7 @@ func (config *KubeletManagedHostConfig) getFileContents(podName, containerName,
|
|||||||
func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {
|
func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {
|
||||||
hostPathType := new(v1.HostPathType)
|
hostPathType := new(v1.HostPathType)
|
||||||
*hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate))
|
*hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate))
|
||||||
|
etcHostsPath, etcHostsOriginalPath := getEtcHostsPath()
|
||||||
mounts := []v1.VolumeMount{
|
mounts := []v1.VolumeMount{
|
||||||
{
|
{
|
||||||
Name: "host-etc-hosts",
|
Name: "host-etc-hosts",
|
||||||
@ -198,6 +201,7 @@ func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {
|
|||||||
func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName string) *v1.Pod {
|
func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName string) *v1.Pod {
|
||||||
hostPathType := new(v1.HostPathType)
|
hostPathType := new(v1.HostPathType)
|
||||||
*hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate))
|
*hostPathType = v1.HostPathType(string(v1.HostPathFileOrCreate))
|
||||||
|
etcHostsPath, etcHostsOriginalPath := getEtcHostsPath()
|
||||||
mounts := []v1.VolumeMount{
|
mounts := []v1.VolumeMount{
|
||||||
{
|
{
|
||||||
Name: "host-etc-hosts",
|
Name: "host-etc-hosts",
|
||||||
@ -230,3 +234,10 @@ func (config *KubeletManagedHostConfig) createPodSpecWithHostNetwork(podName str
|
|||||||
}
|
}
|
||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEtcHostsPath() (string, string) {
|
||||||
|
if framework.NodeOSDistroIs("windows") {
|
||||||
|
return etcHostsPathWindows, etcHostsOriginalPathWindows
|
||||||
|
}
|
||||||
|
return etcHostsPathLinux, etcHostsOriginalPathLinux
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user