From 47c6223b3a99de74a170f587ef1ac6ca71bf700b Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 17 Feb 2021 09:58:12 +0100 Subject: [PATCH] e2e: track deletion of PVC and PV more closely When passing a pointer to a PVC and PV, the status of the deleted objects is not logged correctly. The `PersistentVolumeClaim.Status` and `PersistedVolume.Status` that is added to the logs contain the status of the initially created object (reference to the PVC/PV). When the PVC/PV is removed, there is no guarantee that the object is updated. Logs show an empty (nullified) `PersistentVolumeClaim.Status`, which is not helpful. Instead, use the returned PVC/PV from the `Get()` function and use that for further logging. Even when the `.Status` struct from the PVC/PV gets wiped, the returned object should have correct details. Updates: #1874 Signed-off-by: Niels de Vos --- e2e/pvc.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/e2e/pvc.go b/e2e/pvc.go index 7ec4264c5..81ff63a82 100644 --- a/e2e/pvc.go +++ b/e2e/pvc.go @@ -94,10 +94,12 @@ func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v timeout := time.Duration(t) * time.Minute start := time.Now() + + pvcToDelete := pvc err = wait.PollImmediate(poll, timeout, func() (bool, error) { // Check that the PVC is deleted. - e2elog.Logf("waiting for PVC %s in state %s to be deleted (%d seconds elapsed)", pvc.Name, pvc.Status.String(), int(time.Since(start).Seconds())) - _, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(context.TODO(), pvc.Name, metav1.GetOptions{}) + e2elog.Logf("waiting for PVC %s in state %s to be deleted (%d seconds elapsed)", pvcToDelete.Name, pvcToDelete.Status.String(), int(time.Since(start).Seconds())) + pvcToDelete, err = c.CoreV1().PersistentVolumeClaims(pvcToDelete.Namespace).Get(context.TODO(), pvcToDelete.Name, metav1.GetOptions{}) if err == nil { return false, nil } @@ -110,12 +112,14 @@ func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v if err != nil { return err } + start = time.Now() + pvToDelete := pv return wait.PollImmediate(poll, timeout, func() (bool, error) { // Check that the PV is deleted. - e2elog.Logf("waiting for PV %s in state %s to be deleted (%d seconds elapsed)", pv.Name, pv.Status.String(), int(time.Since(start).Seconds())) + e2elog.Logf("waiting for PV %s in state %s to be deleted (%d seconds elapsed)", pvToDelete.Name, pvToDelete.Status.String(), int(time.Since(start).Seconds())) - _, err = c.CoreV1().PersistentVolumes().Get(context.TODO(), pv.Name, metav1.GetOptions{}) + pvToDelete, err = c.CoreV1().PersistentVolumes().Get(context.TODO(), pvToDelete.Name, metav1.GetOptions{}) if err == nil { return false, nil }