@@ -1007,8 +1007,9 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
10071007
10081008 var report * configv1beta1.ReleaseReport
10091009 var currentRelease * releaseInfo
1010- currentRelease , report , err = handleChart (ctx , clusterSummary , mgmtResources , instantiatedChart , kubeconfig ,
1011- isPullMode , logger )
1010+ currentRelease , report , err = handleChart (ctx , clusterSummary , mgmtResources , instantiatedChart ,
1011+ kubeconfig , isPullMode , logger )
1012+ setHelmFailureMessageOnHelmChartSummary (clusterSummary , currentChart , err )
10121013 if err != nil {
10131014 if clusterSummary .Spec .ClusterProfileSpec .ContinueOnError {
10141015 errorMsg += fmt .Sprintf ("chart: %s, release: %s, %v\n " ,
@@ -1018,7 +1019,8 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
10181019 return releaseReports , chartDeployed , err
10191020 }
10201021
1021- valueHash , err := updateValueHashOnHelmChartSummary (ctx , instantiatedChart , clusterSummary , mgmtResources , logger )
1022+ valueHash , err := updateValueHashOnHelmChartSummary (ctx , instantiatedChart , clusterSummary , mgmtResources ,
1023+ logger )
10221024 if err != nil {
10231025 return releaseReports , chartDeployed , err
10241026 }
@@ -1032,10 +1034,12 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
10321034 valueHash , currentRelease .Status ))
10331035 } else {
10341036 logger .V (logs .LogInfo ).Info (fmt .Sprintf ("release %s/%s (version %s) status: %s" ,
1035- currentRelease .ReleaseNamespace , currentRelease .ReleaseName , currentRelease .ChartVersion , currentRelease .Status ))
1037+ currentRelease .ReleaseNamespace , currentRelease .ReleaseName , currentRelease .ChartVersion ,
1038+ currentRelease .Status ))
10361039 }
10371040 if currentRelease .Status == releasecommon .StatusDeployed .String () {
1038- // Deployed chart is used for updating ClusterConfiguration. There is no ClusterConfiguration for mgmt cluster
1041+ // Deployed chart is used for updating ClusterConfiguration. There is no ClusterConfiguration
1042+ // for mgmt cluster
10391043 chartDeployed = append (chartDeployed , configv1beta1.Chart {
10401044 RepoURL : instantiatedChart .RepositoryURL ,
10411045 Namespace : currentRelease .ReleaseNamespace ,
@@ -1065,6 +1069,59 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
10651069 return releaseReports , chartDeployed , nil
10661070}
10671071
1072+ func setHelmFailureMessageOnHelmChartSummary (clusterSummary * configv1beta1.ClusterSummary ,
1073+ instantiatedChart * configv1beta1.HelmChart , err error ) {
1074+
1075+ for i := range clusterSummary .Status .HelmReleaseSummaries {
1076+ hr := & clusterSummary .Status .HelmReleaseSummaries [i ]
1077+ if hr .ReleaseNamespace == instantiatedChart .ReleaseNamespace &&
1078+ hr .ReleaseName == instantiatedChart .ReleaseName {
1079+
1080+ if err == nil {
1081+ clusterSummary .Status .HelmReleaseSummaries [i ].FailureMessage = nil
1082+ } else {
1083+ failureMessage := err .Error ()
1084+ clusterSummary .Status .HelmReleaseSummaries [i ].FailureMessage = & failureMessage
1085+ }
1086+ return
1087+ }
1088+ }
1089+ }
1090+
1091+ // getFailureMessageFromHelmChartSummary returns the failureMessage stored for this chart
1092+ // in the ClusterSummary
1093+ func getFailureMessageFromHelmChartSummary (requestedChart * configv1beta1.HelmChart ,
1094+ clusterSummary * configv1beta1.ClusterSummary ) * string {
1095+
1096+ for i := range clusterSummary .Status .HelmReleaseSummaries {
1097+ rs := & clusterSummary .Status .HelmReleaseSummaries [i ]
1098+ if rs .ReleaseName == requestedChart .ReleaseName &&
1099+ rs .ReleaseNamespace == requestedChart .ReleaseNamespace {
1100+
1101+ return rs .FailureMessage
1102+ }
1103+ }
1104+
1105+ return nil
1106+ }
1107+
1108+ // getValueHashFromHelmChartSummary returns the valueHash stored for this chart
1109+ // in the ClusterSummary
1110+ func getValueHashFromHelmChartSummary (requestedChart * configv1beta1.HelmChart ,
1111+ clusterSummary * configv1beta1.ClusterSummary ) []byte {
1112+
1113+ for i := range clusterSummary .Status .HelmReleaseSummaries {
1114+ rs := & clusterSummary .Status .HelmReleaseSummaries [i ]
1115+ if rs .ReleaseName == requestedChart .ReleaseName &&
1116+ rs .ReleaseNamespace == requestedChart .ReleaseNamespace {
1117+
1118+ return rs .ValuesHash
1119+ }
1120+ }
1121+
1122+ return nil
1123+ }
1124+
10681125func generateConflictForHelmChart (ctx context.Context , clusterSummary * configv1beta1.ClusterSummary ,
10691126 instantiatedChart * configv1beta1.HelmChart ) string {
10701127
@@ -1553,10 +1610,10 @@ func installRelease(ctx context.Context, clusterSummary *configv1beta1.ClusterSu
15531610 // This condition should never occur. A previous check ensures that only one
15541611 // ClusterProfile/Profile can manage a Helm Chart with a given name in a
15551612 // specific namespace within a managed cluster. If this code is reached,
1556- // that check has already passed. Therefore, the "cannot re-use a name that
1613+ // that check has already passed. Therefore, the "cannot reuse a name that
15571614 // is still in use" error should be impossible.
15581615 // There is no constant defined in the helm library but this is an error seen more than once.
1559- if err .Error () == "cannot re-use a name that is still in use" {
1616+ if strings . Contains ( err .Error (), "cannot reuse a name that is still in use" ) {
15601617 _ , err = upgradeRelease (ctx , clusterSummary , settings , requestedChart , kubeconfig , registryOptions ,
15611618 values , mgmtResources , logger )
15621619 return nil , err
@@ -2529,6 +2586,7 @@ func updateStatusForReferencedHelmReleases(ctx context.Context, c client.Client,
25292586 ReleaseName : instantiatedChart .ReleaseName ,
25302587 ReleaseNamespace : instantiatedChart .ReleaseNamespace ,
25312588 Status : configv1beta1 .HelmChartStatusManaging ,
2589+ FailureMessage : getFailureMessageFromHelmChartSummary (instantiatedChart , clusterSummary ),
25322590 ValuesHash : getValueHashFromHelmChartSummary (instantiatedChart , clusterSummary ), // if a value is currently stored, keep it.
25332591 // after chart is deployed such value will be updated
25342592 }
@@ -2596,26 +2654,21 @@ func updateStatusForNonReferencedHelmReleases(ctx context.Context, c client.Clie
25962654 currentlyReferenced [helmInfo (instantiatedChart .ReleaseNamespace , instantiatedChart .ReleaseName )] = true
25972655 }
25982656
2599- helmReleaseSummaries := make ([]configv1beta1.HelmChartSummary , 0 , len (clusterSummary .Status .HelmReleaseSummaries ))
2600- for i := range clusterSummary .Status .HelmReleaseSummaries {
2601- summary := & clusterSummary .Status .HelmReleaseSummaries [i ]
2602- if _ , ok := currentlyReferenced [helmInfo (summary .ReleaseNamespace , summary .ReleaseName )]; ok {
2603- helmReleaseSummaries = append (helmReleaseSummaries , * summary )
2604- }
2605- }
2606-
2607- if len (helmReleaseSummaries ) == len (clusterSummary .Status .HelmReleaseSummaries ) {
2608- // Nothing has changed
2609- return clusterSummary , nil
2610- }
2611-
26122657 currentClusterSummary := & configv1beta1.ClusterSummary {}
26132658 err := c .Get (ctx ,
26142659 types.NamespacedName {Namespace : clusterSummary .Namespace , Name : clusterSummary .Name }, currentClusterSummary )
26152660 if err != nil {
26162661 return clusterSummary , err
26172662 }
26182663
2664+ helmReleaseSummaries := make ([]configv1beta1.HelmChartSummary , 0 , len (currentClusterSummary .Status .HelmReleaseSummaries ))
2665+ for i := range currentClusterSummary .Status .HelmReleaseSummaries {
2666+ summary := & currentClusterSummary .Status .HelmReleaseSummaries [i ]
2667+ if _ , ok := currentlyReferenced [helmInfo (summary .ReleaseNamespace , summary .ReleaseName )]; ok {
2668+ helmReleaseSummaries = append (helmReleaseSummaries , * summary )
2669+ }
2670+ }
2671+
26192672 currentClusterSummary .Status .HelmReleaseSummaries = helmReleaseSummaries
26202673
26212674 err = c .Status ().Update (ctx , currentClusterSummary )
@@ -3815,23 +3868,6 @@ func updateValueHashOnHelmChartSummary(ctx context.Context, requestedChart *conf
38153868 return helmChartValuesHash , err
38163869}
38173870
3818- // getValueHashFromHelmChartSummary returns the valueHash stored for this chart
3819- // in the ClusterSummary
3820- func getValueHashFromHelmChartSummary (requestedChart * configv1beta1.HelmChart ,
3821- clusterSummary * configv1beta1.ClusterSummary ) []byte {
3822-
3823- for i := range clusterSummary .Status .HelmReleaseSummaries {
3824- rs := & clusterSummary .Status .HelmReleaseSummaries [i ]
3825- if rs .ReleaseName == requestedChart .ReleaseName &&
3826- rs .ReleaseNamespace == requestedChart .ReleaseNamespace {
3827-
3828- return rs .ValuesHash
3829- }
3830- }
3831-
3832- return nil
3833- }
3834-
38353871func getCredentialsAndCAFiles (ctx context.Context , c client.Client , clusterSummary * configv1beta1.ClusterSummary ,
38363872 requestedChart * configv1beta1.HelmChart ) (credentialsPath , caPath string , err error ) {
38373873
0 commit comments