From 6bd73fb6869369879e7580cf75e680778eadee26 Mon Sep 17 00:00:00 2001 From: RavinaChidambaram Date: Wed, 11 Sep 2024 11:46:36 +0530 Subject: [PATCH 1/3] Added ObservedGeneration to solrcloud status Signed-off-by: RavinaChidambaram --- api/v1beta1/solrcloud_types.go | 3 +++ config/crd/bases/solr.apache.org_solrclouds.yaml | 6 ++++++ controllers/solrcloud_controller.go | 3 +++ helm/solr-operator/crds/crds.yaml | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/api/v1beta1/solrcloud_types.go b/api/v1beta1/solrcloud_types.go index 995a9acd..0f840e95 100644 --- a/api/v1beta1/solrcloud_types.go +++ b/api/v1beta1/solrcloud_types.go @@ -1160,6 +1160,9 @@ type SolrCloudStatus struct { // BackupRepositoriesAvailable lists the backupRepositories specified in the SolrCloud and whether they are available across all Pods. // +optional BackupRepositoriesAvailable map[string]bool `json:"backupRepositoriesAvailable,omitempty"` + + // ObservedGeneration represents the most recent generation observed for this SolrCloud. + ObservedGeneration int64 `json:"observedGeneration"` } // SolrNodeStatus is the status of a solrNode in the cloud, with readiness status diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml b/config/crd/bases/solr.apache.org_solrclouds.yaml index 31733228..4b02199e 100644 --- a/config/crd/bases/solr.apache.org_solrclouds.yaml +++ b/config/crd/bases/solr.apache.org_solrclouds.yaml @@ -15873,6 +15873,11 @@ spec: description: InternalCommonAddress is the internal common http address for all solr nodes type: string + observedGeneration: + description: ObservedGeneration represents the most recent generation + observed for this SolrCloud. + format: int64 + type: integer podSelector: description: PodSelector for SolrCloud pods, required by the HPA type: string @@ -16017,6 +16022,7 @@ spec: type: object required: - internalCommonAddress + - observedGeneration - podSelector - readyReplicas - replicas diff --git a/controllers/solrcloud_controller.go b/controllers/solrcloud_controller.go index 9940ff9e..c5df492b 100644 --- a/controllers/solrcloud_controller.go +++ b/controllers/solrcloud_controller.go @@ -101,6 +101,8 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return reconcile.Result{}, err } + reconcileGeneration := instance.ObjectMeta.Generation + changed := instance.WithDefaults(logger) if changed { logger.Info("Setting default settings for SolrCloud") @@ -639,6 +641,7 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } if !reflect.DeepEqual(instance.Status, newStatus) { + newStatus.ObservedGeneration = reconcileGeneration logger.Info("Updating SolrCloud Status", "status", newStatus) oldInstance := instance.DeepCopy() instance.Status = newStatus diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index 14f285ca..a7fe7404 100644 --- a/helm/solr-operator/crds/crds.yaml +++ b/helm/solr-operator/crds/crds.yaml @@ -16134,6 +16134,11 @@ spec: description: InternalCommonAddress is the internal common http address for all solr nodes type: string + observedGeneration: + description: ObservedGeneration represents the most recent generation + observed for this SolrCloud. + format: int64 + type: integer podSelector: description: PodSelector for SolrCloud pods, required by the HPA type: string @@ -16278,6 +16283,7 @@ spec: type: object required: - internalCommonAddress + - observedGeneration - podSelector - readyReplicas - replicas From 07394644b7aa73cc9ca98be40aa7d9e845bdf833 Mon Sep 17 00:00:00 2001 From: RavinaChidambaram Date: Wed, 29 Jan 2025 10:41:07 +0000 Subject: [PATCH 2/3] Added ObservedGeneration to solrcloud status Signed-off-by: RavinaChidambaram --- api/v1beta1/solrcloud_types.go | 2 +- api/v1beta1/zz_generated.deepcopy.go | 5 +++++ controllers/solrcloud_controller.go | 32 ++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/api/v1beta1/solrcloud_types.go b/api/v1beta1/solrcloud_types.go index 0f840e95..8b83eb04 100644 --- a/api/v1beta1/solrcloud_types.go +++ b/api/v1beta1/solrcloud_types.go @@ -1162,7 +1162,7 @@ type SolrCloudStatus struct { BackupRepositoriesAvailable map[string]bool `json:"backupRepositoriesAvailable,omitempty"` // ObservedGeneration represents the most recent generation observed for this SolrCloud. - ObservedGeneration int64 `json:"observedGeneration"` + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` } // SolrNodeStatus is the status of a solrNode in the cloud, with readiness status diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 87e030ff..73e1fa03 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -972,6 +972,11 @@ func (in *SolrCloudStatus) DeepCopyInto(out *SolrCloudStatus) { (*out)[key] = val } } + if in.ObservedGeneration != nil { + in, out := &in.ObservedGeneration, &out.ObservedGeneration + *out = new(int64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SolrCloudStatus. diff --git a/controllers/solrcloud_controller.go b/controllers/solrcloud_controller.go index c5df492b..89ff4e58 100644 --- a/controllers/solrcloud_controller.go +++ b/controllers/solrcloud_controller.go @@ -117,6 +117,28 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( newStatus := solrv1beta1.SolrCloudStatus{} + // Updating ObservedGeneration after checking requeueOrNot to ensure that the operator has finished processing changes in spec, regardless of whether the reconciliation is successful or not. + // It simply indicates that the operator has tried all possible actions. + defer func () { + if instance.GetDeletionTimestamp() != nil || reflect.DeepEqual(instance.Status, solrv1beta1.SolrCloudStatus{}) { + logger.Info("Skipping ObservedGeneration update due to empty status or instance deletion") + return + } + if (instance.Status.ObservedGeneration == nil || *instance.Status.ObservedGeneration!=reconcileGeneration){ + if (!requeueOrNot.Requeue && requeueOrNot.RequeueAfter == 0){ + logger.Info("Updating Solrcloud Observed Generation") + oldinstance:= instance.DeepCopy() + instance.Status.ObservedGeneration = &reconcileGeneration + err := r.Status().Patch(ctx, instance, client.MergeFrom(oldinstance)) + if err != nil { + logger.Error(err, "Failed to patch ObservedGeneration") + } + } + + } + + }() + blockReconciliationOfStatefulSet := false if err = r.reconcileZk(ctx, logger, instance, &newStatus); err != nil { return requeueOrNot, err @@ -639,10 +661,16 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return requeueOrNot, err } } - if !reflect.DeepEqual(instance.Status, newStatus) { - newStatus.ObservedGeneration = reconcileGeneration logger.Info("Updating SolrCloud Status", "status", newStatus) + if !requeueOrNot.Requeue && requeueOrNot.RequeueAfter == 0{ + newStatus.ObservedGeneration = &reconcileGeneration + }else if newStatus.ObservedGeneration!=nil{ + newStatus.ObservedGeneration= instance.Status.ObservedGeneration + }else { + zero := int64(0) + newStatus.ObservedGeneration = &zero + } oldInstance := instance.DeepCopy() instance.Status = newStatus err = r.Status().Patch(ctx, instance, client.MergeFrom(oldInstance)) From 535057be0e250ea279caf1d1d5e6475d7b6654e3 Mon Sep 17 00:00:00 2001 From: RavinaChidambaram Date: Wed, 29 Jan 2025 12:12:49 +0000 Subject: [PATCH 3/3] Added ObservedGeneration to solrcloud status Signed-off-by: RavinaChidambaram --- .../crd/bases/solr.apache.org_solrclouds.yaml | 1 - controllers/solrcloud_controller.go | 32 +++++++++---------- helm/solr-operator/crds/crds.yaml | 1 - 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml b/config/crd/bases/solr.apache.org_solrclouds.yaml index 4b02199e..9dbd911e 100644 --- a/config/crd/bases/solr.apache.org_solrclouds.yaml +++ b/config/crd/bases/solr.apache.org_solrclouds.yaml @@ -16022,7 +16022,6 @@ spec: type: object required: - internalCommonAddress - - observedGeneration - podSelector - readyReplicas - replicas diff --git a/controllers/solrcloud_controller.go b/controllers/solrcloud_controller.go index 89ff4e58..a450f943 100644 --- a/controllers/solrcloud_controller.go +++ b/controllers/solrcloud_controller.go @@ -117,23 +117,23 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( newStatus := solrv1beta1.SolrCloudStatus{} - // Updating ObservedGeneration after checking requeueOrNot to ensure that the operator has finished processing changes in spec, regardless of whether the reconciliation is successful or not. + // Updating ObservedGeneration after checking requeueOrNot to ensure that the operator has finished processing changes in spec, regardless of whether the reconciliation is successful or not. // It simply indicates that the operator has tried all possible actions. - defer func () { + defer func() { if instance.GetDeletionTimestamp() != nil || reflect.DeepEqual(instance.Status, solrv1beta1.SolrCloudStatus{}) { - logger.Info("Skipping ObservedGeneration update due to empty status or instance deletion") - return - } - if (instance.Status.ObservedGeneration == nil || *instance.Status.ObservedGeneration!=reconcileGeneration){ - if (!requeueOrNot.Requeue && requeueOrNot.RequeueAfter == 0){ + logger.Info("Skipping ObservedGeneration update due to empty status or instance deletion") + return + } + if instance.Status.ObservedGeneration == nil || *instance.Status.ObservedGeneration != reconcileGeneration { + if !requeueOrNot.Requeue && requeueOrNot.RequeueAfter == 0 { logger.Info("Updating Solrcloud Observed Generation") - oldinstance:= instance.DeepCopy() + oldinstance := instance.DeepCopy() instance.Status.ObservedGeneration = &reconcileGeneration err := r.Status().Patch(ctx, instance, client.MergeFrom(oldinstance)) if err != nil { logger.Error(err, "Failed to patch ObservedGeneration") } - } + } } @@ -663,13 +663,13 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } if !reflect.DeepEqual(instance.Status, newStatus) { logger.Info("Updating SolrCloud Status", "status", newStatus) - if !requeueOrNot.Requeue && requeueOrNot.RequeueAfter == 0{ - newStatus.ObservedGeneration = &reconcileGeneration - }else if newStatus.ObservedGeneration!=nil{ - newStatus.ObservedGeneration= instance.Status.ObservedGeneration - }else { - zero := int64(0) - newStatus.ObservedGeneration = &zero + if !requeueOrNot.Requeue && requeueOrNot.RequeueAfter == 0 { + newStatus.ObservedGeneration = &reconcileGeneration + } else if newStatus.ObservedGeneration != nil { + newStatus.ObservedGeneration = instance.Status.ObservedGeneration + } else { + defaultObservedGeneration := int64(0) + newStatus.ObservedGeneration = &defaultObservedGeneration } oldInstance := instance.DeepCopy() instance.Status = newStatus diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index a7fe7404..4a9ab56c 100644 --- a/helm/solr-operator/crds/crds.yaml +++ b/helm/solr-operator/crds/crds.yaml @@ -16283,7 +16283,6 @@ spec: type: object required: - internalCommonAddress - - observedGeneration - podSelector - readyReplicas - replicas