diff --git a/e2e/cephfs_helper.go b/e2e/cephfs_helper.go index e8bc84c72..c1029e402 100644 --- a/e2e/cephfs_helper.go +++ b/e2e/cephfs_helper.go @@ -145,9 +145,7 @@ func unmountCephFSVolume(f *framework.Framework, appName, pvcName string) error return fmt.Errorf("failed to get pod: %w", err) } - pvc, err := f.ClientSet.CoreV1(). - PersistentVolumeClaims(f.UniqueName). - Get(context.TODO(), pvcName, metav1.GetOptions{}) + pvc, err := getPersistentVolumeClaim(f.ClientSet, f.UniqueName, pvcName) if err != nil { e2elog.Logf("Error occurred getting PVC %s in namespace %s", pvcName, f.UniqueName) diff --git a/e2e/pvc.go b/e2e/pvc.go index 2f7575d29..2b62466af 100644 --- a/e2e/pvc.go +++ b/e2e/pvc.go @@ -191,10 +191,33 @@ func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v }) } +// getPersistentVolumeClaim returns the PersistentVolumeClaim with the given +// name in the given namespace and retries if there is any API error. +func getPersistentVolumeClaim(c kubernetes.Interface, namespace, name string) (*v1.PersistentVolumeClaim, error) { + var pvc *v1.PersistentVolumeClaim + var err error + timeout := time.Duration(deployTimeout) * time.Minute + err = wait.PollImmediate(1*time.Second, timeout, func() (bool, error) { + pvc, err = c.CoreV1().PersistentVolumeClaims(namespace).Get(context.TODO(), name, metav1.GetOptions{}) + if err != nil { + e2elog.Logf("Error getting pvc %q in namespace %q: %v", name, namespace, err) + if isRetryableAPIError(err) { + return false, nil + } + + return false, fmt.Errorf("failed to get pvc: %w", err) + } + + return true, err + }) + + return pvc, err +} + func getPVCAndPV( c kubernetes.Interface, pvcName, pvcNamespace string) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error) { - pvc, err := c.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{}) + pvc, err := getPersistentVolumeClaim(c, pvcNamespace, pvcName) if err != nil { return nil, nil, fmt.Errorf("failed to get PVC: %w", err) } @@ -213,7 +236,7 @@ func deletePVCAndValidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai var err error e2elog.Logf("Deleting PersistentVolumeClaim %v on namespace %v", name, nameSpace) - pvc, err = c.CoreV1().PersistentVolumeClaims(nameSpace).Get(context.TODO(), name, metav1.GetOptions{}) + pvc, err = getPersistentVolumeClaim(c, nameSpace, name) if err != nil { return fmt.Errorf("failed to get pvc: %w", err) } @@ -265,9 +288,7 @@ func deletePVCAndValidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai // getBoundPV returns a PV details. func getBoundPV(client kubernetes.Interface, pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolume, error) { // Get new copy of the claim - claim, err := client.CoreV1(). - PersistentVolumeClaims(pvc.Namespace). - Get(context.TODO(), pvc.Name, metav1.GetOptions{}) + claim, err := getPersistentVolumeClaim(client, pvc.Namespace, pvc.Name) if err != nil { return nil, fmt.Errorf("failed to get pvc: %w", err) } diff --git a/e2e/rbd.go b/e2e/rbd.go index 6e1e2515a..ff1481048 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -414,11 +414,7 @@ var _ = Describe("RBD", func() { if pvcNamespace != pvc.Namespace { e2elog.Failf("expected pvcNamespace %q got %q", pvc.Namespace, pvcNamespace) } - - pvcObj, err := c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get( - context.TODO(), - pvc.Name, - metav1.GetOptions{}) + pvcObj, err := getPersistentVolumeClaim(c, pvc.Namespace, pvc.Name) if err != nil { e2elog.Logf("error getting pvc %q in namespace %q: %v", pvc.Name, pvc.Namespace, err) } diff --git a/e2e/resize.go b/e2e/resize.go index 9a6b42a3a..689938f02 100644 --- a/e2e/resize.go +++ b/e2e/resize.go @@ -36,10 +36,7 @@ import ( func expandPVCSize(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, size string, t int) error { pvcName := pvc.Name pvcNamespace := pvc.Namespace - - updatedPVC, err := c.CoreV1(). - PersistentVolumeClaims(pvcNamespace). - Get(context.TODO(), pvcName, metav1.GetOptions{}) + updatedPVC, err := getPersistentVolumeClaim(c, pvcNamespace, pvcName) if err != nil { return fmt.Errorf("error fetching pvc %q with %w", pvcName, err) } @@ -120,10 +117,7 @@ func resizePVCAndValidateSize(pvcPath, appPath string, f *framework.Framework) e opt := metav1.ListOptions{ LabelSelector: "app=resize-pvc", } - - pvc, err = f.ClientSet.CoreV1(). - PersistentVolumeClaims(pvc.Namespace). - Get(context.TODO(), pvc.Name, metav1.GetOptions{}) + pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name) if err != nil { return fmt.Errorf("failed to get pvc: %w", err) } diff --git a/e2e/upgrade-cephfs.go b/e2e/upgrade-cephfs.go index d74ef1f3e..23815e792 100644 --- a/e2e/upgrade-cephfs.go +++ b/e2e/upgrade-cephfs.go @@ -390,9 +390,7 @@ var _ = Describe("CephFS Upgrade Testing", func() { opt := metav1.ListOptions{ LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]), } - pvc, err = f.ClientSet.CoreV1(). - PersistentVolumeClaims(pvc.Namespace). - Get(context.TODO(), pvc.Name, metav1.GetOptions{}) + pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name) if err != nil { e2elog.Failf("failed to get pvc: %v", err) } diff --git a/e2e/upgrade-rbd.go b/e2e/upgrade-rbd.go index 0c62ceb03..ee9fc2051 100644 --- a/e2e/upgrade-rbd.go +++ b/e2e/upgrade-rbd.go @@ -401,9 +401,7 @@ var _ = Describe("RBD Upgrade Testing", func() { LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]), } var err error - pvc, err = f.ClientSet.CoreV1(). - PersistentVolumeClaims(pvc.Namespace). - Get(context.TODO(), pvc.Name, metav1.GetOptions{}) + pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name) if err != nil { e2elog.Failf("failed to get pvc: %v", err) } diff --git a/e2e/utils.go b/e2e/utils.go index 59f2a1048..684baaebd 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -683,9 +683,7 @@ func validatePVCClone( } checkSum := "" - pvc, err = f.ClientSet.CoreV1(). - PersistentVolumeClaims(pvc.Namespace). - Get(context.TODO(), pvc.Name, metav1.GetOptions{}) + pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name) if err != nil { e2elog.Failf("failed to get pvc %v", err) }