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

🐛 crs: use separate cache for partial metadata watches on secrets to include all secrets #10633

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

chrischdi
Copy link
Member

@chrischdi chrischdi commented May 16, 2024

What this PR does / why we need it:

This PR introduces a separate cache which is used in the clusterresourceset_controller for watching secrets.

Previously the WatchesMetadata for secrets in clusterresourcesset_controller did inherit the LabelSelector configured in main.go:

https://github.com/kubernetes-sigs/cluster-api/blob/main/main.go#L322-L329

This label selector gets passed through in controller-runtime for the informer which gets created for the watch.

Secrets for clusterresourcesets may apply for multiple clusters, so the label selector may not even exist at the secrets referred by clusterresourcesets.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #10557

/area clusterresourceset

@k8s-ci-robot k8s-ci-robot added area/clusterresourceset Issues or PRs related to clusterresourcesets cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 16, 2024
@chrischdi chrischdi changed the title 🐛 crs: use separate cache for partial metadata watches on secrets to in… 🐛 crs: use separate cache for partial metadata watches on secrets to include all secrets May 16, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from chrischdi. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@sbueringer
Copy link
Member

Very nice!

@chrischdi chrischdi force-pushed the pr-crs-watch-partial-all-secrets branch from 9fde0e2 to 4f90185 Compare May 21, 2024 08:48
@chrischdi chrischdi added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 21, 2024
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

@chrischdi can you please check the unit tests?

@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-main

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.

Just a few nits. Sorry for the nitpicking, just playing around a bit with generics and trying to find the simplest implementation

Otherwise all good, also tested it and it works perfectly (inspected the caches at runtime)

@chrischdi
Copy link
Member Author

/test pull-cluster-api-e2e-main

Comment on lines 193 to 195
// secretToExtensionConfigFunc returns a func which maps a secret to ExtensionConfigs with the corresponding
// InjectCAFromSecretAnnotation to reconcile them on updates of the secrets.
func (r *Reconciler) secretToExtensionConfigFunc(ctx context.Context, o *metav1.PartialObjectMetadata) []reconcile.Request {
Copy link
Member

Choose a reason for hiding this comment

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

Can we revert this (func name + godoc) entirely to what is on main? I think the godoc is not correct anymore (+ the func name is a bit inconsistent now with how we usually call these funcs)

@sbueringer
Copy link
Member

Last nit from my side

/assign @fabriziopandini

@chrischdi
Copy link
Member Author

/test pull-cluster-api-e2e-main

@sbueringer
Copy link
Member

Thank you very much!
/lgtm

Let's get some additional reviews if possible, just in case I'm missing something
/assign @fabriziopandini @vincepri

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: fd0b933f00763538f0332835600823f4a8a7933d

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

Nice change!

Comment on lines +449 to +443
// Setup a separate cache for the metadata watches to secrets.
// This way the watch does not use the LabelSelector defined at the cache which
// would filter to secrets having the cluster label, because secrets referred
// by ClusterResourceSet or ExtensionConfig are not specific to a single cluster.
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
// Setup a separate cache for the metadata watches to secrets.
// This way the watch does not use the LabelSelector defined at the cache which
// would filter to secrets having the cluster label, because secrets referred
// by ClusterResourceSet or ExtensionConfig are not specific to a single cluster.
// Setup a separate cache without label selector for secrets, to be used
// when we need to watch for secrets that are not specific to a single cluster (e.g. ClusterResourceSet or ExtensionConfig controllers).

// This way the watch does not use the LabelSelector defined at the cache which
// would filter to secrets having the cluster label, because secrets referred
// by ClusterResourceSet or ExtensionConfig are not specific to a single cluster.
partialSecretCache, err := cache.New(mgr.GetConfig(), cache.Options{
Copy link
Member

Choose a reason for hiding this comment

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

q: should this be allSecretCache instead of partialSecretCache (nothing in the definition points to partial)
q: is there a way to make sure this cache is used only for Secrets (I think not, but might be we can enforce this with a DefaultTransformerFunc that always returns error)
q: should we use TransformStripManagedFields for secrets? (not necessary, but it doesn't hurt)

cc @sbueringer

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 intention why I named it partialSecretCache is that we tend to only use it for PartialObjectMetadata watches/objects. Maybe I should add that information to the comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the idea of adding a DefaultTransformerFunc and implemented it.

This way we can make sure to not mis-use the cache 👍

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels May 30, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@chrischdi chrischdi force-pushed the pr-crs-watch-partial-all-secrets branch from 53006e4 to 1dd1d9e Compare May 31, 2024 09:05
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2024
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 31, 2024

@chrischdi: 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-cluster-api-apidiff-main 1dd1d9e link false /test pull-cluster-api-apidiff-main

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-sigs/prow repository. I understand the commands that are listed here.

@chrischdi
Copy link
Member Author

/test pull-cluster-api-e2e-main

@chrischdi
Copy link
Member Author

Cosmetics:

/override pull-cluster-api-apidiff-main

@k8s-ci-robot
Copy link
Contributor

@chrischdi: chrischdi unauthorized: /override is restricted to Repo administrators.

In response to this:

Cosmetics:

/override pull-cluster-api-apidiff-main

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-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clusterresourceset Issues or PRs related to clusterresourcesets cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CRS associated secret updates will not trigger CRS Reconcile
5 participants