Skip to content

Commit

Permalink
drpolicy: validation of the drpolicy doesn't depend on cluster deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur authored and ShyamsundarR committed Oct 6, 2023
1 parent e5cede5 commit 579c08e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
19 changes: 16 additions & 3 deletions controllers/drpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const ReasonDRClustersUnavailable = "DRClustersUnavailable"
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
//
//nolint:cyclop,funlen
//nolint:cyclop
func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("DRPolicy", req.NamespacedName.Name, "rid", uuid.New())
log.Info("reconcile enter")
Expand Down Expand Up @@ -120,8 +120,21 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, fmt.Errorf("finalizer add update: %w", u.validatedSetFalse("FinalizerAddFailed", err))
}

if err := u.validatedSetTrue("Succeeded", "drpolicy validated"); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to set drpolicy validation: %w", err)
}

return r.reconcile(drpolicy, drclusters, secretsUtil, ramenConfig, log)
}

func (r *DRPolicyReconciler) reconcile(drpolicy *ramen.DRPolicy,
drclusters *ramen.DRClusterList,
secretsUtil *util.SecretsUtil,
ramenConfig *ramen.RamenConfig,
log logr.Logger,
) (ctrl.Result, error) {
if err := drPolicyDeploy(drpolicy, drclusters, secretsUtil, ramenConfig, log); err != nil {
return ctrl.Result{}, fmt.Errorf("drpolicy deploy: %w", u.validatedSetFalse("DrClustersDeployFailed", err))
return ctrl.Result{}, fmt.Errorf("drpolicy deploy: %w", err)
}

isMetro, _ := dRPolicySupportsMetro(drpolicy, drclusters.Items)
Expand All @@ -133,7 +146,7 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}
}

return ctrl.Result{}, u.validatedSetTrue("Succeeded", "drpolicy validated")
return ctrl.Result{}, nil
}

func validateDRPolicy(ctx context.Context,
Expand Down
11 changes: 8 additions & 3 deletions controllers/drpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,24 @@ var _ = Describe("DrpolicyController", func() {
}

// Ensure list of secrets for the policy name has as many placement rules
Expect(len(plRules)).To(Equal(len(drPoliciesAndSecrets[policyCombinationName])))
Eventually(func() bool {
plRules = getPlRuleForSecrets()

return len(plRules) == len(drPoliciesAndSecrets[policyCombinationName])
}, timeout, interval).Should(BeTrue())

// Range through secrets in drpolicies name and ensure cluster list is the same
for secretName, clusterList := range drPoliciesAndSecrets[policyCombinationName] {
_, _, plRuleName, _ := util.GeneratePolicyResourceNames(secretName)

Expect(func() (clusterNames []string) {
Eventually(func() (clusterNames []string) {
plRules = getPlRuleForSecrets()
for _, cluster := range plRules[plRuleName].Spec.Clusters {
clusterNames = append(clusterNames, cluster.Name)
}

return
}()).To(ConsistOf(clusterList))
}(), timeout, interval).Should(ConsistOf(clusterList))
}
}

Expand Down

0 comments on commit 579c08e

Please sign in to comment.