From 06df89ce7b44073e996390b32374fc55bcbc06c1 Mon Sep 17 00:00:00 2001 From: Abhisek Dwivedi Date: Wed, 15 May 2024 11:01:52 +0530 Subject: [PATCH] Optimised isClusterReadinessEnabled flow --- controllers/poddistruptionbudget.go | 4 +++- controllers/reconciler.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/controllers/poddistruptionbudget.go b/controllers/poddistruptionbudget.go index a97e89057..684ad1bc4 100644 --- a/controllers/poddistruptionbudget.go +++ b/controllers/poddistruptionbudget.go @@ -63,7 +63,9 @@ func (r *SingleClusterReconciler) deletePDB() error { } func (r *SingleClusterReconciler) createOrUpdatePDB() error { - if !r.IsStatusEmpty() { + // Check for cluster readiness status only when it's false. + // Once enabled it won't be disabled. + if !r.IsStatusEmpty() && !r.aeroCluster.Status.IsClusterReadinessEnabled { clusterReadinessEnabled, err := r.getClusterReadinessStatus() if err != nil { return fmt.Errorf("failed to get cluster readiness status: %v", err) diff --git a/controllers/reconciler.go b/controllers/reconciler.go index fa7becdfe..ae511bb5d 100644 --- a/controllers/reconciler.go +++ b/controllers/reconciler.go @@ -417,12 +417,16 @@ func (r *SingleClusterReconciler) updateStatus() error { newAeroCluster.Status.AerospikeClusterStatusSpec = *specToStatus newAeroCluster.Status.Phase = asdbv1.AerospikeClusterCompleted - clusterReadinessEnable, err := r.getClusterReadinessStatus() - if err != nil { - return fmt.Errorf("failed to get cluster readiness status: %v", err) - } + // If IsClusterReadinessEnabled is not enabled, then only check for cluster readiness. + // This is to avoid checking cluster readiness for every reconcile as once it is enabled, it will not be disabled. + if !newAeroCluster.Status.IsClusterReadinessEnabled { + clusterReadinessEnable, gErr := r.getClusterReadinessStatus() + if gErr != nil { + return fmt.Errorf("failed to get cluster readiness status: %v", gErr) + } - newAeroCluster.Status.IsClusterReadinessEnabled = clusterReadinessEnable + newAeroCluster.Status.IsClusterReadinessEnabled = clusterReadinessEnable + } err = r.patchStatus(newAeroCluster) if err != nil {