@@ -135,47 +135,12 @@ func undeployHelmCharts(ctx context.Context, c client.Client,
135
135
}
136
136
defer os .Remove (kubeconfig )
137
137
138
- chartManager , err := chartmanager .GetChartManagerInstance (ctx , c )
138
+ var releaseReports []configv1alpha1.ReleaseReport
139
+ releaseReports , err = uninstallHelmCharts (ctx , c , clusterSummary , kubeconfig , logger )
139
140
if err != nil {
140
141
return err
141
142
}
142
143
143
- releaseReports := make ([]configv1alpha1.ReleaseReport , 0 )
144
- for i := range clusterSummary .Spec .ClusterProfileSpec .HelmCharts {
145
- currentChart := & clusterSummary .Spec .ClusterProfileSpec .HelmCharts [i ]
146
- if chartManager .CanManageChart (clusterSummary , currentChart ) {
147
- logger .V (logs .LogInfo ).Info (fmt .Sprintf ("Uninstalling chart %s from repo %s %s)" ,
148
- currentChart .ChartName ,
149
- currentChart .RepositoryURL ,
150
- currentChart .RepositoryName ))
151
-
152
- // If another ClusterSummary is queued to manage this chart in this cluster, do not uninstall.
153
- // Let the other ClusterSummary take it over.
154
- if chartManager .GetNumberOfRegisteredClusterSummaries (clusterSummary .Spec .ClusterNamespace ,
155
- clusterSummary .Spec .ClusterName , currentChart ) > 1 {
156
- // Immediately unregister so next inline ClusterSummary can take this over
157
- chartManager .UnregisterClusterSummaryForChart (clusterSummary , currentChart )
158
- } else {
159
- err = doUninstallRelease (clusterSummary , currentChart , kubeconfig , logger )
160
- if err != nil {
161
- if ! errors .Is (err , driver .ErrReleaseNotFound ) {
162
- return err
163
- }
164
- }
165
- }
166
-
167
- releaseReports = append (releaseReports , configv1alpha1.ReleaseReport {
168
- ReleaseNamespace : currentChart .ReleaseNamespace , ReleaseName : currentChart .ReleaseName ,
169
- Action : string (configv1alpha1 .UninstallHelmAction ),
170
- })
171
- } else {
172
- releaseReports = append (releaseReports , configv1alpha1.ReleaseReport {
173
- ReleaseNamespace : currentChart .ReleaseNamespace , ReleaseName : currentChart .ReleaseName ,
174
- Action : string (configv1alpha1 .NoHelmAction ), Message : "Currently managed by another ClusterProfile" ,
175
- })
176
- }
177
- }
178
-
179
144
// First get the helm releases currently managed and uninstall all the ones
180
145
// not referenced anymore. Only if this operation succeeds, removes all stale
181
146
// helm release registration for this clusterSummary.
@@ -201,6 +166,11 @@ func undeployHelmCharts(ctx context.Context, c client.Client,
201
166
return err
202
167
}
203
168
169
+ chartManager , err := chartmanager .GetChartManagerInstance (ctx , c )
170
+ if err != nil {
171
+ return err
172
+ }
173
+
204
174
// In dry-run mode nothing gets deployed/undeployed. So if this instance used to manage
205
175
// an helm release and it is now not referencing anymore, do not unsubscribe.
206
176
if clusterSummary .Spec .ClusterProfileSpec .SyncMode != configv1alpha1 .SyncModeDryRun {
@@ -211,6 +181,60 @@ func undeployHelmCharts(ctx context.Context, c client.Client,
211
181
return & configv1alpha1.DryRunReconciliationError {}
212
182
}
213
183
184
+ func uninstallHelmCharts (ctx context.Context , c client.Client , clusterSummary * configv1alpha1.ClusterSummary ,
185
+ kubeconfig string , logger logr.Logger ) ([]configv1alpha1.ReleaseReport , error ) {
186
+
187
+ chartManager , err := chartmanager .GetChartManagerInstance (ctx , c )
188
+ if err != nil {
189
+ return nil , err
190
+ }
191
+
192
+ releaseReports := make ([]configv1alpha1.ReleaseReport , 0 )
193
+ for i := range clusterSummary .Spec .ClusterProfileSpec .HelmCharts {
194
+ currentChart := & clusterSummary .Spec .ClusterProfileSpec .HelmCharts [i ]
195
+ if chartManager .CanManageChart (clusterSummary , currentChart ) {
196
+ logger .V (logs .LogInfo ).Info (fmt .Sprintf ("Uninstalling chart %s from repo %s %s)" ,
197
+ currentChart .ChartName ,
198
+ currentChart .RepositoryURL ,
199
+ currentChart .RepositoryName ))
200
+
201
+ // If another ClusterSummary is queued to manage this chart in this cluster, do not uninstall.
202
+ // Let the other ClusterSummary take it over.
203
+ if chartManager .GetNumberOfRegisteredClusterSummaries (clusterSummary .Spec .ClusterNamespace ,
204
+ clusterSummary .Spec .ClusterName , currentChart ) > 1 {
205
+ // Immediately unregister so next inline ClusterSummary can take this over
206
+ chartManager .UnregisterClusterSummaryForChart (clusterSummary , currentChart )
207
+ } else {
208
+ // If StopMatchingBehavior is LeavePolicies, do not uninstall helm charts
209
+ if ! clusterSummary .DeletionTimestamp .IsZero () &&
210
+ clusterSummary .Spec .ClusterProfileSpec .StopMatchingBehavior == configv1alpha1 .LeavePolicies {
211
+
212
+ logger .V (logs .LogInfo ).Info ("ClusterProfile StopMatchingBehavior set to LeavePolicies" )
213
+ } else {
214
+ err = doUninstallRelease (clusterSummary , currentChart , kubeconfig , logger )
215
+ if err != nil {
216
+ if ! errors .Is (err , driver .ErrReleaseNotFound ) {
217
+ return nil , err
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ releaseReports = append (releaseReports , configv1alpha1.ReleaseReport {
224
+ ReleaseNamespace : currentChart .ReleaseNamespace , ReleaseName : currentChart .ReleaseName ,
225
+ Action : string (configv1alpha1 .UninstallHelmAction ),
226
+ })
227
+ } else {
228
+ releaseReports = append (releaseReports , configv1alpha1.ReleaseReport {
229
+ ReleaseNamespace : currentChart .ReleaseNamespace , ReleaseName : currentChart .ReleaseName ,
230
+ Action : string (configv1alpha1 .NoHelmAction ), Message : "Currently managed by another ClusterProfile" ,
231
+ })
232
+ }
233
+ }
234
+
235
+ return releaseReports , nil
236
+ }
237
+
214
238
func helmHash (ctx context.Context , c client.Client , clusterSummaryScope * scope.ClusterSummaryScope ,
215
239
logger logr.Logger ) ([]byte , error ) {
216
240
@@ -364,8 +388,13 @@ func handleUpgrade(ctx context.Context, clusterSummary *configv1alpha1.ClusterSu
364
388
if err != nil {
365
389
return nil , err
366
390
}
367
- message := fmt .Sprintf ("Current version: %s. Would move to version: %s" ,
368
- currentRelease .ChartVersion , currentChart .ChartVersion )
391
+ var message string
392
+ if currentRelease .ChartVersion != currentChart .ChartVersion {
393
+ message = fmt .Sprintf ("Current version: %s. Would move to version: %s" ,
394
+ currentRelease .ChartVersion , currentChart .ChartVersion )
395
+ } else {
396
+ message = fmt .Sprintf ("No op, already at version: %s" , currentRelease .ChartVersion )
397
+ }
369
398
report = & configv1alpha1.ReleaseReport {
370
399
ReleaseNamespace : currentChart .ReleaseNamespace , ReleaseName : currentChart .ReleaseName ,
371
400
ChartVersion : currentChart .ChartVersion , Action : string (configv1alpha1 .UpgradeHelmAction ),
0 commit comments