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

Conversation

doronkg
Copy link
Contributor

@doronkg doronkg commented Aug 19, 2024

What this PR does / why we need it?

This PR fixes output overriding when using multi mode and grouping by namespace (default!).
Assuming multiple unused resource types exist, only the last in the list will be displayed.

Regardless to the misfortunate output:

  • Grouping by resource works as expected for all resources
  • Deletion works as expected for all resources
Example
$ kor sa,cm -n kor --group-by=resource
kor version: vdev

  _  _____  ____
 | |/ / _ \|  _ \
 | ' / | | | |_) |
 | . \ |_| |  _ <
 |_|\_\___/|_| \_\

Unused ServiceAccounts:
+---+-----------+---------------+
| # | NAMESPACE | RESOURCE NAME |
+---+-----------+---------------+
| 1 | kor       | test          |
+---+-----------+---------------+

Unused ConfigMaps:
+---+-----------+---------------+
| # | NAMESPACE | RESOURCE NAME |
+---+-----------+---------------+
| 1 | kor       | test          |
+---+-----------+---------------+
Before fix
$ kor sa,cm -n kor --group-by=namespace
kor version: vdev

  _  _____  ____
 | |/ / _ \|  _ \
 | ' / | | | |_) |
 | . \ |_| |  _ <
 |_|\_\___/|_| \_\

Unused resources in namespace: "kor"
+---+---------------+---------------+
| # | RESOURCE TYPE | RESOURCE NAME |
+---+---------------+---------------+
| 1 | ConfigMap     | test          |
+---+---------------+---------------+
After fix
$ kor sa,cm -n kor --group-by=namespace
kor version: vdev

  _  _____  ____
 | |/ / _ \|  _ \
 | ' / | | | |_) |
 | . \ |_| |  _ <
 |_|\_\___/|_| \_\

Unused resources in namespace: "kor"
+---+----------------+---------------+
| # | RESOURCE TYPE  | RESOURCE NAME |
+---+----------------+---------------+
| 1 | ServiceAccount | test          |
| 2 | ConfigMap      | test          |
+---+----------------+---------------+

PR Checklist

  • This PR adds K8s exceptions (false positives)
  • This PR adds new code
  • This PR includes tests for new/existing code
  • This PR adds docs

GitHub Issue

Closes #348

Notes for your reviewers

The root cause relies in the diff loop, and is outsourced to the namespace loop in case that's the requested output mode.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 42.42%. Comparing base (c70a3ac) to head (f1c8cd0).
Report is 4 commits behind head on main.

Files Patch % Lines
pkg/kor/multi.go 0.00% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #349      +/-   ##
==========================================
- Coverage   42.45%   42.42%   -0.03%     
==========================================
  Files          61       61              
  Lines        3239     3241       +2     
==========================================
  Hits         1375     1375              
- Misses       1644     1646       +2     
  Partials      220      220              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@yonahd yonahd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yonahd yonahd merged commit 4d74db9 into yonahd:main Aug 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List of objects just returns results for last item in list
3 participants