Skip to content

Commit 26547ac

Browse files
committed
e2e: check PVC health in workload Health()
Fail when application PVCs are Lost or being deleted, and treat Pending as retryable so wait loops can recover during deploy. Signed-off-by: raaizik <132667934+raaizik@users.noreply.github.com>
1 parent b0321f8 commit 26547ac

5 files changed

Lines changed: 69 additions & 2 deletions

File tree

e2e/deployers/retry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package deployers
55

66
import (
7+
"errors"
78
"fmt"
89
"time"
910

@@ -64,6 +65,10 @@ func WaitWorkloadHealth(ctx types.TestContext, cluster *types.Cluster) error {
6465
return nil
6566
}
6667

68+
if errors.Is(err, util.ErrUnrecoverable) {
69+
return err
70+
}
71+
6772
if err := util.Sleep(ctx.Context(), util.RetryInterval); err != nil {
6873
return fmt.Errorf("workload \"%s/%s\" is not healthy in cluster %q: %w",
6974
ctx.AppNamespace(), w.GetAppName(), cluster.Name, err)

e2e/util/errors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-FileCopyrightText: The RamenDR authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package util
5+
6+
import "errors"
7+
8+
// ErrUnrecoverable marks a health check failure that should not be retried.
9+
var ErrUnrecoverable = errors.New("unrecoverable error")

e2e/workloads/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (w Deployment) Health(ctx types.TestContext, cluster *types.Cluster) error
158158
condition.Reason, deploymentMinimumReplicasAvailable, cluster.Name)
159159
}
160160

161-
return nil
161+
return checkPVCHealth(ctx, cluster, ctx.AppNamespace(), deploymentPVCName)
162162
}
163163

164164
// Status returns the deployment status across managed clusters.

e2e/workloads/pvc.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

e2e/workloads/vm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (w *VM) Health(ctx types.TestContext, cluster *types.Cluster) error {
124124
condition.Status, cluster.Name, condition.Message)
125125
}
126126

127-
return nil
127+
return checkPVCHealth(ctx, cluster, ctx.AppNamespace(), vmPVCName)
128128
}
129129

130130
// Status returns the VM workload deployment status across managed clusters.

0 commit comments

Comments
 (0)