...

Source file src/k8s.io/kubernetes/pkg/kubelet/kubelet_pods_windows_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet

     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  	container := v1.Container{
    34  		VolumeMounts: []v1.VolumeMount{
    35  			{
    36  				MountPath: "c:/etc/hosts",
    37  				Name:      "disk",
    38  				ReadOnly:  false,
    39  			},
    40  			{
    41  				MountPath: "c:/mnt/path3",
    42  				Name:      "disk",
    43  				ReadOnly:  true,
    44  			},
    45  			{
    46  				MountPath: "c:/mnt/path4",
    47  				Name:      "disk4",
    48  				ReadOnly:  false,
    49  			},
    50  			{
    51  				MountPath: "c:/mnt/path5",
    52  				Name:      "disk5",
    53  				ReadOnly:  false,
    54  			},
    55  			{
    56  				MountPath: `\mnt\path6`,
    57  				Name:      "disk6",
    58  				ReadOnly:  false,
    59  			},
    60  			{
    61  				MountPath: `/mnt/path7`,
    62  				Name:      "disk7",
    63  				ReadOnly:  false,
    64  			},
    65  			{
    66  				MountPath: `\\.\pipe\pipe1`,
    67  				Name:      "pipe1",
    68  				ReadOnly:  false,
    69  			},
    70  		},
    71  	}
    72  
    73  	podVolumes := kubecontainer.VolumeMap{
    74  		"disk":  kubecontainer.VolumeInfo{Mounter: &stubVolume{path: "c:/mnt/disk"}},
    75  		"disk4": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: "c:/mnt/host"}},
    76  		"disk5": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: "c:/var/lib/kubelet/podID/volumes/empty/disk5"}},
    77  		"disk6": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: `/mnt/disk6`}},
    78  		"disk7": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: `\mnt\disk7`}},
    79  		"pipe1": kubecontainer.VolumeInfo{Mounter: &stubVolume{path: `\\.\pipe\pipe1`}},
    80  	}
    81  
    82  	pod := v1.Pod{
    83  		Spec: v1.PodSpec{
    84  			HostNetwork: true,
    85  		},
    86  	}
    87  
    88  	fhu := hostutil.NewFakeHostUtil(nil)
    89  	fsp := &subpath.FakeSubpath{}
    90  	podDir, err := os.MkdirTemp("", "test-rotate-logs")
    91  	require.NoError(t, err)
    92  	defer os.RemoveAll(podDir)
    93  	mounts, _, err := makeMounts(&pod, podDir, &container, "fakepodname", "", []string{""}, podVolumes, fhu, fsp, nil, false)
    94  	require.NoError(t, err)
    95  
    96  	expectedMounts := []kubecontainer.Mount{
    97  		{
    98  			Name:           "disk",
    99  			ContainerPath:  "c:/etc/hosts",
   100  			HostPath:       "c:/mnt/disk",
   101  			ReadOnly:       false,
   102  			SELinuxRelabel: false,
   103  		},
   104  		{
   105  			Name:           "disk",
   106  			ContainerPath:  "c:/mnt/path3",
   107  			HostPath:       "c:/mnt/disk",
   108  			ReadOnly:       true,
   109  			SELinuxRelabel: false,
   110  		},
   111  		{
   112  			Name:           "disk4",
   113  			ContainerPath:  "c:/mnt/path4",
   114  			HostPath:       "c:/mnt/host",
   115  			ReadOnly:       false,
   116  			SELinuxRelabel: false,
   117  		},
   118  		{
   119  			Name:           "disk5",
   120  			ContainerPath:  "c:/mnt/path5",
   121  			HostPath:       "c:/var/lib/kubelet/podID/volumes/empty/disk5",
   122  			ReadOnly:       false,
   123  			SELinuxRelabel: false,
   124  		},
   125  		{
   126  			Name:           "disk6",
   127  			ContainerPath:  `c:\mnt\path6`,
   128  			HostPath:       `c:/mnt/disk6`,
   129  			ReadOnly:       false,
   130  			SELinuxRelabel: false,
   131  		},
   132  		{
   133  			Name:           "disk7",
   134  			ContainerPath:  `c:/mnt/path7`,
   135  			HostPath:       `c:\mnt\disk7`,
   136  			ReadOnly:       false,
   137  			SELinuxRelabel: false,
   138  		},
   139  		{
   140  			Name:           "pipe1",
   141  			ContainerPath:  `\\.\pipe\pipe1`,
   142  			HostPath:       `\\.\pipe\pipe1`,
   143  			ReadOnly:       false,
   144  			SELinuxRelabel: false,
   145  		},
   146  		{
   147  			Name:           "k8s-managed-etc-hosts",
   148  			ContainerPath:  `C:\Windows\System32\drivers\etc\hosts`,
   149  			HostPath:       filepath.Join(podDir, "etc-hosts"),
   150  			ReadOnly:       false,
   151  			SELinuxRelabel: true,
   152  		},
   153  	}
   154  	assert.Equal(t, expectedMounts, mounts, "mounts of container %+v", container)
   155  }
   156  

View as plain text