|
| 1 | +// SPDX-FileCopyrightText: The RamenDR authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package workloads |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + |
| 9 | + corev1 "k8s.io/api/core/v1" |
| 10 | + k8serrors "k8s.io/apimachinery/pkg/api/errors" |
| 11 | + |
| 12 | + "github.com/ramendr/ramen/e2e/types" |
| 13 | + "github.com/ramendr/ramen/e2e/util" |
| 14 | +) |
| 15 | + |
| 16 | +// checkPVCHealth verifies the application PVC is Bound and not being deleted. |
| 17 | +// Bound returns nil. Pending and NotFound are retryable. Lost or a set |
| 18 | +// deletionTimestamp wrap util.ErrUnrecoverable so wait loops fail immediately. |
| 19 | +func checkPVCHealth( |
| 20 | + ctx types.TestContext, |
| 21 | + cluster *types.Cluster, |
| 22 | + namespace, pvcName string, |
| 23 | +) error { |
| 24 | + pvc, err := getPVC(ctx, cluster, namespace, pvcName) |
| 25 | + if err != nil { |
| 26 | + if k8serrors.IsNotFound(err) { |
| 27 | + return fmt.Errorf("pvc \"%s/%s\" not found in cluster %q", |
| 28 | + namespace, pvcName, cluster.Name) |
| 29 | + } |
| 30 | + |
| 31 | + return fmt.Errorf("pvc \"%s/%s\" not available in cluster %q: %w", |
| 32 | + namespace, pvcName, cluster.Name, err) |
| 33 | + } |
| 34 | + |
| 35 | + if pvc.DeletionTimestamp != nil { |
| 36 | + return fmt.Errorf("pvc \"%s/%s\" is being deleted in cluster %q: %w", |
| 37 | + namespace, pvcName, cluster.Name, util.ErrUnrecoverable) |
| 38 | + } |
| 39 | + |
| 40 | + switch pvc.Status.Phase { |
| 41 | + case corev1.ClaimBound: |
| 42 | + return nil |
| 43 | + case corev1.ClaimPending: |
| 44 | + return fmt.Errorf("pvc \"%s/%s\" phase is %q, expected %q in cluster %q", |
| 45 | + namespace, pvcName, pvc.Status.Phase, corev1.ClaimBound, cluster.Name) |
| 46 | + case corev1.ClaimLost: |
| 47 | + return fmt.Errorf("pvc \"%s/%s\" phase is %q in cluster %q: %w", |
| 48 | + namespace, pvcName, pvc.Status.Phase, cluster.Name, util.ErrUnrecoverable) |
| 49 | + default: |
| 50 | + return fmt.Errorf("pvc \"%s/%s\" phase is %q, expected %q in cluster %q", |
| 51 | + namespace, pvcName, pvc.Status.Phase, corev1.ClaimBound, cluster.Name) |
| 52 | + } |
| 53 | +} |
0 commit comments