diff --git a/api/v1beta1/solrcloud_types.go b/api/v1beta1/solrcloud_types.go index 995a9acd..8b83eb04 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,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/config/crd/bases/solr.apache.org_solrclouds.yaml b/config/crd/bases/solr.apache.org_solrclouds.yaml index 31733228..9dbd911e 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 diff --git a/controllers/solrcloud_controller.go b/controllers/solrcloud_controller.go index 9940ff9e..e81a2ac0 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") @@ -114,6 +116,27 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( requeueOrNot := reconcile.Result{} newStatus := solrv1beta1.SolrCloudStatus{} + var updateObservedGeneration bool + + // Update the observed generation if reconcile exits early due to an error, indicating no further progress can be made. + // 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 updateObservedGeneration == true { + 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 { @@ -638,8 +661,11 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } } + updateObservedGeneration = false + newStatus.ObservedGeneration = instance.Status.ObservedGeneration if !reflect.DeepEqual(instance.Status, newStatus) { logger.Info("Updating SolrCloud Status", "status", newStatus) + newStatus.ObservedGeneration = &reconcileGeneration oldInstance := instance.DeepCopy() instance.Status = newStatus err = r.Status().Patch(ctx, instance, client.MergeFrom(oldInstance)) diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index 14f285ca..4a9ab56c 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