Skip to content

Commit 902f75d

Browse files
committed
feat(api): expose HelmRelease failure state on Application status
Tenants usually read Applications but not the HelmReleases behind them, and only Ready and Released were copied over. A client could therefore see that a release was failing but not how often it had failed, nor whether helm-controller had stopped retrying it. Copy the Stalled condition, which helm-controller sets once it stops reconciling a release (remediation retries exhausted, rollback target missing, invalid CEL, access denied), and surface the install and upgrade failure counters with the last attempted release action. With the RetryOnFailure policy the platform generates today, a failing install or upgrade never stalls, so the counters are the signal; a release on a remediation policy stalls once its retries run out. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent e1e925a commit 902f75d

5 files changed

Lines changed: 172 additions & 2 deletions

File tree

‎pkg/apis/apps/v1alpha1/types.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ type ApplicationStatus struct {
5555
// ExternalIPsCount holds the number of LoadBalancer services with assigned external IPs for Tenant applications.
5656
// +optional
5757
ExternalIPsCount int32 `json:"externalIPsCount,omitempty"`
58+
// InstallFailures is the install failure count of the underlying HelmRelease.
59+
// It counts only attempts that recorded a Helm release, so a failure to
60+
// render or apply the chart shows only as Ready=False. It resets when the
61+
// desired state (generation, chart version, values) changes, and on success
62+
// only under the RetryOnFailure strategy, so a Ready release may carry it.
63+
// +optional
64+
InstallFailures int64 `json:"installFailures,omitempty"`
65+
// UpgradeFailures is the upgrade failure count of the underlying HelmRelease,
66+
// with the same counting and reset rules as InstallFailures.
67+
// +optional
68+
UpgradeFailures int64 `json:"upgradeFailures,omitempty"`
69+
// LastAttemptedReleaseAction is the last release action (install or upgrade)
70+
// the underlying HelmRelease attempted.
71+
// +optional
72+
LastAttemptedReleaseAction string `json:"lastAttemptedReleaseAction,omitempty"`
5873
}
5974

6075
// SchedulingClass returns the scheduling class requested by this Application.

‎pkg/generated/applyconfiguration/apps/v1alpha1/applicationstatus.go‎

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

‎pkg/generated/openapi/zz_generated.openapi.go‎

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

‎pkg/registry/apps/application/rest.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,13 +1573,16 @@ func (r *REST) convertHelmReleaseToApplication(ctx context.Context, hr *helmv2.H
15731573
},
15741574
Spec: filteredSpec,
15751575
Status: appsv1alpha1.ApplicationStatus{
1576-
Version: hr.Status.LastAttemptedRevision,
1576+
Version: hr.Status.LastAttemptedRevision,
1577+
InstallFailures: hr.Status.InstallFailures,
1578+
UpgradeFailures: hr.Status.UpgradeFailures,
1579+
LastAttemptedReleaseAction: string(hr.Status.LastAttemptedReleaseAction),
15771580
},
15781581
}
15791582

