Skip to content

Commit 405dcf1

Browse files
committed
(bug) Fix HelmReleaseSummary.FailureMessage never persisted after chart deployment failure
When a Helm chart deployment fails, setHelmFailureMessageOnHelmChartSummary correctly sets FailureMessage on clusterSummary.Status.HelmReleaseSummaries[i] in memory, but this value was never written back to the API server. The root cause is a sequencing issue: updateStatusForReferencedHelmReleases (which persists HelmReleaseSummaries) runs before walkChartsAndDeploy. After walkChartsAndDeploy fails and sets the FailureMessage in memory, updateStatusForNonReferencedHelmReleases then re-fetches a fresh ClusterSummary from the API and overwrites the status, so discarding the in-memory change entirely. As a result, HelmReleaseSummaries[].FailureMessage always remained empty even after repeated failures, while featureSummaries[].failureMessage (set through a separate path) correctly reflected the error. A secondary bug: setHelmFailureMessageOnHelmChartSummary was passed currentChart (the raw, pre-template spec) instead of instantiatedChart. The lookup compares ReleaseName/ReleaseNamespace against values stored in HelmReleaseSummaries, which are the instantiated values. When those fields contain Go templates, the lookup would silently find no match and the FailureMessage would not be set at all. Fix consist in: 1. Pass instantiatedChart (post-template) instead of currentChart to setHelmFailureMessageOnHelmChartSummary so the lookup always matches what is stored in HelmReleaseSummaries. 2. In updateStatusForNonReferencedHelmReleases, before overwriting the status with the freshly fetched ClusterSummary, build an index of the in-memory FailureMessage values set by walkChartsAndDeploy and merge them into the entries being written. This ensures the failure from the current reconciliation round is persisted to the API.
1 parent cb914ec commit 405dcf1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

controllers/handlers_helm.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
10091009
var currentRelease *releaseInfo
10101010
currentRelease, report, err = handleChart(ctx, clusterSummary, mgmtResources, instantiatedChart,
10111011
kubeconfig, isPullMode, logger)
1012-
setHelmFailureMessageOnHelmChartSummary(clusterSummary, currentChart, err)
1012+
setHelmFailureMessageOnHelmChartSummary(clusterSummary, instantiatedChart, err)
10131013
if err != nil {
10141014
if clusterSummary.Spec.ClusterProfileSpec.ContinueOnError {
10151015
errorMsg += fmt.Sprintf("chart: %s, release: %s, %v\n",
@@ -2729,11 +2729,23 @@ func updateStatusForNonReferencedHelmReleases(ctx context.Context, c client.Clie
27292729
return clusterSummary, err
27302730
}
27312731

2732+
// Index the in-memory FailureMessages written by walkChartsAndDeploy so they are
2733+
// not lost when we overwrite the status from the freshly fetched currentClusterSummary.
2734+
inMemoryFailure := make(map[string]*string, len(clusterSummary.Status.HelmReleaseSummaries))
2735+
for i := range clusterSummary.Status.HelmReleaseSummaries {
2736+
s := &clusterSummary.Status.HelmReleaseSummaries[i]
2737+
inMemoryFailure[helmInfo(s.ReleaseNamespace, s.ReleaseName)] = s.FailureMessage
2738+
}
2739+
27322740
helmReleaseSummaries := make([]configv1beta1.HelmChartSummary, 0, len(currentClusterSummary.Status.HelmReleaseSummaries))
27332741
for i := range currentClusterSummary.Status.HelmReleaseSummaries {
27342742
summary := &currentClusterSummary.Status.HelmReleaseSummaries[i]
27352743
if _, ok := currentlyReferenced[helmInfo(summary.ReleaseNamespace, summary.ReleaseName)]; ok {
2736-
helmReleaseSummaries = append(helmReleaseSummaries, *summary)
2744+
entry := *summary
2745+
if msg, exists := inMemoryFailure[helmInfo(summary.ReleaseNamespace, summary.ReleaseName)]; exists {
2746+
entry.FailureMessage = msg
2747+
}
2748+
helmReleaseSummaries = append(helmReleaseSummaries, entry)
27372749
}
27382750
}
27392751

0 commit comments

Comments
 (0)