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