From a749ed4ac439c8d05ca2b8226ff1af143ca5b67b Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 9 Dec 2024 16:06:20 +0200 Subject: [PATCH 1/3] e2e: Clarify namespaces We use test.Context.Namespace() and namespace temporary variables for different namespaces which makes the code confusing and error prone. We have 2 namespaces: - management namespace: used for OCM and ramen resources, on the hub and depending on the deployer also on the managed clusters. - application namespace: use for application resources, and depending on the deployer, also for the OCM and ramen resources. In addition we typically managed resources on the hub (subscription, applicationset), but sometimes on the managed clusters (discovered apps). Changes: - Rename types.Context.Namespace() to types.Context.ManagementNamespace() - Add types.Context.AppNamespace() - When using a namespace, use the relevant context namespaces, and call temporary variables managementNamespace or appNamespace. Signed-off-by: Nir Soffer --- e2e/deployers/applicationset.go | 20 ++++++++------- e2e/deployers/crud.go | 19 ++++++++------- e2e/deployers/discoveredapp.go | 26 ++++++++++---------- e2e/deployers/subscription.go | 21 ++++++++-------- e2e/dractions/actions.go | 29 +++++++++++----------- e2e/dractions/discovered.go | 43 +++++++++++++++++---------------- e2e/test/context.go | 6 ++++- e2e/types/types.go | 9 ++++++- 8 files changed, 94 insertions(+), 79 deletions(-) diff --git a/e2e/deployers/applicationset.go b/e2e/deployers/applicationset.go index 835e226b8..3a39ee74b 100644 --- a/e2e/deployers/applicationset.go +++ b/e2e/deployers/applicationset.go @@ -10,24 +10,25 @@ import ( type ApplicationSet struct{} +// Deploy creates an ApplicationSet on the hub cluster, creating the workload on one of the managed clusters. func (a ApplicationSet) Deploy(ctx types.Context) error { name := ctx.Name() log := ctx.Logger() - namespace := util.ArgocdNamespace + managementNamespace := ctx.ManagementNamespace() log.Info("Deploying workload") - err := CreateManagedClusterSetBinding(McsbName, namespace) + err := CreateManagedClusterSetBinding(McsbName, managementNamespace) if err != nil { return err } - err = CreatePlacement(ctx, name, namespace) + err = CreatePlacement(ctx, name, managementNamespace) if err != nil { return err } - err = CreatePlacementDecisionConfigMap(ctx, name, namespace) + err = CreatePlacementDecisionConfigMap(ctx, name, managementNamespace) if err != nil { return err } @@ -40,10 +41,11 @@ func (a ApplicationSet) Deploy(ctx types.Context) error { return err } +// Undeploy deletes an ApplicationSet from the hub cluster, deleting the workload from the managed clusters. func (a ApplicationSet) Undeploy(ctx types.Context) error { name := ctx.Name() log := ctx.Logger() - namespace := util.ArgocdNamespace + managementNamespace := ctx.ManagementNamespace() log.Info("Undeploying workload") @@ -52,25 +54,25 @@ func (a ApplicationSet) Undeploy(ctx types.Context) error { return err } - err = DeleteConfigMap(ctx, name, namespace) + err = DeleteConfigMap(ctx, name, managementNamespace) if err != nil { return err } - err = DeletePlacement(ctx, name, namespace) + err = DeletePlacement(ctx, name, managementNamespace) if err != nil { return err } // multiple appsets could use the same mcsb in argocd ns. // so delete mcsb if only 1 appset is in argocd ns - lastAppset, err := isLastAppsetInArgocdNs(namespace) + lastAppset, err := isLastAppsetInArgocdNs(managementNamespace) if err != nil { return err } if lastAppset { - err = DeleteManagedClusterSetBinding(ctx, McsbName, namespace) + err = DeleteManagedClusterSetBinding(ctx, McsbName, managementNamespace) if err != nil { return err } diff --git a/e2e/deployers/crud.go b/e2e/deployers/crud.go index edc9dabcb..352d9d5e2 100644 --- a/e2e/deployers/crud.go +++ b/e2e/deployers/crud.go @@ -136,7 +136,7 @@ func CreateSubscription(ctx types.Context, s Subscription) error { name := ctx.Name() log := ctx.Logger() w := ctx.Workload() - namespace := name + managementNamespace := ctx.ManagementNamespace() labels := make(map[string]string) labels[AppLabelKey] = name @@ -156,7 +156,7 @@ func CreateSubscription(ctx types.Context, s Subscription) error { subscription := &subscriptionv1.Subscription{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: managementNamespace, Labels: labels, Annotations: annotations, }, @@ -191,12 +191,12 @@ func CreateSubscription(ctx types.Context, s Subscription) error { func DeleteSubscription(ctx types.Context, s Subscription) error { name := ctx.Name() log := ctx.Logger() - namespace := name + managementNamespace := ctx.ManagementNamespace() subscription := &subscriptionv1.Subscription{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: managementNamespace, }, } @@ -276,12 +276,13 @@ func CreateApplicationSet(ctx types.Context, a ApplicationSet) error { name := ctx.Name() log := ctx.Logger() w := ctx.Workload() - namespace := util.ArgocdNamespace + managementNamespace := ctx.ManagementNamespace() + appNamespace := ctx.AppNamespace() appset := &argocdv1alpha1hack.ApplicationSet{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: managementNamespace, }, Spec: argocdv1alpha1hack.ApplicationSetSpec{ Generators: []argocdv1alpha1hack.ApplicationSetGenerator{ @@ -309,7 +310,7 @@ func CreateApplicationSet(ctx types.Context, a ApplicationSet) error { }, Destination: argocdv1alpha1hack.ApplicationDestination{ Server: "{{server}}", - Namespace: name, + Namespace: appNamespace, }, Project: "default", SyncPolicy: &argocdv1alpha1hack.SyncPolicy{ @@ -353,12 +354,12 @@ func CreateApplicationSet(ctx types.Context, a ApplicationSet) error { func DeleteApplicationSet(ctx types.Context, a ApplicationSet) error { name := ctx.Name() log := ctx.Logger() - namespace := util.ArgocdNamespace + managementNamespace := ctx.ManagementNamespace() appset := &argocdv1alpha1hack.ApplicationSet{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: managementNamespace, }, } diff --git a/e2e/deployers/discoveredapp.go b/e2e/deployers/discoveredapp.go index 54973c315..ec7b832ee 100644 --- a/e2e/deployers/discoveredapp.go +++ b/e2e/deployers/discoveredapp.go @@ -22,15 +22,15 @@ func (d DiscoveredApp) GetNamespace() string { return util.RamenOpsNamespace } +// Deploy creates a workload on the first managed cluster. func (d DiscoveredApp) Deploy(ctx types.Context) error { - name := ctx.Name() log := ctx.Logger() - namespace := name + appNamespace := ctx.AppNamespace() log.Info("Deploying workload") // create namespace in both dr clusters - if err := util.CreateNamespaceAndAddAnnotation(namespace); err != nil { + if err := util.CreateNamespaceAndAddAnnotation(appNamespace); err != nil { return err } @@ -51,7 +51,7 @@ func (d DiscoveredApp) Deploy(ctx types.Context) error { return err } - cmd := exec.Command("kubectl", "apply", "-k", tempDir, "-n", namespace, + cmd := exec.Command("kubectl", "apply", "-k", tempDir, "-n", appNamespace, "--context", drpolicy.Spec.DRClusters[0], "--timeout=5m") if out, err := cmd.Output(); err != nil { @@ -62,7 +62,7 @@ func (d DiscoveredApp) Deploy(ctx types.Context) error { return err } - if err = WaitWorkloadHealth(ctx, util.Ctx.C1.Client, namespace); err != nil { + if err = WaitWorkloadHealth(ctx, util.Ctx.C1.Client, appNamespace); err != nil { return err } @@ -71,10 +71,10 @@ func (d DiscoveredApp) Deploy(ctx types.Context) error { return nil } +// Undeploy deletes the workload from the managed clusters. func (d DiscoveredApp) Undeploy(ctx types.Context) error { - name := ctx.Name() log := ctx.Logger() - namespace := name // this namespace is in dr clusters + appNamespace := ctx.AppNamespace() log.Info("Undeploying workload") @@ -86,26 +86,26 @@ func (d DiscoveredApp) Undeploy(ctx types.Context) error { log.Infof("Deleting discovered apps on cluster %q", drpolicy.Spec.DRClusters[0]) // delete app on both clusters - if err := DeleteDiscoveredApps(ctx, namespace, drpolicy.Spec.DRClusters[0]); err != nil { + if err := DeleteDiscoveredApps(ctx, appNamespace, drpolicy.Spec.DRClusters[0]); err != nil { return err } log.Infof("Deletting discovered apps on cluster %q", drpolicy.Spec.DRClusters[1]) - if err := DeleteDiscoveredApps(ctx, namespace, drpolicy.Spec.DRClusters[1]); err != nil { + if err := DeleteDiscoveredApps(ctx, appNamespace, drpolicy.Spec.DRClusters[1]); err != nil { return err } - log.Infof("Deleting namespace %q on cluster %q", namespace, drpolicy.Spec.DRClusters[0]) + log.Infof("Deleting namespace %q on cluster %q", appNamespace, drpolicy.Spec.DRClusters[0]) // delete namespace on both clusters - if err := util.DeleteNamespace(util.Ctx.C1.Client, namespace, log); err != nil { + if err := util.DeleteNamespace(util.Ctx.C1.Client, appNamespace, log); err != nil { return err } - log.Infof("Deleting namespace %q on cluster %q", namespace, drpolicy.Spec.DRClusters[1]) + log.Infof("Deleting namespace %q on cluster %q", appNamespace, drpolicy.Spec.DRClusters[1]) - if err := util.DeleteNamespace(util.Ctx.C2.Client, namespace, log); err != nil { + if err := util.DeleteNamespace(util.Ctx.C2.Client, appNamespace, log); err != nil { return err } diff --git a/e2e/deployers/subscription.go b/e2e/deployers/subscription.go index f3e0003e1..fe80fdf0c 100644 --- a/e2e/deployers/subscription.go +++ b/e2e/deployers/subscription.go @@ -23,6 +23,7 @@ func (s Subscription) GetNamespace() string { return "" } +// Deploy creates a Subscription on the hub cluster, creating the workload on one of the managed clusters. func (s Subscription) Deploy(ctx types.Context) error { // Generate a Placement for the Workload // Use the global Channel @@ -32,22 +33,22 @@ func (s Subscription) Deploy(ctx types.Context) error { // Address namespace/label/suffix as needed for various resources name := ctx.Name() log := ctx.Logger() - namespace := name + managementNamespace := ctx.ManagementNamespace() log.Info("Deploying workload") // create subscription namespace - err := util.CreateNamespace(util.Ctx.Hub.Client, namespace) + err := util.CreateNamespace(util.Ctx.Hub.Client, managementNamespace) if err != nil { return err } - err = CreateManagedClusterSetBinding(McsbName, namespace) + err = CreateManagedClusterSetBinding(McsbName, managementNamespace) if err != nil { return err } - err = CreatePlacement(ctx, name, namespace) + err = CreatePlacement(ctx, name, managementNamespace) if err != nil { return err } @@ -57,14 +58,14 @@ func (s Subscription) Deploy(ctx types.Context) error { return err } - return waitSubscriptionPhase(ctx, namespace, name, subscriptionv1.SubscriptionPropagated) + return waitSubscriptionPhase(ctx, managementNamespace, name, subscriptionv1.SubscriptionPropagated) } -// Delete Subscription, Placement, Binding +// Undeploy deletes a subscription from the hub cluster, deleting the workload from the managed clusters. func (s Subscription) Undeploy(ctx types.Context) error { name := ctx.Name() log := ctx.Logger() - namespace := name + managementNamespace := ctx.ManagementNamespace() log.Info("Undeploying workload") @@ -73,17 +74,17 @@ func (s Subscription) Undeploy(ctx types.Context) error { return err } - err = DeletePlacement(ctx, name, namespace) + err = DeletePlacement(ctx, name, managementNamespace) if err != nil { return err } - err = DeleteManagedClusterSetBinding(ctx, McsbName, namespace) + err = DeleteManagedClusterSetBinding(ctx, McsbName, managementNamespace) if err != nil { return err } - return util.DeleteNamespace(util.Ctx.Hub.Client, namespace, log) + return util.DeleteNamespace(util.Ctx.Hub.Client, managementNamespace, log) } func (s Subscription) IsWorkloadSupported(w types.Workload) bool { diff --git a/e2e/dractions/actions.go b/e2e/dractions/actions.go index f5a3ca2e4..88b2614b0 100644 --- a/e2e/dractions/actions.go +++ b/e2e/dractions/actions.go @@ -32,7 +32,7 @@ func EnableProtection(ctx types.Context) error { w := ctx.Workload() name := ctx.Name() - namespace := ctx.Namespace() + managementNamespace := ctx.ManagementNamespace() log := ctx.Logger() log.Info("Protecting workload") @@ -42,7 +42,7 @@ func EnableProtection(ctx types.Context) error { placementName := name drpcName := name - placementDecision, err := waitPlacementDecision(util.Ctx.Hub.Client, namespace, placementName) + placementDecision, err := waitPlacementDecision(util.Ctx.Hub.Client, managementNamespace, placementName) if err != nil { return err } @@ -53,7 +53,7 @@ func EnableProtection(ctx types.Context) error { log.Info("Annotating placement") err = retry.RetryOnConflict(retry.DefaultBackoff, func() error { - placement, err := getPlacement(util.Ctx.Hub.Client, namespace, placementName) + placement, err := getPlacement(util.Ctx.Hub.Client, managementNamespace, placementName) if err != nil { return err } @@ -72,18 +72,17 @@ func EnableProtection(ctx types.Context) error { log.Info("Creating drpc") - drpc := generateDRPC(name, namespace, clusterName, drPolicyName, placementName, appname) + drpc := generateDRPC(name, managementNamespace, clusterName, drPolicyName, placementName, appname) if err = createDRPC(util.Ctx.Hub.Client, drpc); err != nil { return err } - // this is the application namespace in drclusters to add the annotation - nsToAnnotate := name - if err := util.CreateNamespaceAndAddAnnotation(nsToAnnotate); err != nil { + // For volsync based replication we must create the cluster namespaces with special annotation. + if err := util.CreateNamespaceAndAddAnnotation(ctx.AppNamespace()); err != nil { return err } - return waitDRPCReady(ctx, util.Ctx.Hub.Client, namespace, drpcName) + return waitDRPCReady(ctx, util.Ctx.Hub.Client, managementNamespace, drpcName) } // remove DRPC @@ -98,17 +97,17 @@ func DisableProtection(ctx types.Context) error { log.Info("Unprotecting workload") name := ctx.Name() - namespace := ctx.Namespace() + managementNamespace := ctx.ManagementNamespace() drpcName := name client := util.Ctx.Hub.Client log.Info("Deleting drpc") - if err := deleteDRPC(client, namespace, drpcName); err != nil { + if err := deleteDRPC(client, managementNamespace, drpcName); err != nil { return err } - return waitDRPCDeleted(ctx, client, namespace, drpcName) + return waitDRPCDeleted(ctx, client, managementNamespace, drpcName) } func Failover(ctx types.Context) error { @@ -141,18 +140,18 @@ func Relocate(ctx types.Context) error { func failoverRelocate(ctx types.Context, action ramen.DRAction, state ramen.DRState) error { drpcName := ctx.Name() - namespace := ctx.Namespace() + managementNamespace := ctx.ManagementNamespace() client := util.Ctx.Hub.Client - if err := waitAndUpdateDRPC(ctx, client, namespace, drpcName, action); err != nil { + if err := waitAndUpdateDRPC(ctx, client, managementNamespace, drpcName, action); err != nil { return err } - if err := waitDRPCPhase(ctx, client, namespace, drpcName, state); err != nil { + if err := waitDRPCPhase(ctx, client, managementNamespace, drpcName, state); err != nil { return err } - return waitDRPCReady(ctx, client, namespace, drpcName) + return waitDRPCReady(ctx, client, managementNamespace, drpcName) } func waitAndUpdateDRPC( diff --git a/e2e/dractions/discovered.go b/e2e/dractions/discovered.go index af169e510..44c798cd6 100644 --- a/e2e/dractions/discovered.go +++ b/e2e/dractions/discovered.go @@ -14,8 +14,8 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error { w := ctx.Workload() name := ctx.Name() log := ctx.Logger() - namespace := ctx.Namespace() // this namespace is in hub - namespaceInDrCluster := name // this namespace is in dr clusters + managementNamespace := ctx.ManagementNamespace() + appNamespace := ctx.AppNamespace() log.Info("Protecting workload") @@ -25,12 +25,12 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error { drpcName := name // create mcsb default in ramen-ops ns - if err := deployers.CreateManagedClusterSetBinding(deployers.McsbName, namespace); err != nil { + if err := deployers.CreateManagedClusterSetBinding(deployers.McsbName, managementNamespace); err != nil { return err } // create placement - if err := createPlacementManagedByRamen(ctx, placementName, namespace); err != nil { + if err := createPlacementManagedByRamen(ctx, placementName, managementNamespace); err != nil { return err } @@ -45,13 +45,13 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error { clusterName := drpolicy.Spec.DRClusters[0] drpc := generateDRPCDiscoveredApps( - name, namespace, clusterName, drPolicyName, placementName, appname, namespaceInDrCluster) + name, managementNamespace, clusterName, drPolicyName, placementName, appname, appNamespace) if err = createDRPC(util.Ctx.Hub.Client, drpc); err != nil { return err } // wait for drpc ready - return waitDRPCReady(ctx, util.Ctx.Hub.Client, namespace, drpcName) + return waitDRPCReady(ctx, util.Ctx.Hub.Client, managementNamespace, drpcName) } // remove DRPC @@ -59,7 +59,7 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error { func DisableProtectionDiscoveredApps(ctx types.Context) error { name := ctx.Name() log := ctx.Logger() - namespace := ctx.Namespace() // this namespace is in hub + managementNamespace := ctx.ManagementNamespace() log.Info("Unprotecting workload") @@ -70,20 +70,20 @@ func DisableProtectionDiscoveredApps(ctx types.Context) error { log.Info("Deleting drpc") - if err := deleteDRPC(client, namespace, drpcName); err != nil { + if err := deleteDRPC(client, managementNamespace, drpcName); err != nil { return err } - if err := waitDRPCDeleted(ctx, client, namespace, drpcName); err != nil { + if err := waitDRPCDeleted(ctx, client, managementNamespace, drpcName); err != nil { return err } // delete placement - if err := deployers.DeletePlacement(ctx, placementName, namespace); err != nil { + if err := deployers.DeletePlacement(ctx, placementName, managementNamespace); err != nil { return err } - return deployers.DeleteManagedClusterSetBinding(ctx, deployers.McsbName, namespace) + return deployers.DeleteManagedClusterSetBinding(ctx, deployers.McsbName, managementNamespace) } func FailoverDiscoveredApps(ctx types.Context) error { @@ -104,13 +104,13 @@ func RelocateDiscoveredApps(ctx types.Context) error { func failoverRelocateDiscoveredApps(ctx types.Context, action ramen.DRAction, state ramen.DRState) error { name := ctx.Name() log := ctx.Logger() - namespace := ctx.Namespace() // this namespace is in hub - namespaceInDrCluster := name // this namespace is in dr clusters + managementNamespace := ctx.ManagementNamespace() + appNamespace := ctx.AppNamespace() drpcName := name client := util.Ctx.Hub.Client - currentCluster, err := getCurrentCluster(client, namespace, name) + currentCluster, err := getCurrentCluster(client, managementNamespace, name) if err != nil { return err } @@ -122,35 +122,36 @@ func failoverRelocateDiscoveredApps(ctx types.Context, action ramen.DRAction, st return err } - targetCluster, err := getTargetCluster(client, namespace, drpcName, drpolicy) + targetCluster, err := getTargetCluster(client, managementNamespace, drpcName, drpolicy) if err != nil { return err } - if err := waitAndUpdateDRPC(ctx, client, namespace, drpcName, action); err != nil { + if err := waitAndUpdateDRPC(ctx, client, managementNamespace, drpcName, action); err != nil { return err } - if err := waitDRPCProgression(ctx, client, namespace, name, ramen.ProgressionWaitOnUserToCleanUp); err != nil { + if err := waitDRPCProgression(ctx, client, managementNamespace, name, + ramen.ProgressionWaitOnUserToCleanUp); err != nil { return err } // delete pvc and deployment from dr cluster log.Infof("Cleaning up discovered apps from cluster %q", currentCluster) - if err = deployers.DeleteDiscoveredApps(ctx, namespaceInDrCluster, currentCluster); err != nil { + if err = deployers.DeleteDiscoveredApps(ctx, appNamespace, currentCluster); err != nil { return err } - if err := waitDRPCPhase(ctx, client, namespace, name, state); err != nil { + if err := waitDRPCPhase(ctx, client, managementNamespace, name, state); err != nil { return err } - if err := waitDRPCReady(ctx, client, namespace, name); err != nil { + if err := waitDRPCReady(ctx, client, managementNamespace, name); err != nil { return err } drClient := getDRClusterClient(targetCluster, drpolicy) - return deployers.WaitWorkloadHealth(ctx, drClient, namespaceInDrCluster) + return deployers.WaitWorkloadHealth(ctx, drClient, appNamespace) } diff --git a/e2e/test/context.go b/e2e/test/context.go index 31e112e5a..46b854ab4 100644 --- a/e2e/test/context.go +++ b/e2e/test/context.go @@ -44,11 +44,15 @@ func (c *Context) Name() string { return c.name } -func (c *Context) Namespace() string { +func (c *Context) ManagementNamespace() string { if ns := c.deployer.GetNamespace(); ns != "" { return ns } + return c.AppNamespace() +} + +func (c *Context) AppNamespace() string { return c.name } diff --git a/e2e/types/types.go b/e2e/types/types.go index ca38004b6..a1677a556 100644 --- a/e2e/types/types.go +++ b/e2e/types/types.go @@ -39,6 +39,13 @@ type Context interface { Deployer() Deployer Workload() Workload Name() string - Namespace() string + + // Namespace for OCM and Ramen resources (Subscription, ApplicationSet, DRPC, VRG) on the hub and managed clusters. + // Depending on the deployer, it may be the same as AppNamespace(). + ManagementNamespace() string + + // Namespace for application resources on the managed clusters. + AppNamespace() string + Logger() *zap.SugaredLogger } From e76d28f51ea2b04ae22a7244d4277692fca51030 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 9 Dec 2024 21:59:07 +0200 Subject: [PATCH 2/3] e2e: More detailed main logs Add the management or app namespace to the initial deploy/undeploy/protect/unprotect/failover/relocate logs. Example logs (showing only "Deploying" logs): 2024-12-10T11:11:23.616+0200 INFO subscr-deploy-rbd-busybox deployers/subscription.go:38 Deploying subscription in namespace "e2e-subscr-deploy-rbd-busybox" 2024-12-10T11:11:23.616+0200 INFO appset-deploy-rbd-busybox deployers/applicationset.go:19 Deploying applicationset in namespace "argocd" 2024-12-10T11:11:23.616+0200 INFO appset-deploy-cephfs-busybox deployers/applicationset.go:19 Deploying applicationset in namespace "argocd" 2024-12-10T11:11:23.616+0200 INFO disapp-deploy-rbd-busybox deployers/discoveredapps.go:30 Deploying workload in namespace "e2e-disapp-deploy-rbd-busybox" 2024-12-10T11:11:23.616+0200 INFO subscr-deploy-cephfs-busybox deployers/subscription.go:38 Deploying subscription in namespace "e2e-subscr-deploy-cephfs-busybox" Signed-off-by: Nir Soffer --- e2e/deployers/applicationset.go | 4 ++-- e2e/deployers/discoveredapp.go | 4 ++-- e2e/deployers/subscription.go | 4 ++-- e2e/dractions/actions.go | 17 +++++++++++------ e2e/dractions/discovered.go | 14 ++++++++++---- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/e2e/deployers/applicationset.go b/e2e/deployers/applicationset.go index 3a39ee74b..378e12edc 100644 --- a/e2e/deployers/applicationset.go +++ b/e2e/deployers/applicationset.go @@ -16,7 +16,7 @@ func (a ApplicationSet) Deploy(ctx types.Context) error { log := ctx.Logger() managementNamespace := ctx.ManagementNamespace() - log.Info("Deploying workload") + log.Infof("Deploying applicationset in namespace %q", managementNamespace) err := CreateManagedClusterSetBinding(McsbName, managementNamespace) if err != nil { @@ -47,7 +47,7 @@ func (a ApplicationSet) Undeploy(ctx types.Context) error { log := ctx.Logger() managementNamespace := ctx.ManagementNamespace() - log.Info("Undeploying workload") + log.Infof("Undeploying applicationset in namespace %q", managementNamespace) err := DeleteApplicationSet(ctx, a) if err != nil { diff --git a/e2e/deployers/discoveredapp.go b/e2e/deployers/discoveredapp.go index ec7b832ee..0ea12994f 100644 --- a/e2e/deployers/discoveredapp.go +++ b/e2e/deployers/discoveredapp.go @@ -27,7 +27,7 @@ func (d DiscoveredApp) Deploy(ctx types.Context) error { log := ctx.Logger() appNamespace := ctx.AppNamespace() - log.Info("Deploying workload") + log.Infof("Deploying workload in namespace %q", appNamespace) // create namespace in both dr clusters if err := util.CreateNamespaceAndAddAnnotation(appNamespace); err != nil { @@ -76,7 +76,7 @@ func (d DiscoveredApp) Undeploy(ctx types.Context) error { log := ctx.Logger() appNamespace := ctx.AppNamespace() - log.Info("Undeploying workload") + log.Infof("Undeploying workload in namespace %q", appNamespace) drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.Client, util.DefaultDRPolicyName) if err != nil { diff --git a/e2e/deployers/subscription.go b/e2e/deployers/subscription.go index fe80fdf0c..4b0f7be93 100644 --- a/e2e/deployers/subscription.go +++ b/e2e/deployers/subscription.go @@ -35,7 +35,7 @@ func (s Subscription) Deploy(ctx types.Context) error { log := ctx.Logger() managementNamespace := ctx.ManagementNamespace() - log.Info("Deploying workload") + log.Infof("Deploying subscription in namespace %q", managementNamespace) // create subscription namespace err := util.CreateNamespace(util.Ctx.Hub.Client, managementNamespace) @@ -67,7 +67,7 @@ func (s Subscription) Undeploy(ctx types.Context) error { log := ctx.Logger() managementNamespace := ctx.ManagementNamespace() - log.Info("Undeploying workload") + log.Infof("Undeploying subscription in namespace %q", managementNamespace) err := DeleteSubscription(ctx, s) if err != nil { diff --git a/e2e/dractions/actions.go b/e2e/dractions/actions.go index 88b2614b0..bad5e1711 100644 --- a/e2e/dractions/actions.go +++ b/e2e/dractions/actions.go @@ -35,7 +35,7 @@ func EnableProtection(ctx types.Context) error { managementNamespace := ctx.ManagementNamespace() log := ctx.Logger() - log.Info("Protecting workload") + log.Infof("Protecting workload in namespace %q", managementNamespace) drPolicyName := util.DefaultDRPolicyName appname := w.GetAppName() @@ -93,11 +93,12 @@ func DisableProtection(ctx types.Context) error { return DisableProtectionDiscoveredApps(ctx) } - log := ctx.Logger() - log.Info("Unprotecting workload") - name := ctx.Name() managementNamespace := ctx.ManagementNamespace() + log := ctx.Logger() + + log.Infof("Unprotecting workload in namespace %q", managementNamespace) + drpcName := name client := util.Ctx.Hub.Client @@ -116,8 +117,10 @@ func Failover(ctx types.Context) error { return FailoverDiscoveredApps(ctx) } + managementNamespace := ctx.ManagementNamespace() log := ctx.Logger() - log.Info("Failing over workload") + + log.Infof("Failing over workload in namespace %q", managementNamespace) return failoverRelocate(ctx, ramen.ActionFailover, ramen.FailedOver) } @@ -132,8 +135,10 @@ func Relocate(ctx types.Context) error { return RelocateDiscoveredApps(ctx) } + managementNamespace := ctx.ManagementNamespace() log := ctx.Logger() - log.Info("Relocating workload") + + log.Infof("Relocating workload in namespace %q", managementNamespace) return failoverRelocate(ctx, ramen.ActionRelocate, ramen.Relocated) } diff --git a/e2e/dractions/discovered.go b/e2e/dractions/discovered.go index 44c798cd6..84b5ab854 100644 --- a/e2e/dractions/discovered.go +++ b/e2e/dractions/discovered.go @@ -17,7 +17,8 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error { managementNamespace := ctx.ManagementNamespace() appNamespace := ctx.AppNamespace() - log.Info("Protecting workload") + // TODO: log cluster namespace for completeness? + log.Infof("Protecting workload in namespace %q", managementNamespace) drPolicyName := util.DefaultDRPolicyName appname := w.GetAppName() @@ -61,7 +62,8 @@ func DisableProtectionDiscoveredApps(ctx types.Context) error { log := ctx.Logger() managementNamespace := ctx.ManagementNamespace() - log.Info("Unprotecting workload") + // TODO: log cluster namespace for completeness? + log.Infof("Unprotecting workload in namespace %q", managementNamespace) placementName := name drpcName := name @@ -88,14 +90,18 @@ func DisableProtectionDiscoveredApps(ctx types.Context) error { func FailoverDiscoveredApps(ctx types.Context) error { log := ctx.Logger() - log.Info("Failing over workload") + managementNamespace := ctx.ManagementNamespace() + + log.Infof("Failing over workload in namespace %q", managementNamespace) return failoverRelocateDiscoveredApps(ctx, ramen.ActionFailover, ramen.FailedOver) } func RelocateDiscoveredApps(ctx types.Context) error { log := ctx.Logger() - log.Info("Relocating workload") + managementNamespace := ctx.ManagementNamespace() + + log.Infof("Relocating workload in namespace %q", managementNamespace) return failoverRelocateDiscoveredApps(ctx, ramen.ActionRelocate, ramen.Relocated) } From 48a3fb4e43a511109f7a49db153d6862786e0203 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 9 Dec 2024 16:22:17 +0200 Subject: [PATCH 3/3] e2e: Add e2e- prefix to test namespaces It it hard to manage the namespaces created for every test when they don't have a common prefix. Add "e2e-" prefix so all of them sort together when listing namespaces. Example namespaces during test: % kubectl get ns --context hub | grep e2e- e2e-subscr-deploy-cephfs-busybox Active 6m2s e2e-subscr-deploy-rbd-busybox Active 6m2s % kubectl get ns --context dr1 | grep e2e- e2e-disapp-deploy-rbd-busybox Active 4m49s e2e-subscr-deploy-cephfs-busybox Active 4m14s e2e-subscr-deploy-rbd-busybox Active 4m48s % kubectl get ns --context dr2 | grep e2e- e2e-disapp-deploy-rbd-busybox Active 5m10s e2e-subscr-deploy-cephfs-busybox Active 5m8s e2e-subscr-deploy-rbd-busybox Active 4m35s Fixes: #1611 Signed-off-by: Nir Soffer --- e2e/test/context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/e2e/test/context.go b/e2e/test/context.go index 46b854ab4..e489759c8 100644 --- a/e2e/test/context.go +++ b/e2e/test/context.go @@ -14,6 +14,9 @@ import ( "go.uber.org/zap" ) +// Make it easier to manage namespaces created by the tests. +const appNamespacePrefix = "e2e-" + type Context struct { workload types.Workload deployer types.Deployer @@ -53,7 +56,7 @@ func (c *Context) ManagementNamespace() string { } func (c *Context) AppNamespace() string { - return c.name + return appNamespacePrefix + c.name } func (c *Context) Logger() *zap.SugaredLogger {