-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Cache serializations across watchers #81914
Cache serializations across watchers #81914
Conversation
@wojtek-t: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. 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. |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
899779b
to
3f20ed6
Compare
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, I'l try to get another pass out shortly
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
3f20ed6
to
7eb32f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updates to first 5 commits were done in the parent PR: #81585
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple more suggestions
7eb32f6
to
e876bce
Compare
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
// The following functions implement metav1.Object interface: | ||
// - getters simply delegate for underlying object | ||
// - SetSelfLink stores the value passed in the first call | ||
// - all other setters ignore the passed value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is pretty confusing... I expected all getters/setters to pass through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit tricky. We can let them pass through and this will work, because noone is really using that.
But if we would e.g. create an encoder that is trying to overwrite one of the metadata, this can clearly break it for everyone. If course this is possible to fix - that encode instead of using CacheEncode should be calling GetObject() and operate on it. But that's relying on others.
I personally think that ignoring the values is safer - passing it through is easy to do, but I'm not sure it's what we really want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spoke offline. will switch setters to lock, invalidate the cache on changes, and pass through. we don't actually expect these to get called frequently, so this is just for completeness and to fulfill the objectmeta interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
defer o.lock.Unlock() | ||
if o.selfLink != nil { | ||
selfLink := *o.selfLink | ||
result.selfLink = &selfLink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
special-casing selfLink seems problematic. Can we generalize the object ownership principles so that the cached encoding can safely operate without this special-casing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we will remove selflink, this special case will also be removed - this is sth that I had in the back of my head too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can drop this as part of passing through setters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
case !curObjPasses && oldObjPasses: | ||
// return a delete event with the previous object content, but with the event's resource version | ||
oldObj := event.PrevObject.DeepCopyObject() | ||
if err := c.versioner.UpdateObject(oldObj, event.ResourceVersion); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... this is fragile and potentially problematic (the same original object+resourceVersion can be encoded with different resourceVersions)... definitely need a test that exercises an object at a given resourceVersion getting encoded into delete events at different resourceVersions. For example:
- start three watchers
- unfiltered
labelSelector=foo=true
labelSelector=bar=true
- add object with labels
foo=true
,bar=true
at rv=1- watch events with rv=1 get sent to all watchers
- update object to remove
foo=true
label at rv=2- update event with rv=2 and
bar=true
content gets sent to unfiltered andbar=true
watchers - delete event with rv=2 and
foo=true,bar=true
content gets sent tofoo=true
watcher
- update event with rv=2 and
- update object to remove
bar=true
label at rv=3- update event with rv=3 and no label content gets sent to unfiltered watcher
- delete event with rv=3 and
bar=true
content gets sent tobar=true
watcher
- delete object at rv=4
- delete event with rv=4 and no label content gets sent to unfiltered watcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - this is also the reason why I think the deep-copy is needed.
Will work on adding this test now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
e876bce
to
3ad2feb
Compare
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go
Outdated
Show resolved
Hide resolved
f4d16a5
to
25a728a
Compare
@wojtek-t: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. 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. |
/retest |
/lgtm thanks for all the work on this |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, wojtek-t 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 |
@wojtek-t: The following test failed, say
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. |
Reuse serialization result across watchers - before this change, we were serializing objects independently for every single watcher. With this PR, when dispatching an event in watchcache:
This is significant performance improvement:
This is also addressing Creating large Endpoints objects in large clusters takes long #75294
Ref kubernetes/enhancements#1152