@@ -417,15 +417,15 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
417
417
nodes := make ([]appv1.ResourceNode , 0 )
418
418
proj , err := ctrl .getAppProj (a )
419
419
if err != nil {
420
- return nil , err
420
+ return nil , fmt . Errorf ( "failed to get project: %w" , err )
421
421
}
422
422
423
423
orphanedNodesMap := make (map [kube.ResourceKey ]appv1.ResourceNode )
424
424
warnOrphaned := true
425
425
if proj .Spec .OrphanedResources != nil {
426
426
orphanedNodesMap , err = ctrl .stateCache .GetNamespaceTopLevelResources (a .Spec .Destination .Server , a .Spec .Destination .Namespace )
427
427
if err != nil {
428
- return nil , err
428
+ return nil , fmt . Errorf ( "failed to get namespace top-level resources: %w" , err )
429
429
}
430
430
warnOrphaned = proj .Spec .OrphanedResources .IsWarn ()
431
431
}
@@ -435,12 +435,12 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
435
435
var live = & unstructured.Unstructured {}
436
436
err := json .Unmarshal ([]byte (managedResource .LiveState ), & live )
437
437
if err != nil {
438
- return nil , err
438
+ return nil , fmt . Errorf ( "failed to unmarshal live state of managed resources: %w" , err )
439
439
}
440
440
var target = & unstructured.Unstructured {}
441
441
err = json .Unmarshal ([]byte (managedResource .TargetState ), & target )
442
442
if err != nil {
443
- return nil , err
443
+ return nil , fmt . Errorf ( "failed to unmarshal target state of managed resources: %w" , err )
444
444
}
445
445
446
446
if live == nil {
@@ -456,7 +456,11 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
456
456
} else {
457
457
err := ctrl .stateCache .IterateHierarchy (a .Spec .Destination .Server , kube .GetResourceKey (live ), func (child appv1.ResourceNode , appName string ) bool {
458
458
permitted , _ := proj .IsResourcePermitted (schema.GroupKind {Group : child .ResourceRef .Group , Kind : child .ResourceRef .Kind }, child .Namespace , a .Spec .Destination , func (project string ) ([]* appv1.Cluster , error ) {
459
- return ctrl .db .GetProjectClusters (context .TODO (), project )
459
+ clusters , err := ctrl .db .GetProjectClusters (context .TODO (), project )
460
+ if err != nil {
461
+ return nil , fmt .Errorf ("failed to get project clusters: %w" , err )
462
+ }
463
+ return clusters , nil
460
464
})
461
465
if ! permitted {
462
466
return false
@@ -465,7 +469,7 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
465
469
return true
466
470
})
467
471
if err != nil {
468
- return nil , err
472
+ return nil , fmt . Errorf ( "failed to iterate resource hierarchy: %w" , err )
469
473
}
470
474
}
471
475
}
@@ -514,7 +518,7 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
514
518
515
519
hosts , err := ctrl .getAppHosts (a , nodes )
516
520
if err != nil {
517
- return nil , err
521
+ return nil , fmt . Errorf ( "failed to get app hosts: %w" , err )
518
522
}
519
523
return & appv1.ApplicationTree {Nodes : nodes , OrphanedNodes : orphanedNodes , Hosts : hosts }, nil
520
524
}
0 commit comments