yonahd / kor

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

chore: find kor exceptions script #288

Closed doronkg closed 4 months ago

doronkg commented 4 months ago

What this PR does / why we need it?

This PR add a hack folder into kor, to include future useful scripts for contributors. It also includes the initial script find_exceptions.sh to discover false-positive default resources, the output of this script could be merged to pkg/kor/exceptions to be ignored by kor.

This script should be used in issues like #236, #240 for intsance.

Output Example ```console $ ./find_exceptions.sh Processing completed for ConfigMaps, output saved to exceptions/configmaps.json Processing completed for Secrets, output saved to exceptions/secrets.json Processing completed for ServiceAccounts, output saved to exceptions/serviceaccounts.json $ cat exceptions/configmaps.json { "exceptionConfigMaps": [ { "Namespace": "kube-system", "ResourceName": "bootstrap" }, { "Namespace": "kube-system", "ResourceName": "cluster-config-v1" }, { "Namespace": "kube-system", "ResourceName": "openshift-service-ca.crt" }, { "Namespace": "kube-system", "ResourceName": "root-ca" } ] } ```

PR Checklist

GitHub Issue

[XX-XX]

Notes for your reviewers

The find_exceptions.sh does not squash resources that appear in multiple namespaces, for example, if a ConfigMap is created in every namespace, the output will not display as so:

    {
      "Namespace": "*",
      "ResourceName": "kube-root-ca.crt"
    }

The script eases the process to map the default resources, but requires manual intervention (regex, merging, etc).

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 40.96%. Comparing base (852a6f9) to head (77155bc). Report is 1 commits behind head on main.

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #288 +/- ## ======================================= Coverage 40.96% 40.96% ======================================= Files 58 58 Lines 2910 2910 ======================================= Hits 1192 1192 Misses 1530 1530 Partials 188 188 ```

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

doronkg commented 4 months ago

Rebasing issues, I’ll re-submit it.

pbr0ck3r commented 4 months ago

We should add a way to sort the JSON (alphabetize it) as well.