@@ -33,6 +33,7 @@ import (
33
33
e2efeature "k8s.io/kubernetes/test/e2e/feature"
34
34
"k8s.io/kubernetes/test/e2e/framework"
35
35
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
36
+ e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
36
37
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
37
38
e2evolume "k8s.io/kubernetes/test/e2e/framework/volume"
38
39
storageframework "k8s.io/kubernetes/test/e2e/storage/framework"
@@ -164,10 +165,9 @@ func (v *volumeModifyTestSuite) DefineTests(driver storageframework.TestDriver,
164
165
ginkgo .DeferCleanup (e2epod .DeletePodWithWait , f .ClientSet , pod )
165
166
framework .ExpectNoError (err , "While creating test pod with VAC" )
166
167
167
- createdPVC , err := f .ClientSet .CoreV1 ().PersistentVolumeClaims (f .Namespace .Name ).Get (ctx , l .resource .Pvc .Name , metav1.GetOptions {})
168
- framework .ExpectNoError (err , "While getting created PVC" )
169
- // Check VAC matches on created PVC, but not current VAC in status
170
- gomega .Expect (vacMatches (createdPVC , l .vac .Name , false )).To (gomega .BeTrueBecause ("Created PVC should match expected VAC" ))
168
+ ginkgo .By ("Checking PVC status" )
169
+ err = e2epv .WaitForPersistentVolumeClaimModified (ctx , f .ClientSet , l .resource .Pvc , modifyVolumeWaitPeriod )
170
+ framework .ExpectNoError (err , "While waiting for PVC to have expected VAC" )
171
171
})
172
172
173
173
ginkgo .It ("should modify volume with no VAC" , func (ctx context.Context ) {
@@ -191,11 +191,9 @@ func (v *volumeModifyTestSuite) DefineTests(driver storageframework.TestDriver,
191
191
l .resource .Pvc = SetPVCVACName (ctx , l .resource .Pvc , l .vac .Name , f .ClientSet , setVACWaitPeriod )
192
192
gomega .Expect (l .resource .Pvc ).NotTo (gomega .BeNil ())
193
193
194
- ginkgo .By ("Waiting for modification to finish" )
195
- l .resource .Pvc = WaitForVolumeModification (ctx , l .resource .Pvc , f .ClientSet , modifyVolumeWaitPeriod )
196
-
197
- pvcConditions := l .resource .Pvc .Status .Conditions
198
- gomega .Expect (pvcConditions ).To (gomega .BeEmpty (), "PVC should not have conditions" )
194
+ ginkgo .By ("Checking PVC status" )
195
+ err = e2epv .WaitForPersistentVolumeClaimModified (ctx , f .ClientSet , l .resource .Pvc , modifyVolumeWaitPeriod )
196
+ framework .ExpectNoError (err , "While waiting for PVC to have expected VAC" )
199
197
})
200
198
201
199
ginkgo .It ("should modify volume that already has a VAC" , func (ctx context.Context ) {
@@ -225,11 +223,9 @@ func (v *volumeModifyTestSuite) DefineTests(driver storageframework.TestDriver,
225
223
l .resource .Pvc = SetPVCVACName (ctx , l .resource .Pvc , newVAC .Name , f .ClientSet , setVACWaitPeriod )
226
224
gomega .Expect (l .resource .Pvc ).NotTo (gomega .BeNil ())
227
225
228
- ginkgo .By ("Waiting for modification to finish" )
229
- l .resource .Pvc = WaitForVolumeModification (ctx , l .resource .Pvc , f .ClientSet , modifyVolumeWaitPeriod )
230
-
231
- pvcConditions := l .resource .Pvc .Status .Conditions
232
- gomega .Expect (pvcConditions ).To (gomega .BeEmpty (), "PVC should not have conditions" )
226
+ ginkgo .By ("Checking PVC status" )
227
+ err = e2epv .WaitForPersistentVolumeClaimModified (ctx , f .ClientSet , l .resource .Pvc , modifyVolumeWaitPeriod )
228
+ framework .ExpectNoError (err , "While waiting for PVC to have expected VAC" )
233
229
})
234
230
}
235
231
@@ -250,45 +246,8 @@ func SetPVCVACName(ctx context.Context, origPVC *v1.PersistentVolumeClaim, name
250
246
return patchedPVC
251
247
}
252
248
253
- // WaitForVolumeModification waits for the volume to be modified
254
- // The input PVC is assumed to have a VolumeAttributesClassName set
255
- func WaitForVolumeModification (ctx context.Context , pvc * v1.PersistentVolumeClaim , c clientset.Interface , timeout time.Duration ) * v1.PersistentVolumeClaim {
256
- var newPVC * v1.PersistentVolumeClaim
257
- pvName := pvc .Spec .VolumeName
258
- gomega .Eventually (ctx , func (g gomega.Gomega ) {
259
- pv , err := c .CoreV1 ().PersistentVolumes ().Get (ctx , pvName , metav1.GetOptions {})
260
- framework .ExpectNoError (err , "While getting existing PV" )
261
- g .Expect (pv .Spec .VolumeAttributesClassName ).NotTo (gomega .BeNil ())
262
- newPVC , err = c .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Get (ctx , pvc .Name , metav1.GetOptions {})
263
- framework .ExpectNoError (err , "While getting new PVC" )
264
- g .Expect (vacMatches (newPVC , * pv .Spec .VolumeAttributesClassName , true )).To (gomega .BeTrueBecause ("Modified PVC should match expected VAC" ))
265
- }, timeout , modifyPollInterval ).Should (gomega .Succeed ())
266
- return newPVC
267
- }
268
-
269
249
func CleanupVAC (ctx context.Context , vac * storagev1beta1.VolumeAttributesClass , c clientset.Interface , timeout time.Duration ) {
270
250
gomega .Eventually (ctx , func () error {
271
251
return c .StorageV1beta1 ().VolumeAttributesClasses ().Delete (ctx , vac .Name , metav1.DeleteOptions {})
272
252
}, timeout , modifyPollInterval ).Should (gomega .BeNil ())
273
253
}
274
-
275
- func vacMatches (pvc * v1.PersistentVolumeClaim , expectedVac string , checkStatusCurrentVac bool ) bool {
276
- // Check the following to ensure the VAC matches and that all pending modifications are complete:
277
- // 1. VAC Name matches Expected
278
- // 2. PVC Modify Volume status is either nil or has an empty status string
279
- // 3. PVC Status Current VAC Matches Expected (only if checkStatusCurrentVac is true)
280
- // (3) is only expected to be true after a VAC is modified, but not when a VAC is used to create a volume
281
- if pvc .Spec .VolumeAttributesClassName == nil || * pvc .Spec .VolumeAttributesClassName != expectedVac {
282
- return false
283
- }
284
- if pvc .Status .ModifyVolumeStatus != nil && (pvc .Status .ModifyVolumeStatus .Status != "" || pvc .Status .ModifyVolumeStatus .TargetVolumeAttributesClassName != expectedVac ) {
285
- return false
286
- }
287
- if checkStatusCurrentVac {
288
- if pvc .Status .CurrentVolumeAttributesClassName == nil || * pvc .Status .CurrentVolumeAttributesClassName != expectedVac {
289
- return false
290
- }
291
- }
292
-
293
- return true
294
- }
0 commit comments