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.
This commit is contained in:
Sean Eagan 2020-08-31 13:22:10 -05:00
parent fd7d23256a
commit 55f603806d
6 changed files with 54 additions and 25 deletions

View File

@ -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"`

View File

@ -207,6 +207,7 @@ func (in *HelmReleaseSpec) DeepCopy() *HelmReleaseSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmReleaseStatus) DeepCopyInto(out *HelmReleaseStatus) {
*out = *in
in.LastObservedTime.DeepCopyInto(&out.LastObservedTime)
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]Condition, len(*in))

View File

@ -409,12 +409,17 @@ 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
type: string
lastReleaseRevision:
description: LastReleaseRevision is the revision of the last successful
Helm release.
type: integer
observedGeneration:
description: ObservedGeneration is the last reconciled generation.
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
observedStateReconciled:

View File

@ -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

View File

@ -770,7 +770,33 @@ int64
</td>
<td>
<em>(Optional)</em>
<p>ObservedGeneration is the last reconciled generation.</p>
<p>ObservedGeneration is the last observed generation.</p>
</td>
</tr>
<tr>
<td>
<code>observedStateReconciled</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>ObservedStateReconciled represents whether the observed state has been successfully reconciled.</p>
</td>
</tr>
<tr>
<td>
<code>lastObservedTime</code><br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#time-v1-meta">
Kubernetes meta/v1.Time
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>LastObservedTime is the last time at which the HelmRelease was observed.</p>
</td>
</tr>
<tr>
@ -789,18 +815,6 @@ int64
</tr>
<tr>
<td>
<code>observedStateReconciled</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>ObservedStateReconciled represents whether the observed state has been successfully reconciled.</p>
</td>
</tr>
<tr>
<td>
<code>lastAppliedRevision</code><br>
<em>
string

View File

@ -674,6 +674,7 @@ status:
observedStateReconciled: true
lastAppliedRevision: 4.0.6
lastAttemptedRevision: 4.0.6
lastObservedTime: "2020-07-13T13:18:42Z"
lastReleaseRevision: 1
observedGeneration: 2
```
@ -704,6 +705,7 @@ status:
failures: 1
lastAppliedRevision: 4.0.6
lastAttemptedRevision: 4.0.6
lastObservedTime: "2020-07-13T18:17:28Z"
lastReleaseRevision: 1
observedGeneration: 3
```