Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor some codes, add filter objects, and add support for lable filtering... #194

Merged
merged 3 commits into from Jan 31, 2024

Conversation

Forget-C
Copy link
Contributor

refactor&feat&fix&style:
1. Unify parameter types and divide them into two categories: normal parameters kor.Opts and filter parameters filters.Options.
2. includeExcludeLists no longer participates in cmd args binding, and is taken over by filters.Options.
3. The initialization operations of includeNamespace and excludeNamespace are taken over by filters.Options and will only be executed once.
4. Add filters.Framework object to uniformly process filtering logic.
5. All currently supported resources are supported by the kor/used=true tag.
6. Fix the problem that filterOptions.Validate does not take effect
7. Support includeable parameters

The unit tests have passed, but due to the large scope of the changes, more tests are needed.

1. Unify parameter types and divide them into two categories: normal parameters `kor.Opts` and filter parameters `filters.Options`.
2. `includeExcludeLists` no longer participates in `cmd args` binding, and is taken over by `filters.Options`.
3. The initialization operations of `includeNamespace` and `excludeNamespace` are taken over by `filters.Options` and will only be executed once.
4. Add filters.Framework object to uniformly process filtering logic.
5. All currently supported resources are supported by the `kor/used=true` tag.
6. Fix the problem that filterOptions.Validate does not take effect
7. Support includeable parameters

Signed-off-by: Extreme <1403539044@qq.com>
Signed-off-by: Extreme <1403539044@qq.com>
@Forget-C
Copy link
Contributor Author

The original purpose was to abstract the filter framework to facilitate the addition of filter parameters. Other changes are necessary to achieve this goal. #187
now, If we want to add a filter, we only need the following steps:

create filter func

// FilterFunc is a filter that is a function
// If the resource is legal, return true
// example:
// deployment.Spec.Replicas > 0; return true
// meta.GetLabels()["kor/used"] == "true"; return true
type FilterFunc func(object runtime.Object, opts *Options) bool
func TestFilter(object runtime.Object, opts *Options) bool {
	if meta, ok := object.(metav1.Object); ok {
		if meta.GetLabels()["kor/used"] == "true" {
			return true
		}
	}
	return false
}

Set a name

const  TestFilterName = "test"

Add to registry

func NewDefaultRegistry() Registry {
	return Registry{
		LabelFilterName:    LabelFilter,
		AgeFilterName:      AgeFilter,
		KorLabelFilterName: KorLabelFilter,
                TestFilterName: TestFilter,
	}
}

Signed-off-by: Extreme <1403539044@qq.com>
@codecov-commenter
Copy link

Codecov Report

Attention: 220 lines in your changes are missing coverage. Please review.

Comparison is base (1e391dd) 45.87% compared to head (69bc5c5) 44.43%.
Report is 1 commits behind head on main.

Files Patch % Lines
pkg/filters/options.go 0.00% 77 Missing ⚠️
pkg/filters/frameworks.go 0.00% 46 Missing ⚠️
pkg/filters/registry.go 0.00% 24 Missing ⚠️
pkg/kor/all.go 0.00% 20 Missing ⚠️
pkg/filters/filters.go 64.58% 12 Missing and 5 partials ⚠️
pkg/kor/crds.go 0.00% 6 Missing ⚠️
pkg/kor/multi.go 0.00% 5 Missing ⚠️
pkg/kor/exporter.go 0.00% 4 Missing ⚠️
pkg/kor/finalizers.go 33.33% 3 Missing and 1 partial ⚠️
pkg/kor/ingresses.go 71.42% 0 Missing and 2 partials ⚠️
... and 13 more

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #194      +/-   ##
==========================================
- Coverage   45.87%   44.43%   -1.45%     
==========================================
  Files          25       29       +4     
  Lines        2413     2444      +31     
==========================================
- Hits         1107     1086      -21     
- Misses       1122     1205      +83     
+ Partials      184      153      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@luisdavim luisdavim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, left a few comments in the code.

Thanks.

Copy link
Owner

@yonahd yonahd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved!
Thank you!

@yonahd yonahd merged commit 9bf9386 into yonahd:main Jan 31, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants