@@ -82,38 +82,38 @@ func TestPVCTestSuite(t *testing.T) {
8282func (p * PodTestSuite ) TestPodWithHostPathVolume () {
8383 p .kustomizeDir = "pod"
8484
85- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
85+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
8686}
8787
8888func (p * PodTestSuite ) TestPodWithLocalVolume () {
8989 p .kustomizeDir = "pod-with-local-volume"
9090
91- runTest (p , []string {p .config .IMAGE }, "ready" , localVolumeType )
91+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , localVolumeType )
9292}
9393
9494func (p * PodTestSuite ) TestPodWithLocalVolumeDefault () {
9595 p .kustomizeDir = "pod-with-default-local-volume"
9696
97- runTest (p , []string {p .config .IMAGE }, "ready" , localVolumeType )
97+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , localVolumeType )
9898}
9999
100100func (p * PodTestSuite ) TestPodWithNodeAffinity () {
101101 p .kustomizeDir = "pod-with-node-affinity"
102102
103- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
103+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
104104}
105105
106106func (p * PodTestSuite ) TestPodWithRWOPVolume () {
107107 p .kustomizeDir = "pod-with-rwop-volume"
108108
109- runTest (p , []string {p .config .IMAGE }, "ready" , localVolumeType )
109+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , localVolumeType )
110110}
111111
112112func (p * PodTestSuite ) TestPodWithSecurityContext () {
113113 p .kustomizeDir = "pod-with-security-context"
114114 kustomizeDir := testdataFile (p .kustomizeDir )
115115
116- runTest (p , []string {p .config .IMAGE }, "podscheduled" , hostPathVolumeType )
116+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "podscheduled" ) , hostPathVolumeType )
117117
118118 cmd := fmt .Sprintf (`kubectl get pod -l %s=%s -o=jsonpath='{.items[0].status.conditions[?(@.type=="Ready")].reason}'` , LabelKey , LabelValue )
119119
@@ -142,22 +142,33 @@ loop:
142142func (p * PodTestSuite ) TestPodWithSubpath () {
143143 p .kustomizeDir = "pod-with-subpath"
144144
145- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
145+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
146146}
147147
148148func (p * PodTestSuite ) TestPodWithMultipleStorageClasses () {
149149 p .kustomizeDir = "multiple-storage-classes"
150150
151- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
151+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
152152}
153153
154154func (p * PodTestSuite ) TestPodWithCustomPathPatternStorageClasses () {
155155 p .kustomizeDir = "custom-path-pattern"
156156
157- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
157+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
158158}
159159
160- func runTest (p * PodTestSuite , images []string , waitCondition , volumeType string ) {
160+ func (p * PodTestSuite ) TestPodWithLegacyAffinityConstraint () {
161+ // The helper pod should be correctly scheduled
162+ p .kustomizeDir = "pv-with-legacy-affinity"
163+
164+ runTest (p , []string {p .config .IMAGE }, "kubectl wait pv pvc-to-clean-up --for delete --timeout=120s" , "" )
165+ }
166+
167+ func waitCondition (waitCondition string ) string {
168+ return fmt .Sprintf ("kubectl wait pod -l %s=%s --for condition=%s --timeout=120s" , LabelKey , LabelValue , waitCondition )
169+ }
170+
171+ func runTest (p * PodTestSuite , images []string , waitCmd , volumeType string ) {
161172 kustomizeDir := testdataFile (p .kustomizeDir )
162173
163174 var cmds []string
@@ -171,7 +182,7 @@ func runTest(p *PodTestSuite, images []string, waitCondition, volumeType string)
171182 cmds ,
172183 fmt .Sprintf ("kustomize edit add label %s:%s -f" , LabelKey , LabelValue ),
173184 "kustomize build | kubectl apply -f -" ,
174- fmt . Sprintf ( "kubectl wait pod -l %s=%s --for condition=%s --timeout=120s" , LabelKey , LabelValue , waitCondition ) ,
185+ waitCmd ,
175186 )
176187
177188 for _ , cmd := range cmds {
@@ -188,13 +199,15 @@ func runTest(p *PodTestSuite, images []string, waitCondition, volumeType string)
188199 }
189200 }
190201
191- typeCheckCmd := fmt .Sprintf ("kubectl get pv $(%s) -o jsonpath='{.spec.%s}'" , "kubectl get pv -o jsonpath='{.items[0].metadata.name}'" , volumeType )
192- c := createCmd (p .T (), typeCheckCmd , kustomizeDir , p .config .envs (), nil )
193- typeCheckOutput , err := c .CombinedOutput ()
194- if err != nil {
195- p .FailNow ("" , "failed to check volume type: %v" , err )
196- }
197- if len (typeCheckOutput ) == 0 || ! strings .Contains (string (typeCheckOutput ), "path" ) {
198- p .FailNow ("volume Type not correct" )
202+ if volumeType != "" {
203+ typeCheckCmd := fmt .Sprintf ("kubectl get pv $(%s) -o jsonpath='{.spec.%s}'" , "kubectl get pv -o jsonpath='{.items[0].metadata.name}'" , volumeType )
204+ c := createCmd (p .T (), typeCheckCmd , kustomizeDir , p .config .envs (), nil )
205+ typeCheckOutput , err := c .CombinedOutput ()
206+ if err != nil {
207+ p .FailNow ("" , "failed to check volume type: %v" , err )
208+ }
209+ if len (typeCheckOutput ) == 0 || ! strings .Contains (string (typeCheckOutput ), "path" ) {
210+ p .FailNow ("volume Type not correct" )
211+ }
199212 }
200213}
0 commit comments