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 <prd@redhat.com>
  • Loading branch information
pruthvitd committed Feb 18, 2025
1 parent ca44e13 commit 1a63337
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
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
`
)

24 changes: 24 additions & 0 deletions internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2499,3 +2499,27 @@ func (r *DRPlacementControlReconciler) drpcHaveCommonClusters(ctx context.Contex

return drpolicyClusters.Intersection(otherDrpolicyClusters).Len() > 0, nil
}

//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")
drpcName := drpc.Spec.KubeObjectProtection.RecipeRef.Name
otherDrpcName := otherdrpc.Spec.KubeObjectProtection.RecipeRef.Name
if drpcName == rmnapi.VMRecipeName && otherDrpcName == rmnapi.VMRecipeName {

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

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: rmnapi

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

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: rmnapi

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

View workflow job for this annotation

GitHub Actions / Build image

undefined: rmnapi
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 {
log.Info("Its a valid Independent VM protection.")

return true
}
}

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

return false
}
9 changes: 8 additions & 1 deletion internal/controller/vrg_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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 @@ -116,7 +117,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 {

Check failure on line 122 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: rmnapi

Check failure on line 122 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: rmnapi

Check failure on line 122 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Build image

undefined: rmnapi
if err := yaml.Unmarshal([]byte(rmnapi.VMRecipe), &recipe); err != nil {

Check failure on line 123 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: yaml

Check failure on line 123 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: rmnapi

Check failure on line 123 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: yaml

Check failure on line 123 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Unit tests

undefined: rmnapi

Check failure on line 123 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Build image

undefined: yaml

Check failure on line 123 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Build image

undefined: rmnapi
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 1a63337

Please sign in to comment.