Skip to content

Commit

Permalink
Enhancement to support multiple DRPC for epic-6681
Browse files Browse the repository at this point in the history
	Allow the application users to have multiple DRPCs for the
	same discovered application namespace(s). Remove the DRPC
	conflict check to enable the Ramen operator to create o
	multiple VRGs within the same namespace.

Signed-off-by: pruthvitd <prd@redhat.com>
  • Loading branch information
pruthvitd committed Feb 17, 2025
1 parent ac2617d commit 35a8291
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
28 changes: 5 additions & 23 deletions internal/controller/api/hub_managed_cluster_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,9 @@

package api

import (
// "context"
// "encoding/json"
// "fmt"
// "os"
// "strings"

// "github.com/go-logr/logr"
// ramen "github.com/ramendr/ramen/api/v1alpha1"
// "github.com/ramendr/ramen/internal/controller/kubeobjects"
// "github.com/ramendr/ramen/internal/controller/util"
// recipe "github.com/ramendr/recipe/api/v1alpha1"
// "golang.org/x/exp/slices"
// "k8s.io/apimachinery/pkg/types"
// "k8s.io/apimachinery/pkg/util/sets"
// "sigs.k8s.io/controller-runtime/pkg/builder"
// "sigs.k8s.io/controller-runtime/pkg/client"
// "sigs.k8s.io/controller-runtime/pkg/handler"
// "sigs.k8s.io/controller-runtime/pkg/reconcile"
)

const (
VMRecipeName = "vm-recipe"
VMRecipe=`
VMRecipeName = "vm-recipe"
VMRecipe = `
apiVersion: ramendr.openshift.io/v1alpha1
kind: Recipe
metadata:
Expand All @@ -43,6 +22,9 @@ spec:
- replicaset
- persistentvolumeclaims
- pods
includedResources:
- namespaces
- nodes
includedNamespaces:
- vm-dv
labelSelector:
Expand Down
20 changes: 14 additions & 6 deletions internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2503,18 +2503,26 @@ func (r *DRPlacementControlReconciler) drpcHaveCommonClusters(ctx context.Contex
return drpolicyClusters.Intersection(otherDrpolicyClusters).Len() > 0, nil
}

func drpcProtectVMInNS(drpc *rmn.DRPlacementControl, otherdrpc *rmn.DRPlacementControl, ramenConfig *rmn.RamenConfig, log logr.Logger) bool {
//nolint:wsl
func drpcProtectVMInNS(drpc *rmn.DRPlacementControl, otherdrpc *rmn.DRPlacementControl,
ramenConfig *rmn.RamenConfig, log logr.Logger) bool {
log.Info("In DRPC Protect VM in NS Validation")
if (drpc.Spec.KubeObjectProtection.RecipeRef.Name == rmnapi.VMRecipeName && otherdrpc.Spec.KubeObjectProtection.RecipeRef.Name == rmnapi.VMRecipeName) {
drpcName := drpc.Spec.KubeObjectProtection.RecipeRef.Name
otherDrpcName := otherdrpc.Spec.KubeObjectProtection.RecipeRef.Name
if drpcName == rmnapi.VMRecipeName && otherDrpcName == rmnapi.VMRecipeName {
log.Info("It could be Independent VM protection.")
ramenOpsNS:=RamenOperandsNamespace(*ramenConfig)
log.Info("Ramen Ops namespace is : "+ramenOpsNS)
if (drpc.Spec.KubeObjectProtection.RecipeRef.Namespace == ramenOpsNS && otherdrpc.Spec.KubeObjectProtection.RecipeRef.Namespace == ramenOpsNS) {
ramenOpsNS := RamenOperandsNamespace(*ramenConfig)
log.Info("Ramen Ops namespace is : " + ramenOpsNS)

if drpc.Spec.KubeObjectProtection.RecipeRef.Namespace == ramenOpsNS &&
otherdrpc.Spec.KubeObjectProtection.RecipeRef.Namespace == ramenOpsNS {
log.Info("Its a valid Independent VM protection.")

return true
}
}

log.Info("It isn't a valid Independent VM protection.")

return false
}
}
12 changes: 6 additions & 6 deletions internal/controller/vrg_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func GetPVCSelector(ctx context.Context, reader client.Reader, vrg ramen.VolumeR
return recipeElements.PvcSelector, nil
}

//nolint:funlen,cyclop
func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.VolumeReplicationGroup,
ramenConfig ramen.RamenConfig, log logr.Logger,
) (RecipeElements, error) {
Expand Down Expand Up @@ -118,14 +119,13 @@ func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.Volu
}

recipe := recipe.Recipe{}
if vrg.Spec.KubeObjectProtection.RecipeRef.Namespace == RamenOperandsNamespace(ramenConfig) && vrg.Spec.KubeObjectProtection.RecipeRef.Name==rmnapi.VMRecipeName {
if err:=yaml.Unmarshal([]byte(rmnapi.VMRecipe), &recipe); err != nil {
return recipeElements, fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err)
}
} else {
if err := reader.Get(ctx, recipeNamespacedName, &recipe); err != nil {
if vrg.Spec.KubeObjectProtection.RecipeRef.Namespace == RamenOperandsNamespace(ramenConfig) &&
vrg.Spec.KubeObjectProtection.RecipeRef.Name == rmnapi.VMRecipeName {
if err := yaml.Unmarshal([]byte(rmnapi.VMRecipe), &recipe); err != nil {
return recipeElements, fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err)
}
} else if err := reader.Get(ctx, recipeNamespacedName, &recipe); err != nil {
return recipeElements, fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err)
}

if err := RecipeParametersExpand(&recipe, vrg.Spec.KubeObjectProtection.RecipeParameters, log); err != nil {
Expand Down

0 comments on commit 35a8291

Please sign in to comment.