Skip to content

Commit

Permalink
Merge pull request #94 from fluxcd/last-handled-reconcile-at
Browse files Browse the repository at this point in the history
Record last handled reconcile at annotation
  • Loading branch information
hiddeco authored Sep 29, 2020
2 parents a6e8e3d + d554a92 commit ddcbd1c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
5 changes: 3 additions & 2 deletions api/v2alpha1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,10 @@ type HelmReleaseStatus struct {
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

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

// Conditions holds the conditions for the HelmRelease.
// +optional
Expand Down
1 change: 0 additions & 1 deletion api/v2alpha1/zz_generated.deepcopy.go

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

7 changes: 3 additions & 4 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,9 @@ spec:
description: LastAttemptedValuesChecksum is the SHA1 checksum of the
values of the last reconciliation attempt.
type: string
lastObservedTime:
description: LastObservedTime is the last time at which the HelmRelease
was observed.
format: date-time
lastHandledReconcileAt:
description: LastHandledReconcileAt is the last manual reconciliation
request (by annotating the HelmRelease) handled by the reconciler.
type: string
lastReleaseRevision:
description: LastReleaseRevision is the revision of the last successful
Expand Down
16 changes: 8 additions & 8 deletions controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *HelmReleaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
hr, result, err := r.reconcile(ctx, log, hr)

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

func (r *HelmReleaseReconciler) reconcile(ctx context.Context, log logr.Logger, hr v2.HelmRelease) (v2.HelmRelease, ctrl.Result, error) {
// Record the value of the reconciliation request, if any
if v, ok := hr.GetAnnotations()[consts.ReconcileAtAnnotation]; ok {
hr.Status.LastHandledReconcileAt = v
}

// Observe HelmRelease generation.
if hr.Status.ObservedGeneration != hr.Generation {
hr.Status.ObservedGeneration = hr.Generation
hr = v2.HelmReleaseProgressing(hr)
if updateStatusErr := r.updateStatus(ctx, &hr); updateStatusErr != nil {
if updateStatusErr := r.Status().Update(ctx, &hr); updateStatusErr != nil {
log.Error(updateStatusErr, "unable to update status after generation update")
return hr, ctrl.Result{Requeue: true}, updateStatusErr
}
Expand Down Expand Up @@ -294,7 +299,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, log logr.L
hr, hasNewState := v2.HelmReleaseAttempted(hr, revision, releaseRevision, valuesChecksum)
if hasNewState {
hr = v2.HelmReleaseProgressing(hr)
if updateStatusErr := r.updateStatus(ctx, &hr); updateStatusErr != nil {
if updateStatusErr := r.Status().Update(ctx, &hr); updateStatusErr != nil {
log.Error(updateStatusErr, "unable to update status after state update")
return hr, updateStatusErr
}
Expand Down Expand Up @@ -410,11 +415,6 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, log logr.L
return v2.HelmReleaseReady(hr), nil
}

func (r *HelmReleaseReconciler) updateStatus(ctx context.Context, hr *v2.HelmRelease) error {
hr.Status.LastObservedTime = v1.Now()
return r.Status().Update(ctx, hr)
}

func (r *HelmReleaseReconciler) checkDependencies(hr v2.HelmRelease) error {
for _, d := range hr.Spec.DependsOn {
if d.Namespace == "" {
Expand Down
9 changes: 4 additions & 5 deletions docs/api/helmrelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -901,16 +901,15 @@ int64
</tr>
<tr>
<td>
<code>lastObservedTime</code><br>
<code>lastHandledReconcileAt</code><br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#time-v1-meta">
Kubernetes meta/v1.Time
</a>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>LastObservedTime is the last time at which the HelmRelease was observed.</p>
<p>LastHandledReconcileAt is the last manual reconciliation request (by
annotating the HelmRelease) handled by the reconciler.</p>
</td>
</tr>
<tr>
Expand Down

0 comments on commit ddcbd1c

Please sign in to comment.