-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Clarify "resourceVersion unset" semantics in Watch #26064
Comments
@embano1: This issue is currently awaiting triage. SIG Docs takes a lead on issue triage for this website, but any Kubernetes member can accept issues by applying the The 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 think @jpbetz knows the current state on this, this might be a dup |
Thx, yeah...I checked the docs (last PR from him actually) and also the issues but could not find clarification around cache/nocache Watch() behavior in the docs. |
Yes - this is a bug in documentation, which we should fix. That said - using watch with RV = 0 or RV unset isn't really a recommended pattern. Generally the "list + watch from there" is the pattern that we recommend everywhere. |
Agree. Follow-up question since most users will likely use ListerWatcher with SharedIndexInformer (reflector) or controller-runtime (which does this implicitly): These controllers don't enforce quorum list on start, thus are also vulnerable to time travel issues even though using list+watch, right? Reason why I am asking is that this behavior likely is not known to the majority of the community. Should we also document this then? |
The documentation absolutely needs to be updated for this case. I'll try to get to that. I agree that watch with RV="" should be avoided. I'll try to incorporate that into the documentation. ListerWatcher, SharedIndexInformer or whatever other documentation doesn't capture this also really needs to be updated. I'm less familiar with that documentation, so if anyone is willing to own getting that updated, it would be a huge help. I believe the Reflector documentation is OK since it just delegates to the ListerWatcher provided to NewReflector, but it might be good to see if it can be improved in any way as well. |
Happy to help, wondering whether this would only be in the
Please help me with my understanding: as you said, func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
klog.V(3).Infof("Listing and watching %v from %s", r.expectedTypeName, r.name)
var resourceVersion string
options := metav1.ListOptions{ResourceVersion: r.relistResourceVersion()}
if err := func() error {
initTrace := trace.New("Reflector ListAndWatch", trace.Field{"name", r.name})
defer initTrace.LogIfLong(10 * time.Second)
var list runtime.Object
var paginatedResult bool
var err error
listCh := make(chan struct{}, 1)
panicCh := make(chan interface{}, 1)
go func() {
defer func() {
if r := recover(); r != nil {
panicCh <- r
}
}()
// Attempt to gather list in chunks, if supported by listerWatcher, if not, the first
// list request will return the full response.
pager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
return r.listerWatcher.List(opts)
})) IMHO if r.lastSyncResourceVersion == "" {
// For performance reasons, initial list performed by reflector uses "0" as resource version to allow it to
// be served from the watch cache if it is enabled.
return "0"
} Thus, the reflector will List from |
Oh right. So the background here is that we did attempt (quite a long time ago, now) to update Reflectors to do the initial list using RV="". The PR (kubernetes/kubernetes#83520) got rolled back due to due to excessive list calls to etcd (kubernetes/kubernetes#86824). I haven't gotten the bandwidth since then to try to tackle this again, but maybe it would be reasonable to provide an option when constructing reflectors to specify that initial lists should be consistent. For documentation, you're absolutely right, we have the "reflectors can go back in time problem" and we should document that. |
Perfect, let me know where I can help and I'll file PR(s). Just don't know all the places from a docs perspective. |
/sig api-machinery |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
I could revise #25299 if someone suggests new wording. |
@sftim can you please point me to the section where you would like to add the different |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
@embano1 I'd add the extra details about |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closing this issue. In response to this:
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 is a Feature Request
I wasn't sure whether to file as bug or feature (more clarity), thus decided to use "feature" here. I also understand that there have been lots of discussions around watch behavior [1,2], but wanted to seek clarity from a documentation perspective.
[1] #16944
[2] kubernetes/kubernetes#74022
What would you like to be added
The current documentation on resource version for Watches in the API concepts states:
This is correct for API servers without cache. However, the default behavior in kube-apiserver is
--watch-cache Default: true
. From theCacher
code path forWatch()
I read that no matter which RV is passed, it will always be served from the cache:If my understanding is correct, any client
Watch()
with empty RV (""
) against an API server with cacheenabled
will not be served via quorum read. If so, the documentation should point this out, e.g. amend the following paragraph:Start a watch at the most recent resource version, which must be consistent (i.e. served from etcd via a quorum read). [add something about clusters with API server cache enabled]
Why is this needed
A user (controller developer) might be under the false assumption that their
Watches()
are strongly consistent when not specifying a RV and not knowing whether the actual cluster runs with API server caching or not (e.g. managed environments, separate teams, etc.).Comments
If my understanding is correct the time travel bug for lists could potentially exist in many custom controllers/CRDs if users rely on strongly consistent RV ==
""
semantics as described in the documentation.cc/ @liggitt @jpbetz @lavalamp @wojtek-t @tnozicka @marshtompsxd @lalithsuresh
The text was updated successfully, but these errors were encountered: