@@ -59,13 +59,13 @@ var _ = framework.KubeDescribe("Container Mount Propagation", func() {
5959 rc .RemovePodSandbox (context .TODO (), podID )
6060 })
6161
62- It ( "mount with 'rprivate' should not support propagation" , func () {
62+ testMountPropagation := func (propagation runtimeapi. MountPropagation ) {
6363 By ("create host path and flag file" )
64- mntSource , propagationSrcDir , propagationMntPoint , clearHostPath := createHostPathForMountPropagation (podID , runtimeapi . MountPropagation_PROPAGATION_PRIVATE )
64+ mntSource , propagationSrcDir , propagationMntPoint , clearHostPath := createHostPathForMountPropagation (podID , propagation )
6565 defer clearHostPath () // clean up the TempDir
6666
6767 By ("create container with volume" )
68- containerID := createMountPropagationContainer (rc , ic , "mount-propagation-test-" , podID , podConfig , mntSource , runtimeapi . MountPropagation_PROPAGATION_PRIVATE )
68+ containerID := createMountPropagationContainer (rc , ic , "mount-propagation-test-" , podID , podConfig , mntSource , propagation )
6969
7070 By ("test start container with volume" )
7171 testStartContainer (rc , containerID )
@@ -76,7 +76,13 @@ var _ = framework.KubeDescribe("Container Mount Propagation", func() {
7676 By ("check whether propagationMntPoint contains file or dir in container" )
7777 command := []string {"ls" , "-A" , propagationMntPoint }
7878 output := execSyncContainer (rc , containerID , command )
79- Expect (len (output )).To (BeZero (), "len(output) should be zero." )
79+
80+ switch propagation {
81+ case runtimeapi .MountPropagation_PROPAGATION_PRIVATE :
82+ Expect (len (output )).To (BeZero (), "len(output) should be zero." )
83+ case runtimeapi .MountPropagation_PROPAGATION_BIDIRECTIONAL , runtimeapi .MountPropagation_PROPAGATION_HOST_TO_CONTAINER :
84+ Expect (len (output )).NotTo (BeZero (), "len(output) should not be zero." )
85+ }
8086
8187 By ("create a directory named containerMntPoint as a mount point in container" )
8288 containerMntPoint := path .Join (mntSource , "containerMntPoint" )
@@ -90,75 +96,25 @@ var _ = framework.KubeDescribe("Container Mount Propagation", func() {
9096 By ("check whether containerMntPoint contains file or dir in host" )
9197 fileInfo , err := ioutil .ReadDir (containerMntPoint )
9298 framework .ExpectNoError (err , "failed to ReadDir %q in Host" , containerMntPoint )
93- Expect (len (fileInfo )).To (BeZero (), "len(fileInfo) should be zero." )
94- })
95-
96- It ("mount with 'rshared' should support propagation from host to container and vice versa" , func () {
97- By ("create host path and flag file" )
98- mntSource , propagationSrcDir , propagationMntPoint , clearHostPath := createHostPathForMountPropagation (podID , runtimeapi .MountPropagation_PROPAGATION_BIDIRECTIONAL )
99- defer clearHostPath () // clean up the TempDir
100-
101- By ("create container with volume" )
102- containerID := createMountPropagationContainer (rc , ic , "mount-propagation-test-" , podID , podConfig , mntSource , runtimeapi .MountPropagation_PROPAGATION_BIDIRECTIONAL )
103-
104- By ("test start container with volume" )
105- testStartContainer (rc , containerID )
106-
107- By ("create a propatation mount point in host" )
108- createPropagationMountPoint (propagationSrcDir , propagationMntPoint )
10999
110- By ("check whether propagationMntPoint contains file or dir in container" )
111- command := []string {"ls" , "-A" , propagationMntPoint }
112- output := execSyncContainer (rc , containerID , command )
113- Expect (len (output )).NotTo (BeZero (), "len(output) should not be zero." )
114-
115- By ("create a directory named containerMntPoint as a mount point in container" )
116- containerMntPoint := path .Join (mntSource , "containerMntPoint" )
117- command = []string {"sh" , "-c" , "mkdir -p " + containerMntPoint }
118- execSyncContainer (rc , containerID , command )
100+ switch propagation {
101+ case runtimeapi .MountPropagation_PROPAGATION_PRIVATE , runtimeapi .MountPropagation_PROPAGATION_HOST_TO_CONTAINER :
102+ Expect (len (fileInfo )).To (BeZero (), "len(fileInfo) should be zero." )
103+ case runtimeapi .MountPropagation_PROPAGATION_BIDIRECTIONAL :
104+ Expect (len (fileInfo )).NotTo (BeZero (), "len(fileInfo) should not be zero." )
105+ }
106+ }
119107
120- By ("mount /etc to the mount point in container" )
121- command = [] string { "sh" , "-c" , "mount --bind /etc " + containerMntPoint }
122- execSyncContainer ( rc , containerID , command )
108+ It ("mount with 'rprivate' should not support propagation" , func () {
109+ testMountPropagation ( runtimeapi . MountPropagation_PROPAGATION_PRIVATE )
110+ } )
123111
124- By ("check whether containerMntPoint contains file or dir in host" )
125- fileInfo , err := ioutil .ReadDir (containerMntPoint )
126- framework .ExpectNoError (err , "failed to ReadDir %q in Host" , containerMntPoint )
127- Expect (len (fileInfo )).NotTo (BeZero (), "len(fileInfo) should not be zero." )
112+ It ("mount with 'rshared' should support propagation from host to container and vice versa" , func () {
113+ testMountPropagation (runtimeapi .MountPropagation_PROPAGATION_BIDIRECTIONAL )
128114 })
129115
130116 It ("mount with 'rslave' should support propagation from host to container" , func () {
131- By ("create host path and flag file" )
132- mntSource , propagationSrcDir , propagationMntPoint , clearHostPath := createHostPathForMountPropagation (podID , runtimeapi .MountPropagation_PROPAGATION_HOST_TO_CONTAINER )
133- defer clearHostPath () // clean up the TempDir
134-
135- By ("create container with volume" )
136- containerID := createMountPropagationContainer (rc , ic , "mount-propagation-test-" , podID , podConfig , mntSource , runtimeapi .MountPropagation_PROPAGATION_HOST_TO_CONTAINER )
137-
138- By ("test start container with volume" )
139- testStartContainer (rc , containerID )
140-
141- By ("create a propatation mount point in host" )
142- createPropagationMountPoint (propagationSrcDir , propagationMntPoint )
143-
144- By ("check whether propagationMntPoint contains file or dir in container" )
145- command := []string {"ls" , "-A" , propagationMntPoint }
146- output := execSyncContainer (rc , containerID , command )
147- Expect (len (output )).NotTo (BeZero (), "len(output) should not be zero." )
148-
149- By ("create a directory named containerMntPoint as a mount point in container" )
150- containerMntPoint := path .Join (mntSource , "containerMntPoint" )
151- command = []string {"sh" , "-c" , "mkdir -p " + containerMntPoint }
152- execSyncContainer (rc , containerID , command )
153-
154- By ("mount /etc to the mount point in container" )
155- command = []string {"sh" , "-c" , "mount --bind /etc " + containerMntPoint }
156- execSyncContainer (rc , containerID , command )
157-
158- By ("check whether containerMntPoint contains file or dir in host" )
159- fileInfo , err := ioutil .ReadDir (containerMntPoint )
160- framework .ExpectNoError (err , "failed to ReadDir %q in Host" , containerMntPoint )
161- Expect (len (fileInfo )).To (BeZero (), "len(fileInfo) should be zero." )
117+ testMountPropagation (runtimeapi .MountPropagation_PROPAGATION_HOST_TO_CONTAINER )
162118 })
163119 })
164120})
0 commit comments