yonahd / kor

A Golang Tool to discover unused Kubernetes Resources
MIT License
974 stars 91 forks source link

fix: Multi output grouping by namespace #349

Closed doronkg closed 1 month ago

doronkg commented 1 month ago

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:

Example ```console $ 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 ```console $ 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 ```console $ 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

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 commented 1 month ago

:warning: 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 :warning:

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.