yonahd / kor

A Golang Tool to discover unused Kubernetes Resources
MIT License
1.04k stars 96 forks source link

fix(delete): Refactor input handling & output display on resource deletion #323

Closed doronkg closed 4 months ago

doronkg commented 4 months ago

What this PR does / why we need it?

This PR aims to resolve 2 outputing issues resulting in the --delete flag.

  1. Avoid the unexpected newline error on confirmation
  2. Append -DELETED suffix on deleted resources in output
$ .\main.exe clusterrole --delete
Do you want to delete ClusterRole aaa in namespace ? (Y/N): y
Deleting ClusterRole aaa in namespace
kor version: vdev

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

Unused resources in namespace: ""
+---+---------------+---------------+
| # | RESOURCE TYPE | RESOURCE NAME |
+---+---------------+---------------+
| 1 | ClusterRole   | aaa-DELETED   |
+---+---------------+---------------+

PR Checklist

GitHub Issue

Closes #321 Closes #322

Notes for your reviewers

321 is resolved by consuming the newline character ("\n") and removing it from the input buffer.

322 is resolved by moving the deletion logic before the grouping logic, so the updated diff variable will be used.

codecov-commenter commented 4 months ago

Codecov Report

Attention: Patch coverage is 1.63934% with 60 lines in your changes missing coverage. Please review.

Project coverage is 41.77%. Comparing base (ced2ef2) to head (9b0aaf1). Report is 2 commits behind head on main.

Files Patch % Lines
pkg/kor/clusterroles.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/configmaps.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/daemonsets.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/deployments.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/hpas.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/ingresses.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/jobs.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/networkpolicies.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/pdbs.go 0.00% 2 Missing and 1 partial :warning:
pkg/kor/pods.go 0.00% 2 Missing and 1 partial :warning:
... and 11 more

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #323 +/- ## ========================================== + Coverage 41.34% 41.77% +0.42% ========================================== Files 61 61 Lines 3212 3179 -33 ========================================== Hits 1328 1328 + Misses 1671 1637 -34 - Partials 213 214 +1 ```

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