From df8e05f76f88fd3375857719edd18962f2b5055e Mon Sep 17 00:00:00 2001 From: Sean Eagan Date: Mon, 31 Aug 2020 13:22:10 -0500 Subject: [PATCH] Record last observed time in status This adds a .status.lastObservedTime field which records when the HelmRelease was last observed by the controller. This allows the user to observe whether the spec.interval and reconcileAt annotations are triggering reconciliation attempts as desired. --- api/v2alpha1/helmrelease_types.go | 14 +++++++++----- controllers/helmrelease_controller.go | 15 +++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/api/v2alpha1/helmrelease_types.go b/api/v2alpha1/helmrelease_types.go index 73210d0d6..9c7d8e55c 100644 --- a/api/v2alpha1/helmrelease_types.go +++ b/api/v2alpha1/helmrelease_types.go @@ -563,18 +563,22 @@ func (in Uninstall) GetTimeout(defaultTimeout metav1.Duration) metav1.Duration { // HelmReleaseStatus defines the observed state of HelmRelease type HelmReleaseStatus struct { - // ObservedGeneration is the last reconciled generation. + // ObservedGeneration is the last observed generation. // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` - // Conditions holds the conditions for the HelmRelease. - // +optional - Conditions []Condition `json:"conditions,omitempty"` - // ObservedStateReconciled represents whether the observed state has been successfully reconciled. // +optional ObservedStateReconciled bool `json:"observedStateReconciled,omitempty"` + // LastObservedTime is the last time at which the HelmRelease was observed. + // +optional + LastObservedTime metav1.Time `json:"lastObservedTime,omitempty"` + + // Conditions holds the conditions for the HelmRelease. + // +optional + Conditions []Condition `json:"conditions,omitempty"` + // LastAppliedRevision is the revision of the last successfully applied source. // +optional LastAppliedRevision string `json:"lastAppliedRevision,omitempty"` diff --git a/controllers/helmrelease_controller.go b/controllers/helmrelease_controller.go index 0d4b19384..c67c37010 100644 --- a/controllers/helmrelease_controller.go +++ b/controllers/helmrelease_controller.go @@ -125,6 +125,15 @@ func (r *HelmReleaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) return ctrl.Result{}, nil } + // Record time of reconciliation attempt. + hr.Status.LastObservedTime = v1.Now() + + // Observe HelmRelease generation. + if hr.Status.ObservedGeneration != hr.Generation { + hr.Status.ObservedGeneration = hr.Generation + hr = v2.HelmReleaseProgressing(hr) + } + if hr.Spec.Suspend { msg := "HelmRelease is suspended, skipping reconciliation" hr = v2.HelmReleaseNotReady(hr, v2.SuspendedReason, msg) @@ -136,12 +145,6 @@ func (r *HelmReleaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) return ctrl.Result{}, nil } - // Observe the HelmRelease generation. - if hr.Status.ObservedGeneration != hr.Generation { - hr.Status.ObservedGeneration = hr.Generation - hr = v2.HelmReleaseProgressing(hr) - } - if err := r.Status().Update(ctx, &hr); err != nil { log.Error(err, "unable to update status") return ctrl.Result{Requeue: true}, err