yonahd / kor

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

Fix: Add filters to replicasets #324

Closed yonahd closed 4 months ago

yonahd commented 4 months ago

What this PR does / why we need it?

This adds the filters to replicasets

PR Checklist

GitHub Issue

Closes #318

codecov-commenter commented 4 months ago

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 42.01%. Comparing base (bc2cca8) to head (fb7521c). Report is 1 commits behind head on main.

Files Patch % Lines
pkg/kor/finalizers.go 0.00% 0 Missing and 1 partial :warning:
pkg/kor/replicaset.go 0.00% 0 Missing and 1 partial :warning:

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #324 +/- ## ========================================== + Coverage 41.77% 42.01% +0.24% ========================================== Files 61 61 Lines 3179 3175 -4 ========================================== + Hits 1328 1334 +6 + Misses 1637 1633 -4 + Partials 214 208 -6 ```

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

doronkg commented 4 months ago

Following a quick grep it seems as ReplicaSets is not the only case where SetObject() function is missing:

$ grep -rn 'if pass, _ := filter.Run' pkg/kor/
pkg/kor/clusterroles.go:47:             if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/clusterroles.go:64:             if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/finalizers.go:50:                                       if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/ingresses.go:39:                if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/replicaset.go:25:               if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/roles.go:30:            if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/services.go:34:         if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/statefulsets.go:25:             if pass, _ := filter.Run(filterOpts); pass {
yonahd commented 4 months ago

Following a quick grep it seems as ReplicaSets is not the only case where SetObject() function is missing:

$ grep -rn 'if pass, _ := filter.Run' pkg/kor/
pkg/kor/clusterroles.go:47:             if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/clusterroles.go:64:             if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/finalizers.go:50:                                       if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/ingresses.go:39:                if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/replicaset.go:25:               if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/roles.go:30:            if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/services.go:34:         if pass, _ := filter.Run(filterOpts); pass {
pkg/kor/statefulsets.go:25:             if pass, _ := filter.Run(filterOpts); pass {

Good catch. I'll take care of all the references

yonahd commented 4 months ago

Removed the filter from areas in the code that are not referring to the actual resource. The filter logic should apply only to the actual resource and not to wether its orphaned or not