-
Notifications
You must be signed in to change notification settings - Fork 3.4k
StateDB-based K8s fake client object tracker #39446
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
StateDB-based K8s fake client object tracker #39446
Conversation
a4ee357
to
39d8681
Compare
39d8681
to
297ee87
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.
nice! I've added a comment re a deadlock that I think should happen, but maybe I misunderstood something.
One more place to clean up might be the controlplane tests, where there's the whole infra for waiting for the watch to be established. Otherwise I can do that in a separate PR.
I'm planning to remove test/controlplane completely soon so probably not worth it. |
70f37e5
to
ddc224a
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.
LGTM modulo one missed db/initialized
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.
Looks good, just some small things here and there..
ddc224a
to
8a10a10
Compare
This comment was marked as outdated.
This comment was marked as outdated.
af7c346
to
9967569
Compare
This comment was marked as outdated.
This comment was marked as outdated.
/test |
9967569
to
9b38ae1
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.
nice, thanks!
The default testing.ObjectTracker that comes with client-go does not properly implement the Watch() method: 1) Does not support watching from a specific ResourceVersion 2) Does not support multiple concurrent Watch() calls 3) Does not support FieldSelector This has been an ongoing pain as all the testing code needs to make sure the implementation does not call Watch() too early. This has required either populating the ObjectTracker before starting the implementation or synchronizing with the implementation to add objects only after Watch() has been called (e.g. db/initialized or k8s/wait-watchers). This commit implements a StateDB based ObjectTracker that properly implements Watch() and FieldSelector. Signed-off-by: Jussi Maki <jussi@isovalent.com>
With the new fake client object tracker we no longer need to synchronize with the reflectors before adding objects, so we can remove db/initialized. Interestingly enough this change triggered the goleak to hit the workqueue goroutine leak from Resource[T]. We don't have a way for waiting for that background goroutine to exit so we'll just need to ignore it the same way pkg/k8s/resource/resource_test.go does. Fix the node name in hostport.txtar now that FieldSelector is implemented. Signed-off-by: Jussi Maki <jussi@isovalent.com>
No need to wait for watchers anymore so remove db/initialized calls from tests. Signed-off-by: Jussi Maki <jussi@isovalent.com>
Now that we're using our own object tracker the Tracker() method cannot be used as that returns the wrong object tracker. It anyway makes more sense to go via the typed API. Fix the Resource[T] tests to not use Tracker() and also not to use ResourceVersion as that's now correctly populated by the object tracker. Signed-off-by: Jussi Maki <jussi@isovalent.com>
With the proper object tracker we no longer need this. Signed-off-by: Jussi Maki <jussi@isovalent.com>
Since we're using Tracker() method in bunch of tests make it point to our ObjectTracker. Unfortunately there's no clean way to do this so I need to just play tricks with unsafe.Pointer. At least the result can be validated. Signed-off-by: Jussi Maki <jussi@isovalent.com>
As db/initialized is not necessary anymore just for waiting for reflector/informer to sync, remove remaining uses of it. Fix the remaining field selector issues. Signed-off-by: Jussi Maki <jussi@isovalent.com>
9b38ae1
to
d523bb3
Compare
/test |
This implements a new
testing.ObjectTracker
on top of StateDB that fixes the long-standing pain point with the k8s fake client, namely that itsWatch
implementation does not support multiple watchers and it will miss events that happen betweenList
andWatch
. This new implementation understandsResourceVersion
and allows starting to watch from older versions without missing events.This will also help doing more complicated integration tests where we would e.g. run the agent and the operator hives in the same process with a single fake client & tracker and we would be able to have both watching the same resources.
An extra bonus is that we now have debug logging for every k8s action that is done: