api: add `LastAttemptedReleaseAction` to status

This can be used to reliable determine the active remediation strategy
which should be used. Including in edge cases where e.g. an uninstall
remediation is configured for upgrade failures.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This commit is contained in:
Hidde Beydals 2023-11-07 19:45:26 +01:00
parent 80d0878e96
commit 10277c7b26
No known key found for this signature in database
GPG Key ID: 979F380FC2341744
3 changed files with 54 additions and 3 deletions

View File

@ -827,6 +827,16 @@ func (in Uninstall) GetDeletionPropagation() string {
return *in.DeletionPropagation
}
// ReleaseAction is the action to perform a Helm release.
type ReleaseAction string
const (
// ReleaseActionInstall represents a Helm install action.
ReleaseActionInstall ReleaseAction = "install"
// ReleaseActionUpgrade represents a Helm upgrade action.
ReleaseActionUpgrade ReleaseAction = "upgrade"
)
// HelmReleaseStatus defines the observed state of a HelmRelease.
type HelmReleaseStatus struct {
// ObservedGeneration is the last observed generation.
@ -859,6 +869,12 @@ type HelmReleaseStatus struct {
// +optional
History ReleaseHistory `json:"history,omitempty"`
// LastAttemptedReleaseAction is the last release action performed for this
// HelmRelease. It is used to determine the active remediation strategy.
// +kubebuilder:validation:Enum=install;upgrade
// +optional
LastAttemptedReleaseAction ReleaseAction `json:"lastAttemptedReleaseAction,omitempty"`
// Failures is the reconciliation failure count against the latest desired
// state. It is reset after a successful reconciliation.
// +optional
@ -1019,12 +1035,17 @@ func (in HelmRelease) HasPrevious() bool {
return in.Status.History.Previous != nil
}
// GetActiveRemediation returns the active Remediation for the HelmRelease.
// GetActiveRemediation returns the active Remediation configuration for the
// HelmRelease.
func (in HelmRelease) GetActiveRemediation() Remediation {
if in.HasPrevious() {
switch in.Status.LastAttemptedReleaseAction {
case ReleaseActionInstall:
return in.GetInstall().GetRemediation()
case ReleaseActionUpgrade:
return in.GetUpgrade().GetRemediation()
default:
return nil
}
return in.GetInstall().GetRemediation()
}
// GetRequeueAfter returns the duration after which the HelmRelease

View File

@ -2002,6 +2002,14 @@ spec:
attempted to reconcile.
format: int64
type: integer
lastAttemptedReleaseAction:
description: LastAttemptedReleaseAction is the last release action
performed for this HelmRelease. It is used to determine the active
remediation strategy.
enum:
- install
- upgrade
type: string
lastAttemptedRevision:
description: LastAttemptedRevision is the Source revision of the last
reconciliation attempt.

View File

@ -1311,6 +1311,21 @@ ReleaseHistory
</tr>
<tr>
<td>
<code>lastAttemptedReleaseAction</code><br>
<em>
<a href="#helm.toolkit.fluxcd.io/v2beta2.ReleaseAction">
ReleaseAction
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>LastAttemptedReleaseAction is the last release action performed for this
HelmRelease. It is used to determine the active remediation strategy.</p>
</td>
</tr>
<tr>
<td>
<code>failures</code><br>
<em>
int64
@ -1754,6 +1769,13 @@ Kustomize
</table>
</div>
</div>
<h3 id="helm.toolkit.fluxcd.io/v2beta2.ReleaseAction">ReleaseAction
(<code>string</code> alias)</h3>
<p>
(<em>Appears on:</em>
<a href="#helm.toolkit.fluxcd.io/v2beta2.HelmReleaseStatus">HelmReleaseStatus</a>)
</p>
<p>ReleaseAction is the action to perform a Helm release.</p>
<h3 id="helm.toolkit.fluxcd.io/v2beta2.ReleaseHistory">ReleaseHistory
</h3>
<p>