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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

// If you filter update events like this:
// Controller.Watch(
// &source.Kind{Type: v1.MyCustomKind},
// &handler.EnqueueRequestForObject{},
// predicate.Or(predicate.GenerationChangedPredicate{},
// predicate.LabelChangedPredicate{}))
// then the SyncPeriod will not trigger a Reconcile call, because the update event
// will be ignored by the predicate.
SyncPeriod *time.Duration

// ReaderFailOnMissingInformer configures the cache to return a ErrResourceNotCached error when a user
Expand Down