Skip to content

Commit ae185e9

Browse files
committed
e2e: test LastPhaseTransitionTime field when binding PV
1 parent a9c3444 commit ae185e9

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/e2e/storage/persistent_volumes.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,57 @@ var _ = utils.SIGDescribe("PersistentVolumes", func() {
201201
framework.ExpectNoError(err)
202202
completeTest(ctx, f, c, ns, pv, pvc)
203203
})
204+
205+
// Create PV and pre-bound PVC that matches the PV, verify that when PV and PVC bind
206+
// the LastPhaseTransitionTime filed of the PV is updated.
207+
ginkgo.It("create a PV and a pre-bound PVC: test phase transition timestamp is set [Feature: PersistentVolumeLastPhaseTransitionTime]", func(ctx context.Context) {
208+
pv, pvc, err = e2epv.CreatePVPVC(ctx, c, f.Timeouts, pvConfig, pvcConfig, ns, true)
209+
framework.ExpectNoError(err)
210+
211+
// The claim should transition phase to: Bound
212+
err = e2epv.WaitForPersistentVolumeClaimPhase(ctx, v1.ClaimBound, c, ns, pvc.Name, 2*time.Second, framework.ClaimProvisionShortTimeout)
213+
framework.ExpectNoError(err)
214+
pvc, err = c.CoreV1().PersistentVolumeClaims(ns).Get(ctx, pvc.Name, metav1.GetOptions{})
215+
framework.ExpectNoError(err)
216+
pv, err = c.CoreV1().PersistentVolumes().Get(ctx, pvc.Spec.VolumeName, metav1.GetOptions{})
217+
framework.ExpectNoError(err)
218+
if pv.Status.LastPhaseTransitionTime == nil {
219+
framework.Failf("Persistent volume %v should have LastPhaseTransitionTime value set after transitioning phase, but it's nil.", pv.GetName())
220+
}
221+
completeTest(ctx, f, c, ns, pv, pvc)
222+
})
223+
224+
// Create PV and pre-bound PVC that matches the PV, verify that when PV and PVC bind
225+
// the LastPhaseTransitionTime field of the PV is set, then delete the PVC to change PV phase to
226+
// released and validate PV LastPhaseTransitionTime correctly updated timestamp.
227+
ginkgo.It("create a PV and a pre-bound PVC: test phase transition timestamp multiple updates [Feature: PersistentVolumeLastPhaseTransitionTime]", func(ctx context.Context) {
228+
pv, pvc, err = e2epv.CreatePVPVC(ctx, c, f.Timeouts, pvConfig, pvcConfig, ns, true)
229+
framework.ExpectNoError(err)
230+
231+
// The claim should transition phase to: Bound.
232+
err = e2epv.WaitForPersistentVolumeClaimPhase(ctx, v1.ClaimBound, c, ns, pvc.Name, 2*time.Second, framework.ClaimProvisionShortTimeout)
233+
framework.ExpectNoError(err)
234+
pvc, err = c.CoreV1().PersistentVolumeClaims(ns).Get(ctx, pvc.Name, metav1.GetOptions{})
235+
framework.ExpectNoError(err)
236+
pv, err = c.CoreV1().PersistentVolumes().Get(ctx, pvc.Spec.VolumeName, metav1.GetOptions{})
237+
framework.ExpectNoError(err)
238+
239+
// Save first phase transition time.
240+
firstPhaseTransition := pv.Status.LastPhaseTransitionTime
241+
242+
// Let test finish and delete PVC.
243+
completeTest(ctx, f, c, ns, pv, pvc)
244+
245+
// The claim should transition phase to: Released.
246+
err = e2epv.WaitForPersistentVolumePhase(ctx, v1.VolumeReleased, c, pv.Name, 2*time.Second, framework.ClaimProvisionShortTimeout)
247+
framework.ExpectNoError(err)
248+
249+
// Verify the phase transition timestamp got updated chronologically *after* first phase transition.
250+
pv, err = c.CoreV1().PersistentVolumes().Get(ctx, pvc.Spec.VolumeName, metav1.GetOptions{})
251+
if !firstPhaseTransition.Before(pv.Status.LastPhaseTransitionTime) {
252+
framework.Failf("Persistent volume %v should have LastPhaseTransitionTime value updated to be chronologically after previous phase change: %v, but it's %v.", pv.GetName(), firstPhaseTransition, pv.Status.LastPhaseTransitionTime)
253+
}
254+
})
204255
})
205256

206257
// Create multiple pvs and pvcs, all in the same namespace. The PVs-PVCs are

0 commit comments

Comments
 (0)