Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Multi output grouping by namespace #349

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/kor/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func GetUnusedMulti(resourceNames string, filterOpts *filters.Options, clientset
resources := make(map[string]map[string][]ResourceInfo)
var err error

if opts.GroupBy == "namespace" {
resources[""] = make(map[string][]ResourceInfo)
}

noNamespaceDiff, resourceList := retrieveNoNamespaceDiff(clientset, apiExtClient, dynamicClient, resourceList, filterOpts)
if len(noNamespaceDiff) != 0 {
for _, diff := range noNamespaceDiff {
Expand All @@ -114,7 +118,6 @@ func GetUnusedMulti(resourceNames string, filterOpts *filters.Options, clientset
}
switch opts.GroupBy {
case "namespace":
resources[""] = make(map[string][]ResourceInfo)
resources[""][diff.resourceType] = diff.diff
case "resource":
appendResources(resources, diff.resourceType, "", diff.diff)
Expand All @@ -125,6 +128,10 @@ func GetUnusedMulti(resourceNames string, filterOpts *filters.Options, clientset

for _, namespace := range namespaces {
allDiffs := retrieveNamespaceDiffs(clientset, namespace, resourceList, filterOpts)
if opts.GroupBy == "namespace" {
resources[namespace] = make(map[string][]ResourceInfo)
}

for _, diff := range allDiffs {
if opts.DeleteFlag {
if diff.diff, err = DeleteResource(diff.diff, clientset, namespace, diff.resourceType, opts.NoInteractive); err != nil {
Expand All @@ -133,7 +140,6 @@ func GetUnusedMulti(resourceNames string, filterOpts *filters.Options, clientset
}
switch opts.GroupBy {
case "namespace":
resources[namespace] = make(map[string][]ResourceInfo)
resources[namespace][diff.resourceType] = diff.diff
case "resource":
appendResources(resources, diff.resourceType, namespace, diff.diff)
Expand Down