Skip to content

Commit 36841fe

Browse files
parikshithbnirs
authored andcommitted
e2e: make disable and undeploy actions idempotent
This change ensures that undeploy and disable actions handle missing placement resources gracefully when calling GetCurrentCluster, making them idempotent. Signed-off-by: Parikshith <[email protected]>
1 parent d662a76 commit 36841fe

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

e2e/deployers/appset.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ramendr/ramen/e2e/config"
88
"github.com/ramendr/ramen/e2e/types"
99
"github.com/ramendr/ramen/e2e/util"
10+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1011
)
1112

1213
type ApplicationSet struct{}
@@ -58,11 +59,16 @@ func (a ApplicationSet) Undeploy(ctx types.Context) error {
5859

5960
clusterName, err := util.GetCurrentCluster(util.Ctx.Hub, managementNamespace, name)
6061
if err != nil {
61-
return err
62-
}
62+
if !k8serrors.IsNotFound(err) {
63+
return err
64+
}
6365

64-
log.Infof("Undeploying applicationset app \"%s/%s\" in cluster %q",
65-
ctx.AppNamespace(), ctx.Workload().GetAppName(), clusterName)
66+
log.Debugf("Could not retrieve the cluster name: %s", err)
67+
log.Infof("Undeploying applicationset app \"%s/%s\"", ctx.AppNamespace(), ctx.Workload().GetAppName())
68+
} else {
69+
log.Infof("Undeploying applicationset app \"%s/%s\" in cluster %q",
70+
ctx.AppNamespace(), ctx.Workload().GetAppName(), clusterName)
71+
}
6672

6773
err = DeleteApplicationSet(ctx, a)
6874
if err != nil {

e2e/deployers/subscr.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ramendr/ramen/e2e/config"
88
"github.com/ramendr/ramen/e2e/types"
99
"github.com/ramendr/ramen/e2e/util"
10+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1011
subscriptionv1 "open-cluster-management.io/multicloud-operators-subscription/pkg/apis/apps/v1"
1112
)
1213

@@ -80,12 +81,17 @@ func (s Subscription) Undeploy(ctx types.Context) error {
8081

8182
clusterName, err := util.GetCurrentCluster(util.Ctx.Hub, managementNamespace, name)
8283
if err != nil {
83-
return err
84+
if !k8serrors.IsNotFound(err) {
85+
return err
86+
}
87+
88+
log.Debugf("Could not retrieve the cluster name: %s", err)
89+
log.Infof("Undeploying subscription app \"%s/%s\"", ctx.AppNamespace(), ctx.Workload().GetAppName())
90+
} else {
91+
log.Infof("Undeploying subscription app \"%s/%s\" in cluster %q",
92+
ctx.AppNamespace(), ctx.Workload().GetAppName(), clusterName)
8493
}
8594

86-
log.Infof("Undeploying subscription app \"%s/%s\" in cluster %q",
87-
ctx.AppNamespace(), ctx.Workload().GetAppName(), clusterName)
88-
8995
err = DeleteSubscription(ctx, s)
9096
if err != nil {
9197
return err

e2e/dractions/actions.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ramendr/ramen/e2e/config"
99
"github.com/ramendr/ramen/e2e/types"
1010
"github.com/ramendr/ramen/e2e/util"
11+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1112
"k8s.io/client-go/util/retry"
1213
)
1314

@@ -108,11 +109,16 @@ func DisableProtection(ctx types.Context) error {
108109

109110
clusterName, err := util.GetCurrentCluster(util.Ctx.Hub, managementNamespace, placementName)
110111
if err != nil {
111-
return err
112-
}
112+
if !k8serrors.IsNotFound(err) {
113+
return err
114+
}
113115

114-
log.Infof("Unprotecting workload \"%s/%s\" in cluster %q",
115-
appNamespace, ctx.Workload().GetAppName(), clusterName)
116+
log.Debugf("Could not retrieve the cluster name: %s", err)
117+
log.Infof("Unprotecting workload \"%s/%s\"", appNamespace, ctx.Workload().GetAppName())
118+
} else {
119+
log.Infof("Unprotecting workload \"%s/%s\" in cluster %q",
120+
appNamespace, ctx.Workload().GetAppName(), clusterName)
121+
}
116122

117123
drpcName := name
118124

e2e/dractions/disapp.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/ramendr/ramen/e2e/deployers"
1010
"github.com/ramendr/ramen/e2e/types"
1111
"github.com/ramendr/ramen/e2e/util"
12+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1213
)
1314

1415
func EnableProtectionDiscoveredApps(ctx types.Context) error {
@@ -73,11 +74,16 @@ func DisableProtectionDiscoveredApps(ctx types.Context) error {
7374

7475
clusterName, err := util.GetCurrentCluster(util.Ctx.Hub, managementNamespace, placementName)
7576
if err != nil {
76-
return err
77-
}
77+
if !k8serrors.IsNotFound(err) {
78+
return err
79+
}
7880

79-
log.Infof("Unprotecting workload \"%s/%s\" in cluster %q",
80-
appNamespace, ctx.Workload().GetAppName(), clusterName)
81+
log.Debugf("Could not retrieve the cluster name: %s", err)
82+
log.Infof("Unprotecting workload \"%s/%s\"", appNamespace, ctx.Workload().GetAppName())
83+
} else {
84+
log.Infof("Unprotecting workload \"%s/%s\" in cluster %q",
85+
appNamespace, ctx.Workload().GetAppName(), clusterName)
86+
}
8187

8288
if err := deleteDRPC(ctx, util.Ctx.Hub, managementNamespace, drpcName); err != nil {
8389
return err

0 commit comments

Comments
 (0)