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

⚠️ Allow configuring more granular cache filtering #2421

Merged
merged 1 commit into from Jul 28, 2023

Conversation

alvaroaleman
Copy link
Member

This change implements most of the cache options design, in particular it is now possible to:

What is still missing is to allow configuring namespace-level default settings that will be used for all namespaces not explicitly configured. There is nothing in the way of doing that as a follow-up.

The implementation slightly derivates from the design document in that the filter settings in ByGVK do not use the Config struct but instead are directly embedded. This allows us to not break compatibility and is more ergonomic to use.

The implementation is based on a new and internal per-type delegating "meta cache".

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 24, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2023
@alvaroaleman alvaroaleman removed the request for review from inteon July 24, 2023 22:29
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 24, 2023
@alvaroaleman alvaroaleman changed the title ✨ Allow configuring more granular cache filtering ⚠️ : Allow configuring more granular cache filtering Jul 24, 2023
@alvaroaleman alvaroaleman changed the title ⚠️ : Allow configuring more granular cache filtering ⚠️ Allow configuring more granular cache filtering Jul 24, 2023
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

First quick round of review

pkg/cache/internal/informers.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Very nice, just nits from my side

pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Outdated Show resolved Hide resolved
pkg/cache/delegate_by_type.go Outdated Show resolved Hide resolved
synced := true
for _, cache := range append(maps.Values(dbt.caches), dbt.defaultCache) {
if !cache.WaitForCacheSync(ctx) {
synced = false
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
synced = false
return false

Q: Would this make sense here?

If yes, we have a few more places where we could do the same (but maybe better in a separate PR)

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason it is the way that it is is that the interface is documented as "Blocks until caches are synced". If we return early, not all caches might be synced. I don't know if anyone would continue their binary if this returns false but odds are, someone somewhere will

Copy link
Member

Choose a reason for hiding this comment

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

Yeah let's better not change it. Was just thinking if we're hitting the case where some caches are definitely not synced we might as well return earlier. But no real reason to make a change

pkg/cache/delegate_by_type.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Show resolved Hide resolved
pkg/cache/defaulting_test.go Show resolved Hide resolved
This change implements most of the [cache options design][0], in
particular it is now possible to:
* Configure Namespaces per type
* Configure filtering per namespace

What is still missing is to allow configuring namespace-level default
settings that will be used for all namespaces not explicitly configured.
There is nothing in the way of doing that as a follow-up.

The implementation slightly derivates from the design document in that
the filter settings in `ByGVK` do not use the `Config` struct but
instead are directly embedded. This allows us to not break compatibility
and is more ergonomic to use.

The implementation is based on a new and internal per-type delegating
"meta cache".

[0]: https://github.com/kubernetes-sigs/controller-runtime/blob/main/designs/cache_options.md
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 26, 2023

@alvaroaleman: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-apidiff 3e35cab link false /test pull-controller-runtime-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@sbueringer
Copy link
Member

sbueringer commented Jul 28, 2023

Thx!

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache: Support multiple namespaces for just one type
3 participants