Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to support multiple DRPC in a NS for epic-6681 #1834

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
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 @@

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
Loading