Skip to content

Commit 339e5ba

Browse files
authored
Fix the bug that the live resources are not filtered by the given selector. (#5763)
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
1 parent 9244032 commit 339e5ba

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/app/pipedv1/plugin/kubernetes/provider/liveresources.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,22 @@ import (
2424

2525
// GetLiveResources returns all live resources that belong to the given application.
2626
func 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

Comments
 (0)