diff --git a/controllers/drpolicy_controller.go b/controllers/drpolicy_controller.go index 47f2068b7..0ea56639d 100644 --- a/controllers/drpolicy_controller.go +++ b/controllers/drpolicy_controller.go @@ -69,7 +69,7 @@ const ReasonDRClustersUnavailable = "DRClustersUnavailable" // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.9.2/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") @@ -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) @@ -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, diff --git a/controllers/drpolicy_controller_test.go b/controllers/drpolicy_controller_test.go index 0b84ea39a..caef96de9 100644 --- a/controllers/drpolicy_controller_test.go +++ b/controllers/drpolicy_controller_test.go @@ -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)) } }