@@ -82,38 +82,38 @@ func TestPVCTestSuite(t *testing.T) {
82
82
func (p * PodTestSuite ) TestPodWithHostPathVolume () {
83
83
p .kustomizeDir = "pod"
84
84
85
- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
85
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
86
86
}
87
87
88
88
func (p * PodTestSuite ) TestPodWithLocalVolume () {
89
89
p .kustomizeDir = "pod-with-local-volume"
90
90
91
- runTest (p , []string {p .config .IMAGE }, "ready" , localVolumeType )
91
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , localVolumeType )
92
92
}
93
93
94
94
func (p * PodTestSuite ) TestPodWithLocalVolumeDefault () {
95
95
p .kustomizeDir = "pod-with-default-local-volume"
96
96
97
- runTest (p , []string {p .config .IMAGE }, "ready" , localVolumeType )
97
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , localVolumeType )
98
98
}
99
99
100
100
func (p * PodTestSuite ) TestPodWithNodeAffinity () {
101
101
p .kustomizeDir = "pod-with-node-affinity"
102
102
103
- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
103
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
104
104
}
105
105
106
106
func (p * PodTestSuite ) TestPodWithRWOPVolume () {
107
107
p .kustomizeDir = "pod-with-rwop-volume"
108
108
109
- runTest (p , []string {p .config .IMAGE }, "ready" , localVolumeType )
109
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , localVolumeType )
110
110
}
111
111
112
112
func (p * PodTestSuite ) TestPodWithSecurityContext () {
113
113
p .kustomizeDir = "pod-with-security-context"
114
114
kustomizeDir := testdataFile (p .kustomizeDir )
115
115
116
- runTest (p , []string {p .config .IMAGE }, "podscheduled" , hostPathVolumeType )
116
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "podscheduled" ) , hostPathVolumeType )
117
117
118
118
cmd := fmt .Sprintf (`kubectl get pod -l %s=%s -o=jsonpath='{.items[0].status.conditions[?(@.type=="Ready")].reason}'` , LabelKey , LabelValue )
119
119
@@ -142,22 +142,33 @@ loop:
142
142
func (p * PodTestSuite ) TestPodWithSubpath () {
143
143
p .kustomizeDir = "pod-with-subpath"
144
144
145
- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
145
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
146
146
}
147
147
148
148
func (p * PodTestSuite ) xxTestPodWithMultipleStorageClasses () {
149
149
p .kustomizeDir = "multiple-storage-classes"
150
150
151
- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
151
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
152
152
}
153
153
154
154
func (p * PodTestSuite ) TestPodWithCustomPathPatternStorageClasses () {
155
155
p .kustomizeDir = "custom-path-pattern"
156
156
157
- runTest (p , []string {p .config .IMAGE }, "ready" , hostPathVolumeType )
157
+ runTest (p , []string {p .config .IMAGE }, waitCondition ( "ready" ) , hostPathVolumeType )
158
158
}
159
159
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 ) {
161
172
kustomizeDir := testdataFile (p .kustomizeDir )
162
173
163
174
var cmds []string
@@ -171,7 +182,7 @@ func runTest(p *PodTestSuite, images []string, waitCondition, volumeType string)
171
182
cmds ,
172
183
fmt .Sprintf ("kustomize edit add label %s:%s -f" , LabelKey , LabelValue ),
173
184
"kustomize build | kubectl apply -f -" ,
174
- fmt . Sprintf ( "kubectl wait pod -l %s=%s --for condition=%s --timeout=120s" , LabelKey , LabelValue , waitCondition ) ,
185
+ waitCmd ,
175
186
)
176
187
177
188
for _ , cmd := range cmds {
@@ -188,13 +199,15 @@ func runTest(p *PodTestSuite, images []string, waitCondition, volumeType string)
188
199
}
189
200
}
190
201
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
+ }
199
212
}
200
213
}
0 commit comments