-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Ensure APIStreaming is used if available #3055
Comments
Thanks! Looking forward to this feature and was wondering how we would enable it in controller-runtime. Automatic enablement would be really cool :) |
I think CR should have the same default behavior as the underlying client-go version (it's not enabled per default in client-go v0.32) |
xref @p0lyn0mial's https://github.com/kubernetes-sigs/controller-runtime/pull/2934/files where he proved that controller-runtime can adopt watchlist. |
the test results from the pr can be found in this comment. |
One thing @sbueringer noticed is that it doesn't seem the live clients LIST will use watchlist under the hood by default And generally speaking, this doesn't necessarily mean that watchlist was actually used, just that nothing broke or am I missing something?
|
For the cache, it seems our usage of I think to use $ g diff
diff --git a/pkg/client/typed_client.go b/pkg/client/typed_client.go
index 92afd9a9..63014d9b 100644
--- a/pkg/client/typed_client.go
+++ b/pkg/client/typed_client.go
@@ -20,6 +20,7 @@ import (
"context"
"k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/client-go/util/watchlist"
)
var _ Reader = &typedClient{}
@@ -157,6 +158,17 @@ func (c *typedClient) List(ctx context.Context, obj ObjectList, opts ...ListOpti
listOpts := ListOptions{}
listOpts.ApplyOptions(opts)
+ watchListOptions, hasWatchListOptionsPrepared, err := watchlist.PrepareWatchListOptionsFromListOptions(*listOpts.AsListOptions())
+ if err == nil && hasWatchListOptionsPrepared {
+ if err := r.Get().
+ NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
+ Resource(r.resource()).
+ VersionedParams(&watchListOptions, c.paramCodec).
+ WatchList(ctx).
+ Into(obj); err == nil {
+ return nil
+ }
+ }
return r.Get().
NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
Resource(r.resource()). I can not off-hand think of a good way to write tests for this though |
There are two FGs. The In order to use the new feature on a 1.32 cluster you need to explicitly enable |
The live client Alvaro is referring to is implemented here: controller-runtime/pkg/client/typed_client.go Line 151 in 10a0272
List method from client-go.
r, err := c.resources.getResource(obj)
if err != nil {
return err
}
listOpts := ListOptions{}
listOpts.ApplyOptions(opts)
return r.Get().
NamespaceIfScoped(listOpts.Namespace, r.isNamespaced()).
Resource(r.resource()).
VersionedParams(listOpts.AsListOptions(), c.paramCodec).
Do(ctx).
Into(obj) Our assumption at the moment is that this doesn't automatically use |
ah, yes, this is correct, the feature was added to the generated client not to the rest client int the client-go lib. |
Note: Due to lack of time from the maintainers, we will not update the live client to use apistreaming for the next c-r release. It already works in the cache which is the majority use-case and is default disabled in client-go anyways, so we do not want to block the release on this. |
We should be using https://kubernetes.io/blog/2024/12/17/kube-apiserver-api-streaming/ if the server supports it. It could be that there are no changes required for that, but we should validate that assumption before the next release.
The text was updated successfully, but these errors were encountered: