@@ -89,6 +89,7 @@ func createSubPathTestInput(pattern testpatterns.TestPattern, resource subPathTe
89
89
filePathInVolume : filepath .Join (subPathDir , fileName ),
90
90
volType : resource .volType ,
91
91
pod : resource .pod ,
92
+ formatPod : resource .formatPod ,
92
93
volSource : resource .genericVolumeTestResource .volSource ,
93
94
roVol : resource .roVolSource ,
94
95
}
@@ -131,6 +132,7 @@ type subPathTestResource struct {
131
132
132
133
roVolSource * v1.VolumeSource
133
134
pod * v1.Pod
135
+ formatPod * v1.Pod
134
136
}
135
137
136
138
var _ TestResource = & subPathTestResource {}
@@ -171,9 +173,13 @@ func (s *subPathTestResource) setupResource(driver drivers.TestDriver, pattern t
171
173
172
174
subPath := f .Namespace .Name
173
175
config := dInfo .Config
174
- s .pod = TestPodSubpath (f , subPath , s .volType , s .volSource , true )
176
+ s .pod = SubpathTestPod (f , subPath , s .volType , s .volSource , true )
175
177
s .pod .Spec .NodeName = config .ClientNodeName
176
178
s .pod .Spec .NodeSelector = config .NodeSelector
179
+
180
+ s .formatPod = volumeFormatPod (f , s .volSource )
181
+ s .formatPod .Spec .NodeName = config .ClientNodeName
182
+ s .formatPod .Spec .NodeSelector = config .NodeSelector
177
183
}
178
184
179
185
func (s * subPathTestResource ) cleanupResource (driver drivers.TestDriver , pattern testpatterns.TestPattern ) {
@@ -196,6 +202,7 @@ type subPathTestInput struct {
196
202
filePathInVolume string
197
203
volType string
198
204
pod * v1.Pod
205
+ formatPod * v1.Pod
199
206
volSource * v1.VolumeSource
200
207
roVol * v1.VolumeSource
201
208
}
@@ -359,7 +366,7 @@ func testSubPath(input *subPathTestInput) {
359
366
}
360
367
361
368
// Format the volume while it's writable
362
- formatVolume (input .f , input .volSource )
369
+ formatVolume (input .f , input .formatPod )
363
370
364
371
// Set volume source to read only
365
372
input .pod .Spec .Volumes [0 ].VolumeSource = * input .roVol
@@ -387,8 +394,8 @@ func TestBasicSubpathFile(f *framework.Framework, contents string, pod *v1.Pod,
387
394
Expect (err ).NotTo (HaveOccurred (), "while deleting pod" )
388
395
}
389
396
390
- // TestPodSubpath runs pod subpath test
391
- func TestPodSubpath (f * framework.Framework , subpath , volumeType string , source * v1.VolumeSource , privilegedSecurityContext bool ) * v1.Pod {
397
+ // SubpathTestPod returns a pod spec for subpath tests
398
+ func SubpathTestPod (f * framework.Framework , subpath , volumeType string , source * v1.VolumeSource , privilegedSecurityContext bool ) * v1.Pod {
392
399
var (
393
400
suffix = strings .ToLower (fmt .Sprintf ("%s-%s" , volumeType , rand .String (4 )))
394
401
gracePeriod = int64 (1 )
@@ -479,6 +486,38 @@ func TestPodSubpath(f *framework.Framework, subpath, volumeType string, source *
479
486
}
480
487
}
481
488
489
+ // volumeFormatPod returns a Pod that does nothing but will cause the plugin to format a filesystem
490
+ // on first use
491
+ func volumeFormatPod (f * framework.Framework , volumeSource * v1.VolumeSource ) * v1.Pod {
492
+ return & v1.Pod {
493
+ ObjectMeta : metav1.ObjectMeta {
494
+ Name : fmt .Sprintf ("volume-prep-%s" , f .Namespace .Name ),
495
+ },
496
+ Spec : v1.PodSpec {
497
+ Containers : []v1.Container {
498
+ {
499
+ Name : fmt .Sprintf ("init-volume-%s" , f .Namespace .Name ),
500
+ Image : imageutils .GetE2EImage (imageutils .BusyBox ),
501
+ Command : []string {"/bin/sh" , "-ec" , "echo nothing" },
502
+ VolumeMounts : []v1.VolumeMount {
503
+ {
504
+ Name : volumeName ,
505
+ MountPath : "/vol" ,
506
+ },
507
+ },
508
+ },
509
+ },
510
+ RestartPolicy : v1 .RestartPolicyNever ,
511
+ Volumes : []v1.Volume {
512
+ {
513
+ Name : volumeName ,
514
+ VolumeSource : * volumeSource ,
515
+ },
516
+ },
517
+ },
518
+ }
519
+ }
520
+
482
521
func clearSubpathPodCommands (pod * v1.Pod ) {
483
522
pod .Spec .InitContainers [0 ].Command = nil
484
523
pod .Spec .Containers [0 ].Args = nil
@@ -684,38 +723,9 @@ func testSubpathReconstruction(f *framework.Framework, pod *v1.Pod, forceDelete
684
723
utils .TestVolumeUnmountsFromDeletedPodWithForceOption (f .ClientSet , f , pod , forceDelete , true )
685
724
}
686
725
687
- func formatVolume (f * framework.Framework , volumeSource * v1.VolumeSource ) {
688
- var err error
689
- // Launch pod to format the volume
690
- pod := & v1.Pod {
691
- ObjectMeta : metav1.ObjectMeta {
692
- Name : fmt .Sprintf ("volume-prep-%s" , f .Namespace .Name ),
693
- },
694
- Spec : v1.PodSpec {
695
- Containers : []v1.Container {
696
- {
697
- Name : fmt .Sprintf ("init-volume-%s" , f .Namespace .Name ),
698
- Image : imageutils .GetE2EImage (imageutils .BusyBox ),
699
- Command : []string {"/bin/sh" , "-ec" , "echo nothing" },
700
- VolumeMounts : []v1.VolumeMount {
701
- {
702
- Name : volumeName ,
703
- MountPath : "/vol" ,
704
- },
705
- },
706
- },
707
- },
708
- RestartPolicy : v1 .RestartPolicyNever ,
709
- Volumes : []v1.Volume {
710
- {
711
- Name : volumeName ,
712
- VolumeSource : * volumeSource ,
713
- },
714
- },
715
- },
716
- }
726
+ func formatVolume (f * framework.Framework , pod * v1.Pod ) {
717
727
By (fmt .Sprintf ("Creating pod to format volume %s" , pod .Name ))
718
- pod , err = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (pod )
728
+ pod , err : = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (pod )
719
729
Expect (err ).ToNot (HaveOccurred (), "while creating volume init pod" )
720
730
721
731
err = framework .WaitForPodSuccessInNamespace (f .ClientSet , pod .Name , pod .Namespace )
0 commit comments