@@ -128,9 +128,9 @@ func (h *helm) Install(stringifedManifest string, info *types.InstallInfo, trans
128
128
"resource" , client .ObjectKeyFromObject (info .BaseResource ).String ())
129
129
130
130
// verify resources
131
- if ready , err := h .verifyResources (info .Ctx , resourceLists ,
132
- info . CheckReadyStates , types . OperationCreate ); ! ready || err != nil {
133
- return ready , err
131
+ if err := h .checkTargetResources (info .Ctx , resourceLists . Target ,
132
+ types . OperationCreate , info . CheckReadyStates ); err != nil {
133
+ return false , err
134
134
}
135
135
136
136
// update helm repositories
@@ -168,8 +168,8 @@ func (h *helm) Uninstall(stringifedManifest string, info *types.InstallInfo, tra
168
168
}
169
169
170
170
// uninstall resources
171
- _ , err = h .uninstallResources (resourceLists )
172
- if IgnoreHelmClientNotFound ( err ) != nil {
171
+ err = h .uninstallResources (resourceLists . Installed )
172
+ if err != nil {
173
173
return false , err
174
174
}
175
175
@@ -187,10 +187,10 @@ func (h *helm) Uninstall(stringifedManifest string, info *types.InstallInfo, tra
187
187
"resource" , client .ObjectKeyFromObject (info .BaseResource ).String ())
188
188
189
189
// verify resource uninstallation
190
- if ready , err := h .verifyResources (
191
- info .Ctx , resourceLists ,
192
- info .CheckReadyStates , types . OperationDelete ); ! ready || err != nil {
193
- return ready , err
190
+ if err := h .checkTargetResources (
191
+ info .Ctx , resourceLists . Target , types . OperationDelete ,
192
+ info .CheckReadyStates ); err != nil {
193
+ return false , err
194
194
}
195
195
196
196
// include CRDs means that the Chart will include the CRDs during rendering, if this is set to false,
@@ -219,12 +219,12 @@ func (h *helm) Uninstall(stringifedManifest string, info *types.InstallInfo, tra
219
219
return true , nil
220
220
}
221
221
222
- func IgnoreHelmClientNotFound (err error ) error {
222
+ func isHelmClientNotFound (err error ) bool {
223
223
// Refactoring this error check after this PR get merged and released https://github.com/helm/helm/pull/11591
224
224
if err != nil && strings .Contains (err .Error (), "object not found, skipping delete" ) {
225
- return nil
225
+ return true
226
226
}
227
- return err
227
+ return false
228
228
}
229
229
230
230
// uninstallChartCRDs uses a types.InstallInfo to lookup a chart and then tries to remove all CRDs found within it
@@ -244,23 +244,21 @@ func (h *helm) uninstallChartCRDs(info *types.InstallInfo) error {
244
244
if err != nil {
245
245
return err
246
246
}
247
- resList , err := h .getTargetResources (info .Ctx , crds .String (), nil , nil , false )
247
+ resourceList , err := h .getTargetResources (info .Ctx , crds .String (), nil , nil , false )
248
+ if resourceList == nil {
249
+ return nil
250
+ }
248
251
if err != nil {
249
252
return err
250
253
}
251
-
252
- _ , deleteErrs := h .clients .KubeClient ().Delete (resList )
253
- criticalDeleteErrs := make ([]error , 0 , len (deleteErrs ))
254
- for i := range deleteErrs {
255
- if deleteErrs [i ] != nil && ! apierrors .IsNotFound (deleteErrs [i ]) {
256
- criticalDeleteErrs = append (criticalDeleteErrs , deleteErrs [i ])
254
+ _ , deleteErrs := h .clients .KubeClient ().Delete (resourceList )
255
+ if len (deleteErrs ) > 0 {
256
+ filteredErrs := filterNotFoundError (deleteErrs )
257
+ if len (filteredErrs ) > 0 {
258
+ return types .NewMultiError (filteredErrs )
257
259
}
258
260
}
259
261
260
- if len (criticalDeleteErrs ) > 0 {
261
- return types .NewMultiError (criticalDeleteErrs )
262
- }
263
-
264
262
return nil
265
263
}
266
264
@@ -299,21 +297,21 @@ func (h *helm) IsConsistent(stringifedManifest string, info *types.InstallInfo,
299
297
}
300
298
301
299
// verify resources
302
- ready , err := h .verifyResources (info .Ctx , resourceLists , info .CheckReadyStates , types .OperationCreate )
300
+ if err := h .checkTargetResources (info .Ctx ,
301
+ resourceLists .Target ,
302
+ types .OperationCreate ,
303
+ info .CheckReadyStates ); err != nil {
304
+ return false , err
305
+ }
303
306
304
307
h .logger .V (util .DebugLogLevel ).Info ("consistency check finished" ,
305
- "consistent" , ready ,
306
308
"create count" , len (result .Created ),
307
309
"update count" , len (result .Updated ),
308
310
"chart" , info .ChartName ,
309
311
"release" , info .ReleaseName ,
310
312
"resource" , client .ObjectKeyFromObject (info .BaseResource ).String (),
311
313
"time" , time .Since (startConsistencyCheck ).String ())
312
314
313
- if ! ready || err != nil {
314
- return ready , err
315
- }
316
-
317
315
// update helm repositories
318
316
if info .UpdateRepositories {
319
317
if err = h .updateRepos (info .Ctx ); err != nil {
@@ -324,13 +322,6 @@ func (h *helm) IsConsistent(stringifedManifest string, info *types.InstallInfo,
324
322
return true , nil
325
323
}
326
324
327
- func (h * helm ) verifyResources (ctx context.Context , resourceLists types.ResourceLists , verifyReadyStates bool ,
328
- operationType types.HelmOperation ,
329
- ) (bool , error ) {
330
- return h .checkWaitForResources (ctx , resourceLists .GetWaitForResources (), operationType ,
331
- verifyReadyStates )
332
- }
333
-
334
325
func (h * helm ) installResources (resourceLists types.ResourceLists , force bool ) (* kube.Result , error ) {
335
326
// create namespace resource first!
336
327
if len (resourceLists .Namespace ) > 0 {
@@ -348,25 +339,35 @@ func (h *helm) installResources(resourceLists types.ResourceLists, force bool) (
348
339
return h .clients .KubeClient ().Update (resourceLists .Installed , resourceLists .Target , force )
349
340
}
350
341
351
- func (h * helm ) uninstallResources (resourceLists types.ResourceLists ) (* kube.Result , error ) {
352
- var response * kube.Result
353
- var delErrors []error
354
- if resourceLists .Installed != nil {
355
- response , delErrors = h .clients .KubeClient ().Delete (resourceLists .Installed )
356
- if len (delErrors ) > 0 {
357
- var wrappedError error
358
- for _ , err := range delErrors {
359
- wrappedError = fmt .Errorf ("%w" , err )
342
+ func (h * helm ) uninstallResources (installedResources kube.ResourceList ) error {
343
+ var deleteErrs []error
344
+ if installedResources != nil {
345
+ _ , deleteErrs = h .clients .KubeClient ().Delete (installedResources )
346
+ if len (deleteErrs ) > 0 {
347
+ filteredErrs := filterNotFoundError (deleteErrs )
348
+ if len (filteredErrs ) > 0 {
349
+ return types .NewMultiError (filteredErrs )
360
350
}
361
- return nil , wrappedError
362
351
}
363
352
}
364
- return response , nil
353
+ return nil
365
354
}
366
355
367
- func (h * helm ) checkWaitForResources (ctx context.Context , targetResources kube.ResourceList ,
368
- operation types.HelmOperation , verifyWithoutTimeout bool ,
369
- ) (bool , error ) {
356
+ func filterNotFoundError (delErrors []error ) []error {
357
+ wrappedErrors := make ([]error , 0 )
358
+ for _ , err := range delErrors {
359
+ if isHelmClientNotFound (err ) || apierrors .IsNotFound (err ) {
360
+ continue
361
+ }
362
+ wrappedErrors = append (wrappedErrors , err )
363
+ }
364
+ return wrappedErrors
365
+ }
366
+
367
+ func (h * helm ) checkTargetResources (ctx context.Context ,
368
+ targetResources kube.ResourceList ,
369
+ operation types.HelmOperation ,
370
+ verifyWithoutTimeout bool ) error {
370
371
// verifyWithoutTimeout flag checks native resources are in their respective ready states
371
372
// without a timeout defined
372
373
if verifyWithoutTimeout {
@@ -375,7 +376,7 @@ func (h *helm) checkWaitForResources(ctx context.Context, targetResources kube.R
375
376
}
376
377
clientSet , err := h .clients .KubernetesClientSet ()
377
378
if err != nil {
378
- return false , err
379
+ return err
379
380
}
380
381
readyChecker := kube .NewReadyChecker (clientSet ,
381
382
func (format string , args ... interface {}) {
@@ -390,20 +391,20 @@ func (h *helm) checkWaitForResources(ctx context.Context, targetResources kube.R
390
391
// if Wait or WaitForJobs is enabled, resources are verified to be in ready state with a timeout
391
392
if ! h .clients .Install ().Wait || h .clients .Install ().Timeout == 0 {
392
393
// return here as ready, since waiting flags were not set
393
- return true , nil
394
+ return nil
394
395
}
395
396
396
397
if operation == types .OperationDelete {
397
398
// WaitForDelete reports an error if resources are not deleted in the specified timeout
398
- return true , h .clients .KubeClient ().WaitForDelete (targetResources , h .clients .Install ().Timeout )
399
+ return h .clients .KubeClient ().WaitForDelete (targetResources , h .clients .Install ().Timeout )
399
400
}
400
401
401
402
if h .clients .Install ().WaitForJobs {
402
403
// WaitWithJobs reports an error if resources are not deleted in the specified timeout
403
- return true , h .clients .KubeClient ().WaitWithJobs (targetResources , h .clients .Install ().Timeout )
404
+ return h .clients .KubeClient ().WaitWithJobs (targetResources , h .clients .Install ().Timeout )
404
405
}
405
406
// Wait reports an error if resources are not deleted in the specified timeout
406
- return true , h .clients .KubeClient ().Wait (targetResources , h .clients .Install ().Timeout )
407
+ return h .clients .KubeClient ().Wait (targetResources , h .clients .Install ().Timeout )
407
408
}
408
409
409
410
func (h * helm ) updateRepos (ctx context.Context ) error {
0 commit comments