Skip to content

Commit d554a92

Browse files
committed
Record last handled reconcile at annotation
This makes it possible for e.g. the GOTK CLI to observe if the controller has handled the resource since the manual reconciliation request was made. It replaces the `LastObservedTime` status field, as this was prone to time skew issues and does not offer much additional value over the timestamps of the conditions.
1 parent a6e8e3d commit d554a92

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

api/v2alpha1/helmrelease_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,10 @@ type HelmReleaseStatus struct {
593593
// +optional
594594
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
595595

596-
// LastObservedTime is the last time at which the HelmRelease was observed.
596+
// LastHandledReconcileAt is the last manual reconciliation request (by
597+
// annotating the HelmRelease) handled by the reconciler.
597598
// +optional
598-
LastObservedTime metav1.Time `json:"lastObservedTime,omitempty"`
599+
LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"`
599600

600601
// Conditions holds the conditions for the HelmRelease.
601602
// +optional

api/v2alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,9 @@ spec:
453453
description: LastAttemptedValuesChecksum is the SHA1 checksum of the
454454
values of the last reconciliation attempt.
455455
type: string
456-
lastObservedTime:
457-
description: LastObservedTime is the last time at which the HelmRelease
458-
was observed.
459-
format: date-time
456+
lastHandledReconcileAt:
457+
description: LastHandledReconcileAt is the last manual reconciliation
458+
request (by annotating the HelmRelease) handled by the reconciler.
460459
type: string
461460
lastReleaseRevision:
462461
description: LastReleaseRevision is the revision of the last successful

controllers/helmrelease_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (r *HelmReleaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
126126
hr, result, err := r.reconcile(ctx, log, hr)
127127

128128
// Update status after reconciliation.
129-
if updateStatusErr := r.updateStatus(ctx, &hr); updateStatusErr != nil {
129+
if updateStatusErr := r.Status().Update(ctx, &hr); updateStatusErr != nil {
130130
log.Error(updateStatusErr, "unable to update status after reconciliation")
131131
return ctrl.Result{Requeue: true}, updateStatusErr
132132
}
@@ -142,11 +142,16 @@ func (r *HelmReleaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
142142
}
143143

144144
func (r *HelmReleaseReconciler) reconcile(ctx context.Context, log logr.Logger, hr v2.HelmRelease) (v2.HelmRelease, ctrl.Result, error) {
145+
// Record the value of the reconciliation request, if any
146+
if v, ok := hr.GetAnnotations()[consts.ReconcileAtAnnotation]; ok {
147+
hr.Status.LastHandledReconcileAt = v
148+
}
149+
145150
// Observe HelmRelease generation.
146151
if hr.Status.ObservedGeneration != hr.Generation {
147152
hr.Status.ObservedGeneration = hr.Generation
148153
hr = v2.HelmReleaseProgressing(hr)
149-
if updateStatusErr := r.updateStatus(ctx, &hr); updateStatusErr != nil {
154+
if updateStatusErr := r.Status().Update(ctx, &hr); updateStatusErr != nil {
150155
log.Error(updateStatusErr, "unable to update status after generation update")
151156
return hr, ctrl.Result{Requeue: true}, updateStatusErr
152157
}
@@ -294,7 +299,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, log logr.L
294299
hr, hasNewState := v2.HelmReleaseAttempted(hr, revision, releaseRevision, valuesChecksum)
295300
if hasNewState {
296301
hr = v2.HelmReleaseProgressing(hr)
297-
if updateStatusErr := r.updateStatus(ctx, &hr); updateStatusErr != nil {
302+
if updateStatusErr := r.Status().Update(ctx, &hr); updateStatusErr != nil {
298303
log.Error(updateStatusErr, "unable to update status after state update")
299304
return hr, updateStatusErr
300305
}
@@ -410,11 +415,6 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, log logr.L
410415
return v2.HelmReleaseReady(hr), nil
411416
}
412417

413-
func (r *HelmReleaseReconciler) updateStatus(ctx context.Context, hr *v2.HelmRelease) error {
414-
hr.Status.LastObservedTime = v1.Now()
415-
return r.Status().Update(ctx, hr)
416-
}
417-
418418
func (r *HelmReleaseReconciler) checkDependencies(hr v2.HelmRelease) error {
419419
for _, d := range hr.Spec.DependsOn {
420420
if d.Namespace == "" {

docs/api/helmrelease.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,16 +901,15 @@ int64
901901
</tr>
902902
<tr>
903903
<td>
904-
<code>lastObservedTime</code><br>
904+
<code>lastHandledReconcileAt</code><br>
905905
<em>
906-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#time-v1-meta">
907-
Kubernetes meta/v1.Time
908-
</a>
906+
string
909907
</em>
910908
</td>
911909
<td>
912910
<em>(Optional)</em>
913-
<p>LastObservedTime is the last time at which the HelmRelease was observed.</p>
911+
<p>LastHandledReconcileAt is the last manual reconciliation request (by
912+
annotating the HelmRelease) handled by the reconciler.</p>
914913
</td>
915914
</tr>
916915
<tr>

0 commit comments

Comments
 (0)