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

drpolicy: validation of the drpolicy doesn't depend on cluster deploy #168

Draft
wants to merge 1 commit into
base: release-4.13
Choose a base branch
from
Draft
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
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)
}

schedulingIntervalSeconds, err := util.GetSecondsFromSchedulingInterval(drpolicy)
Expand All @@ -136,7 +149,7 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c

metric.DRPolicySyncInterval.Set(schedulingIntervalSeconds)

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
Loading