feat(namespaces): add empty namespace detection and removal#249
feat(namespaces): add empty namespace detection and removal#249isindir wants to merge 13 commits intoyonahd:mainfrom
Conversation
|
fixes #92 This PR is still WIP, as it lacks parallel processing of the namespaces as well as unit tests, could you please review if in principle it is what you'd be happy to accept ? |
|
Hi @isindir, Take a look at https://github.com/yonahd/kor/blob/main/CONTRIBUTING.md#repository-structure. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #249 +/- ##
==========================================
+ Coverage 46.56% 47.53% +0.96%
==========================================
Files 69 71 +2
Lines 3930 4155 +225
==========================================
+ Hits 1830 1975 +145
- Misses 1794 1853 +59
- Partials 306 327 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This is definitely a good direction(this is not a simple one). |
Helm chart I think needs extra changes:
I'm looking to work on unit tests if time allows these weekends. |
07bc31c to
7246d82
Compare
Correct, currently the deployment is only used to export metrics, hence read-only RBAC, but we can consider going that way.
Interesting, especially when scanning unused resources in high-scaled clusters that might take more time than the interval set. We can continue with progress on both comments in separated issues/discussions (or in our Discord channel) as they are out-of-scope for this PR, but should be dippen into. I'd like to futher discuss them. Referring to https://github.com/yonahd/kor/blob/main/CONTRIBUTING.md#repository-structure was made to make sure you modify all required files, as adding any new unused resource support should address them. |
|
@doronkg ,
Thank you, I think I covered most of the files except helm chart and some unit tests, atm I'm trying to figure out if I can use fake clients to reliably test a feature I'm implementing. I deliberately left chart untouched as the change already looks very big. btw, for chart - it will be better to have fine-tuned RBAC - possibility to enable only those read/write/per namespace permissions per feature (resource). |
ac738c6 to
5b15ce6
Compare
|
@yonahd @luisdavim @doronkg, I finally found time and adding some more testing to the namespace removal - but I was not following if json configs with resources to skip from namespace evaluation for different k8s distros is fully implemented or not. Could you please suggest and review if my testing in |
The resource exceptions are merged fully. |
|
Let me know when this is ready for review. This is a massive pr and will take quite a while to review |
b6dd857 to
02a3f7e
Compare
|
@yonahd I feel that I'll not be able to do 100% unit test coverage for my new code, please review this PR. Thanks. |
d5d757e to
1f091da
Compare
|
@yonahd - I rebased the PR to the latest, would you have time to review and may be merge it ? We could negotiate next course of actions if needed from my side on a call, please reach me out on keybase , same uid as here. |
Thanks for the PR |
Hi, sorry for the late response. |
4d854e2 to
fecedb6
Compare
8e88467 to
e573053
Compare
e573053 to
3ab11ed
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds empty namespace detection functionality to the Kor tool. It introduces the ability to scan Kubernetes clusters for unused namespaces and optionally remove them based on specific criteria.
- Implements namespace scanning logic to identify empty or unused namespaces
- Adds comprehensive test coverage for namespace detection functionality
- Integrates namespace deletion capabilities into the existing resource deletion framework
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/kor/namespaces.go | Core namespace scanning and detection logic |
| pkg/kor/namespaces_test.go | Unit tests for helper functions (getGVR, ignoreResourceType) |
| pkg/kor/namespaces_IsNamespaceUsed_test.go | Comprehensive tests for namespace usage detection |
| pkg/kor/namespaces_GetUnusedNamespaces_test.go | Integration tests for the main namespace scanning function |
| pkg/kor/kor.go | Extended exception handling to support namespaced resources |
| pkg/kor/delete.go | Enhanced deletion logic to support namespaces and improved messaging |
| cmd/kor/namespaces.go | CLI command interface for namespace operations |
| pkg/filters/options.go | Added filtering options for resource types |
| pkg/kor/exceptions/ | Configuration files for namespace and resource exceptions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
3ab11ed to
d692d24
Compare
f95fb7f to
64a2936
Compare
64a2936 to
8c3e9f0
Compare
8c3e9f0 to
5ba3bd3
Compare
5ba3bd3 to
53eaddb
Compare
|
rebased |
35c9573 to
077fc2a
Compare
…e namespaced-resources.json
077fc2a to
39b8f79
Compare
What this PR does / why we need it?
This PR finds empty and non-default kubernetes namespaces, and if instructed removes these from the cluster.
PR Checklist
GitHub Issue
Closes [#92]
Notes for your reviewers