15801583
var conditions []metav1.Condition
15811584
for _, hrCondition := range hr.GetConditions() {
1582-
if hrCondition.Type == "Ready" || hrCondition.Type == "Released" {
1585+
if hrCondition.Type == "Ready" || hrCondition.Type == "Released" || hrCondition.Type == "Stalled" {
15831586
conditions = append(conditions, metav1.Condition{
15841587
LastTransitionTime: hrCondition.LastTransitionTime,
15851588
Reason: hrCondition.Reason,
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package application
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
helmv2 "github.com/fluxcd/helm-controller/api/v2"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
)
10+
11+
func TestConvertReleaseFailure_StalledAndCountersExposed(t *testing.T) {
12+
r := newTestRESTWithSchemes()
13+
hr := makeHelmRelease("postgresql-mydb", "default")
14+
hr.Status.Conditions = []metav1.Condition{
15+
{Type: "Stalled", Status: metav1.ConditionTrue, Reason: "RetriesExceeded", Message: "Failed to install after 1 attempt(s)"},
16+
{Type: "Ready", Status: metav1.ConditionFalse, Reason: "InstallFailed", Message: "install failed"},
17+
{Type: "Released", Status: metav1.ConditionFalse, Reason: "InstallFailed", Message: "install failed"},
18+
}
19+
hr.Status.Failures = 7
20+
hr.Status.InstallFailures = 1
21+
hr.Status.UpgradeFailures = 3
22+
hr.Status.LastAttemptedReleaseAction = helmv2.ReleaseActionInstall
23+
24+
app, err := r.convertHelmReleaseToApplication(context.TODO(), hr, nil)
25+
if err != nil {
26+
t.Fatalf("unexpected error: %v", err)
27+
}
28+
29+
sc := findCondition(app.GetConditions(), "Stalled")
30+
if sc == nil {
31+
t.Fatal("expected Stalled condition to be copied from the HelmRelease")
32+
}
33+
if sc.Status != metav1.ConditionTrue || sc.Reason != "RetriesExceeded" {
34+
t.Errorf("expected Stalled=True/RetriesExceeded, got %s/%s", sc.Status, sc.Reason)
35+
}
36+
if app.Status.InstallFailures != 1 {
37+
t.Errorf("expected installFailures=1, got %d", app.Status.InstallFailures)
38+
}
39+
if app.Status.UpgradeFailures != 3 {
40+
t.Errorf("expected upgradeFailures=3, got %d", app.Status.UpgradeFailures)
41+
}
42+
if app.Status.LastAttemptedReleaseAction != "install" {
43+
t.Errorf("expected lastAttemptedReleaseAction=install, got %q", app.Status.LastAttemptedReleaseAction)
44+
}
45+
}
46+
47+
// helm-controller clears the counters on success only under the RetryOnFailure
48+
// strategy, so a Ready release can still carry them; they must not be hidden.
49+
func TestConvertReleaseFailure_CountersKeptOnReadyRelease(t *testing.T) {
50+
r := newTestRESTWithSchemes()
51+
hr := makeHelmRelease("postgresql-mydb", "default")
52+
hr.Status.Conditions = []metav1.Condition{
53+
{Type: "Ready", Status: metav1.ConditionTrue, Reason: "UpgradeSucceeded", Message: "ok"},
54+
{Type: "Released", Status: metav1.ConditionTrue, Reason: "UpgradeSucceeded", Message: "ok"},
55+
}
56+
hr.Status.InstallFailures = 2
57+
hr.Status.UpgradeFailures = 1
58+
hr.Status.LastAttemptedReleaseAction = helmv2.ReleaseActionUpgrade
59+
60+
app, err := r.convertHelmReleaseToApplication(context.TODO(), hr, nil)
61+
if err != nil {
62+
t.Fatalf("unexpected error: %v", err)
63+
}
64+
65+
if findCondition(app.GetConditions(), "Stalled") != nil {
66+
t.Error("expected no Stalled condition on a release that does not carry one")
67+
}
68+
if app.Status.InstallFailures != 2 || app.Status.UpgradeFailures != 1 {
69+
t.Errorf("expected install=2 upgrade=1, got install=%d upgrade=%d", app.Status.InstallFailures, app.Status.UpgradeFailures)
70+
}
71+
if app.Status.LastAttemptedReleaseAction != "upgrade" {
72+
t.Errorf("expected lastAttemptedReleaseAction=upgrade, got %q", app.Status.LastAttemptedReleaseAction)
73+
}
74+
}
75+
76+
func TestConvertReleaseFailure_ReconcilingNotCopied(t *testing.T) {
77+
r := newTestRESTWithSchemes()
78+
hr := makeHelmRelease("postgresql-mydb", "default")
79+
hr.Status.Conditions = []metav1.Condition{
80+
{Type: "Reconciling", Status: metav1.ConditionTrue, Reason: "Progressing", Message: "Running 'install' action"},
81+
{Type: "Ready", Status: metav1.ConditionUnknown, Reason: "Progressing", Message: "Running 'install' action"},
82+
}
83+
84+
app, err := r.convertHelmReleaseToApplication(context.TODO(), hr, nil)
85+
if err != nil {
86+
t.Fatalf("unexpected error: %v", err)
87+
}
88+
89+
if findCondition(app.GetConditions(), "Reconciling") != nil {
90+
t.Error("expected Reconciling not to be copied")
91+
}
92+
if findCondition(app.GetConditions(), "Ready") == nil {
93+
t.Error("expected Ready to be copied")
94+
}
95+
}

0 commit comments

Comments
 (0)