diff --git a/e2e/deployers/applicationset.go b/e2e/deployers/applicationset.go index 835e226b8..378e12edc 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") + log.Infof("Deploying applicationset in namespace %q", managementNamespace) - 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,37 +41,38 @@ 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") + log.Infof("Undeploying applicationset in namespace %q", managementNamespace) err := DeleteApplicationSet(ctx, a) if err != nil { 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..0ea12994f 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") + log.Infof("Deploying workload in namespace %q", appNamespace) // 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,12 +71,12 @@ 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") + log.Infof("Undeploying workload in namespace %q", appNamespace) drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.Client, util.DefaultDRPolicyName) if err != nil { @@ -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..4b0f7be93 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") + log.Infof("Deploying subscription in namespace %q", managementNamespace) // 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,33 +58,33 @@ 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") + log.Infof("Undeploying subscription in namespace %q", managementNamespace) err := DeleteSubscription(ctx, s) if err != nil { 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..bad5e1711 100644 --- a/e2e/dractions/actions.go +++ b/e2e/dractions/actions.go @@ -32,17 +32,17 @@ 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") + log.Infof("Protecting workload in namespace %q", managementNamespace) drPolicyName := util.DefaultDRPolicyName appname := w.GetAppName() 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 @@ -94,21 +93,22 @@ func DisableProtection(ctx types.Context) error { return DisableProtectionDiscoveredApps(ctx) } + name := ctx.Name() + managementNamespace := ctx.ManagementNamespace() log := ctx.Logger() - log.Info("Unprotecting workload") - name := ctx.Name() - namespace := ctx.Namespace() + log.Infof("Unprotecting workload in namespace %q", 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 { @@ -117,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) } @@ -133,26 +135,28 @@ 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) } 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..84b5ab854 100644 --- a/e2e/dractions/discovered.go +++ b/e2e/dractions/discovered.go @@ -14,10 +14,11 @@ 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") + // TODO: log cluster namespace for completeness? + log.Infof("Protecting workload in namespace %q", managementNamespace) drPolicyName := util.DefaultDRPolicyName appname := w.GetAppName() @@ -25,12 +26,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 +46,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,9 +60,10 @@ 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") + // TODO: log cluster namespace for completeness? + log.Infof("Unprotecting workload in namespace %q", managementNamespace) placementName := name drpcName := name @@ -70,32 +72,36 @@ 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 { 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) } @@ -104,13 +110,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 +128,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..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 @@ -44,12 +47,16 @@ 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.name + return c.AppNamespace() +} + +func (c *Context) AppNamespace() string { + return appNamespacePrefix + c.name } func (c *Context) Logger() *zap.SugaredLogger { 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 }