@@ -24,19 +24,22 @@ import (
2424
2525// GetLiveResources returns all live resources that belong to the given application.
2626func GetLiveResources (ctx context.Context , kubectl * Kubectl , kubeconfig string , appID string , selector ... string ) (namespaceScoped []Manifest , clusterScoped []Manifest , _ error ) {
27- namespacedLiveResources , err := kubectl . GetAll ( ctx , kubeconfig ,
28- "" ,
27+ selectors := make ([] string , 0 , len ( selector ) + 2 )
28+ selectors = append ( selectors ,
2929 fmt .Sprintf ("%s=%s" , LabelManagedBy , ManagedByPiped ),
3030 fmt .Sprintf ("%s=%s" , LabelApplication , appID ),
3131 )
32+ if len (selector ) > 0 {
33+ selectors = append (selectors , selector ... )
34+ }
35+
36+ // pass empty namespace to get all namespace-scoped resources
37+ namespacedLiveResources , err := kubectl .GetAll (ctx , kubeconfig , "" , selectors ... )
3238 if err != nil {
3339 return nil , nil , fmt .Errorf ("failed while listing all namespace-scoped resources (%v)" , err )
3440 }
3541
36- clusterScopedLiveResources , err := kubectl .GetAllClusterScoped (ctx , kubeconfig ,
37- fmt .Sprintf ("%s=%s" , LabelManagedBy , ManagedByPiped ),
38- fmt .Sprintf ("%s=%s" , LabelApplication , appID ),
39- )
42+ clusterScopedLiveResources , err := kubectl .GetAllClusterScoped (ctx , kubeconfig , selectors ... )
4043 if err != nil {
4144 return nil , nil , fmt .Errorf ("failed while listing all cluster-scoped resources (%v)" , err )
4245 }
0 commit comments