kubernetes: client-go example fails due to race condition in fakes+informers
This is broken off of https://github.com/kubernetes/kubernetes/issues/88508 which was stalebot closed
What happened:
Run the example https://github.com/kubernetes/client-go/blob/master/examples/fake-client/main_test.go#L42. It will usually pass. However, there is an inherent race condition in the fake client and informer code.
In the real client, we do a list, then set up a watch with the resourceVersion returned in the list. However, the fake client ignores resourceVersions. This leads to a race between https://github.com/kubernetes/client-go/blob/866e6a7e3cf35d16a6d3d5175e36d05dfe4b0797/tools/cache/reflector.go#L302 and https://github.com/kubernetes/client-go/blob/866e6a7e3cf35d16a6d3d5175e36d05dfe4b0797/tools/cache/reflector.go#L414; any creates/updates during this time are dropped.
What you expected to happen:
Either:
- The race is fixed
- The example is updated to provide best practices for testing with informers and fakes. I looked through all of the k/k tests I could find, and it seems that instead of doing
client.Create(...)they are generally usinginformer.Store.Add(...). Is this the recommended pattern?
How to reproduce it (as minimally and precisely as possible):
Run the example test many times. using https://godoc.org/golang.org/x/tools/cmd/stress is useful, as is dropping the timeout from 30s to something smaller to speed up the reproduction (although 30s will still reproduce it - if you are patient). Adding -race seems to trigger it more.
If this cannot reproduce, you can inject a time.Sleep between the two code points mentioned above to exacerbate the race and make it consistent.
/sig api-machinery
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 15 (11 by maintainers)
Commits related to this issue
- Don't run CRD informer during tests This change disables the CRD source's informer during tests. I made the mistake of not running `make test` before the previous commit, and thus didn't realize tha... — committed to ericrrath/external-dns by ericrrath 5 years ago
- Don't run CRD informer during tests This change disables the CRD source's informer during tests. I made the mistake of not running `make test` before the previous commit, and thus didn't realize tha... — committed to ericrrath/external-dns by ericrrath 5 years ago
- Don't run CRD informer during tests This change disables the CRD source's informer during tests. I made the mistake of not running `make test` before the previous commit, and thus didn't realize tha... — committed to ttarhan/external-dns by ericrrath 5 years ago
- controlplane: add mechanism to wait for watchers We've recently learned that the fake k8s client set's object tracker do not respect the semantics of the real api-server when it comes to 'Watch': sin... — committed to bimmlerd/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers We've recently learned that the fake k8s client set's object tracker do not respect the semantics of the real api-server when it comes to 'Watch': sin... — committed to bimmlerd/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers We've recently learned that the fake k8s client set's object tracker do not respect the semantics of the real api-server when it comes to 'Watch': sin... — committed to bimmlerd/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers We've recently learned that the fake k8s client set's object tracker do not respect the semantics of the real api-server when it comes to 'Watch': sin... — committed to bimmlerd/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers We've recently learned that the fake k8s client set's object tracker do not respect the semantics of the real api-server when it comes to 'Watch': sin... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter notes: Whitespace conflict at the new `establishedWatchers` field in test/... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter notes: Whitespace conflict at the new `establishedWatchers` field in test/... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter notes: Whitespace conflict at the new `establishedWatchers` field in test/... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter's note: lock.Map doesn't exist, replace with sync.Map ] We've recently lea... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter notes: Whitespace conflict at the new `establishedWatchers` field in test/... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter: lock.Map -> sync.Map ] We've recently learned that the fake k8s client se... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter's note: lock.Map doesn't exist, replace with sync.Map ] We've recently lea... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter: lock.Map -> sync.Map ] We've recently learned that the fake k8s client se... — committed to cilium/cilium by bimmlerd 3 years ago
- controlplane: add mechanism to wait for watchers [ upstream commit ba99d74c444ec3bdcd7d32bd4bbec1d76f85cdd2 ] [ backporter: lock.Map -> sync.Map ] We've recently learned that the fake k8s client se... — committed to cilium/cilium by bimmlerd 3 years ago
- Update from upstream v1.15.4 (#25) * wireguard: Encrypt L7 proxy pkts to remote pods [ upstream commit 26f83491643b8c9b2921544ad340d8de07e9138c ] Marco reported that the following L7 proxy traf... — committed to giantswarm/cilium-upstream by ubergesundheit 3 years ago
I’d like to echo @howardjohn’s https://github.com/kubernetes/kubernetes/issues/95372#issuecomment-716179706
Testing with fake clients seems pretty fundamental to the k8s ecosystem and having them cooperate with informers would be a big win.