Skip to content

📖 Add more docs to SyncPeriod #3269

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

Merged

Conversation

guettli
Copy link
Contributor

@guettli guettli commented Aug 8, 2025

SyncPeriod is likely to get ignored if you use a predicate.

This PR updates the docs to make this more obvious.

Quoting Stefan Büringer

The behavior described is expected and not a bug.
Every SyncPeriod the underlying informers will emit events to trigger reconciliation of all objects. But if there are predicates configured that filter out those events, accordingly the Reconcile func won't be executed.

Related: SyncPeriod does not work if controller is created WithEventFilter(predicate.GenerationChangedPredicate{}) · Issue #2355 · kubernetes-sigs/controller-runtime

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

Hi @guettli. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 8, 2025
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 8, 2025
@guettli guettli force-pushed the tg/add-more-docs-to-syncPeriod branch from 7617cb7 to b8634e5 Compare August 8, 2025 13:00
@guettli guettli force-pushed the tg/add-more-docs-to-syncPeriod branch from b8634e5 to 1ba19c0 Compare August 8, 2025 14:27
@guettli guettli force-pushed the tg/add-more-docs-to-syncPeriod branch from 536b991 to 8a14d92 Compare August 11, 2025 07:31
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 11, 2025
@guettli guettli force-pushed the tg/add-more-docs-to-syncPeriod branch from 8a14d92 to e22988f Compare August 11, 2025 07:31
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 11, 2025
@guettli guettli force-pushed the tg/add-more-docs-to-syncPeriod branch from e22988f to dd7366b Compare August 11, 2025 07:32
SyncPeriod is likely to get ignored if you use a predicate.

This PR updates the docs to make this more obvious.
@guettli guettli force-pushed the tg/add-more-docs-to-syncPeriod branch from dd7366b to 4808f19 Compare August 11, 2025 07:33
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

thanks!

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

LGTM label has been added.

Git tree hash: 3a9ef1ea95f09638ba9f2443adec23981f485c84

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, guettli

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 Aug 11, 2025
@k8s-ci-robot k8s-ci-robot merged commit 6707052 into kubernetes-sigs:main Aug 11, 2025
8 checks passed
@@ -172,6 +172,17 @@ type Options struct {
// is "done" with an object, and would otherwise not requeue it, i.e., we
// recommend the `Reconcile` function return `reconcile.Result{RequeueAfter: t}`,
// instead of `reconcile.Result{}`.
//
// SyncPeriod will trigger update events with the old object being equal to the new
// object, except when the cache was out of sync.
Copy link
Member

@sbueringer sbueringer Aug 11, 2025

Choose a reason for hiding this comment

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

except when the cache was out of sync

I'm not sure that this is true. Do we have evidence that informer sometimes trigger update events with old object != new object during resync?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote that, because I thought that this is what SyncPeriod should do: Check if the local cache is in-sync with the api-server. But the question of Stefan makes sense: Do we have evidence?

@alvaroaleman Do you know more about that?

Copy link
Member

@sbueringer sbueringer Aug 12, 2025

Choose a reason for hiding this comment

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

(Simplified version) Every syncPeriod the informer takes all objects that are stored locally and sends out update events for them.

I took a look at the implementation, but for me it's not clear if oldObj/newObj are always identical or not

xref: https://github.com/kubernetes/kubernetes/blob/5cca03792748714547c39330ac9cb8cb9c7c60ae/staging/src/k8s.io/client-go/tools/cache/controller.go#L567

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that this is a sync between the api-server and the local cache :-)

Copy link
Member

Choose a reason for hiding this comment

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

Nope :) But that's a very frequent misunderstanding

Copy link
Member

Choose a reason for hiding this comment

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

Re-reading the rest of the godoc above. While it contains a lot of correct information I can see how it's misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants