k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/kubelet/kubelet_pods_windows_test.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package kubelet 18 19 import ( 20 "os" 21 "path/filepath" 22 "testing" 23 24 "github.com/stretchr/testify/assert" 25 "github.com/stretchr/testify/require" 26 v1 "k8s.io/api/core/v1" 27 kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" 28 "k8s.io/kubernetes/pkg/volume/util/hostutil" 29 "k8s.io/kubernetes/pkg/volume/util/subpath" 30 ) 31 32 func TestMakeMountsWindows(t *testing.T) { 33 // TODO: remove skip once the failing test has been fixed. 34 t.Skip("Skip failing test on Windows.") 35 container := v1.Container{ 36 VolumeMounts: []v1.VolumeMount{ 37 { 38 MountPath: "c:/etc/hosts", 39 Name: "disk", 40 ReadOnly: false, 41 }, 42 { 43 MountPath: "c:/mnt/path3", 44 Name: "disk", 45 ReadOnly: true, 46 }, 47 { 48 MountPath: "c:/mnt/path4", 49 Name: "disk4", 50 ReadOnly: false, 51 }, 52 { 53 MountPath: "c:/mnt/path5", 54 Name: "disk5", 55 ReadOnly: false, 56 }, 57 { 58 MountPath: `\mnt\path6`, 59 Name: "disk6", 60 ReadOnly: false, 61 }, 62 { 63 MountPath: `/mnt/path7`, 64 Name: "disk7", 65 ReadOnly: false, 66 }, 67 { 68 MountPath: `\\.\pipe\pipe1`, 69 Name: "pipe1", 70 ReadOnly: false, 71 }, 72 }, 73 } 74 75 podVolumes := kubecontainer.VolumeMap{ 76 "disk": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: "c:/mnt/disk"}}, 77 "disk4": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: "c:/mnt/host"}}, 78 "disk5": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: "c:/var/lib/kubelet/podID/volumes/empty/disk5"}}, 79 "disk6": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: `/mnt/disk6`}}, 80 "disk7": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: `\mnt\disk7`}}, 81 "pipe1": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: `\\.\pipe\pipe1`}}, 82 } 83 84 pod := v1.Pod{ 85 Spec: v1.PodSpec{ 86 HostNetwork: true, 87 }, 88 } 89 90 fhu := hostutil.NewFakeHostUtil(nil) 91 fsp := &subpath.FakeSubpath{} 92 podDir, err := os.MkdirTemp("", "test-rotate-logs") 93 require.NoError(t, err) 94 defer os.RemoveAll(podDir) 95 mounts, _, err := makeMounts(&pod, podDir, &container, "fakepodname", "", []string{""}, podVolumes, fhu, fsp, nil, false) 96 require.NoError(t, err) 97 98 expectedMounts := []kubecontainer.Mount{ 99 { 100 Name: "disk", 101 ContainerPath: "c:/etc/hosts", 102 HostPath: "c:/mnt/disk", 103 ReadOnly: false, 104 SELinuxRelabel: false, 105 }, 106 { 107 Name: "disk", 108 ContainerPath: "c:/mnt/path3", 109 HostPath: "c:/mnt/disk", 110 ReadOnly: true, 111 SELinuxRelabel: false, 112 }, 113 { 114 Name: "disk4", 115 ContainerPath: "c:/mnt/path4", 116 HostPath: "c:/mnt/host", 117 ReadOnly: false, 118 SELinuxRelabel: false, 119 }, 120 { 121 Name: "disk5", 122 ContainerPath: "c:/mnt/path5", 123 HostPath: "c:/var/lib/kubelet/podID/volumes/empty/disk5", 124 ReadOnly: false, 125 SELinuxRelabel: false, 126 }, 127 { 128 Name: "disk6", 129 ContainerPath: `c:\mnt\path6`, 130 HostPath: `c:/mnt/disk6`, 131 ReadOnly: false, 132 SELinuxRelabel: false, 133 }, 134 { 135 Name: "disk7", 136 ContainerPath: `c:/mnt/path7`, 137 HostPath: `c:\mnt\disk7`, 138 ReadOnly: false, 139 SELinuxRelabel: false, 140 }, 141 { 142 Name: "pipe1", 143 ContainerPath: `\\.\pipe\pipe1`, 144 HostPath: `\\.\pipe\pipe1`, 145 ReadOnly: false, 146 SELinuxRelabel: false, 147 }, 148 { 149 Name: "k8s-managed-etc-hosts", 150 ContainerPath: `C:\Windows\System32\drivers\etc\hosts`, 151 HostPath: filepath.Join(podDir, "etc-hosts"), 152 ReadOnly: false, 153 SELinuxRelabel: true, 154 }, 155 } 156 assert.Equal(t, expectedMounts, mounts, "mounts of container %+v", container) 157 }