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

Added ObservedGeneration to solrcloud status #722

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions api/v1beta1/solrcloud_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/crd/bases/solr.apache.org_solrclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion controllers/solrcloud_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -115,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
Expand Down Expand Up @@ -637,9 +661,16 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return requeueOrNot, err
}
}

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 {
defaultObservedGeneration := int64(0)
newStatus.ObservedGeneration = &defaultObservedGeneration
}
oldInstance := instance.DeepCopy()
instance.Status = newStatus
err = r.Status().Patch(ctx, instance, client.MergeFrom(oldInstance))
Expand Down
5 changes: 5 additions & 0 deletions helm/solr-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down