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
multiple VRGs within the same namespace.

Signed-off-by: pruthvitd <[email protected]>
  • Loading branch information
pruthvitd committed Feb 19, 2025
1 parent e2d4809 commit bc8c163
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
60 changes: 60 additions & 0 deletions internal/controller/api/hub_managed_cluster_apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: The RamenDR authors
// SPDX-License-Identifier: Apache-2.0

package api

const (
VMRecipeName = "vm-recipe"
VMRecipe = `
apiVersion: ramendr.openshift.io/v1alpha1
kind: Recipe
metadata:
name: vm-recipe
namespace: ramen-ops
spec:
appType: vm-dv
groups:
- backupRef: vm-dv
excludedResourceTypes:
- events
- event.events.k8s.io
- persistentvolumes
- replicaset
- persistentvolumeclaims
- pods
includedResources:
- namespaces
- nodes
includedNamespaces:
- vm-dv
labelSelector:
matchExpressions:
- key: appname
operator: In
values:
- vm
name: vm-dv
type: resource
workflows:
- failOn: any-error
name: backup
sequence:
- group: vm-dv
- failOn: any-error
name: restore
sequence:
- group: vm-dv
volumes:
includedNamespaces:
- vm-dv
name: varlog
type: volume
labelSelector:
matchExpressions:
- key: appname
operator: In
values:
- vm
`
)

36 changes: 32 additions & 4 deletions internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/go-logr/logr"
"github.com/google/uuid"
plrv1 "github.com/stolostron/multicloud-operators-placementrule/pkg/apis/apps/v1"
rmnapi "github.com/ramendr/ramen/internal/controller/api"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -2466,10 +2467,13 @@ func (r *DRPlacementControlReconciler) twoDRPCsConflict(ctx context.Context,
return fmt.Errorf("failed to get protected namespaces for drpc: %v, %w", otherDRPC.Name, err)
}

conflict := drpcsProtectCommonNamespace(drpcProtectedNamespaces, otherDRPCProtectedNamespaces)
if conflict {
return fmt.Errorf("drpc: %s and drpc: %s protect the same namespace",
drpc.Name, otherDRPC.Name)
potentialConflict := drpcsProtectCommonNamespace(drpcProtectedNamespaces, otherDRPCProtectedNamespaces)
if potentialConflict {
independentVMProtection := drpcProtectVMInNS(drpc, otherDRPC, ramenConfig, log)
if !independentVMProtection {
return fmt.Errorf("drpc: %s and drpc: %s protect common resources from the same namespace",
drpc.Name, otherDRPC.Name)
}
}

return nil
Expand Down Expand Up @@ -2499,3 +2503,27 @@ 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 {
log.Info("In DRPC Protect VM in NS Validation")
drpcName := drpc.Spec.KubeObjectProtection.RecipeRef.Name

Check failure on line 2510 in internal/controller/drplacementcontrol_controller.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

assignments should only be cuddled with other assignments (wsl)
otherDrpcName := otherdrpc.Spec.KubeObjectProtection.RecipeRef.Name
if drpcName == rmnapi.VMRecipeName && otherDrpcName == rmnapi.VMRecipeName {

Check failure on line 2512 in internal/controller/drplacementcontrol_controller.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

unnecessary leading newline (whitespace)

ramenOpsNS := RamenOperandsNamespace(*ramenConfig)
log.Info("It could be Independent VM protection.")

Check failure on line 2515 in internal/controller/drplacementcontrol_controller.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

only cuddled expressions if assigning variable or using from line above (wsl)
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
}
10 changes: 9 additions & 1 deletion internal/controller/vrg_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/go-logr/logr"
ramen "github.com/ramendr/ramen/api/v1alpha1"
rmnapi "github.com/ramendr/ramen/internal/controller/api"
"github.com/ramendr/ramen/internal/controller/kubeobjects"
"github.com/ramendr/ramen/internal/controller/util"
recipe "github.com/ramendr/recipe/api/v1alpha1"
Expand All @@ -22,6 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/yaml"
)

type RecipeElements struct {
Expand Down Expand Up @@ -116,7 +118,13 @@ func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.Volu
}

recipe := recipe.Recipe{}
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)
}

Expand Down

0 comments on commit bc8c163

Please sign in to comment.