From a38ad3a2c67290e0bc3dcda17f571ad16573714e Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Fri, 6 Jun 2025 16:15:43 +0200 Subject: [PATCH 1/2] client-go/metadata: rm watchlist --- .../src/k8s.io/client-go/metadata/metadata.go | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/staging/src/k8s.io/client-go/metadata/metadata.go b/staging/src/k8s.io/client-go/metadata/metadata.go index a19ba13049f..2cc7e22adf7 100644 --- a/staging/src/k8s.io/client-go/metadata/metadata.go +++ b/staging/src/k8s.io/client-go/metadata/metadata.go @@ -33,8 +33,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/rest" - "k8s.io/client-go/util/consistencydetector" - "k8s.io/client-go/util/watchlist" ) var deleteScheme = runtime.NewScheme() @@ -220,24 +218,6 @@ func (c *client) Get(ctx context.Context, name string, opts metav1.GetOptions, s // List returns all resources within the specified scope (namespace or cluster). func (c *client) List(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) { - if watchListOptions, hasWatchListOptionsPrepared, watchListOptionsErr := watchlist.PrepareWatchListOptionsFromListOptions(opts); watchListOptionsErr != nil { - klog.FromContext(ctx).Error(watchListOptionsErr, "Failed preparing watchlist options, falling back to the standard LIST semantics", "resource", c.resource) - } else if hasWatchListOptionsPrepared { - result, err := c.watchList(ctx, watchListOptions) - if err == nil { - consistencydetector.CheckWatchListFromCacheDataConsistencyIfRequested(ctx, fmt.Sprintf("watchlist request for %v", c.resource), c.list, opts, result) - return result, nil - } - klog.FromContext(ctx).Error(err, "The watchlist request ended with an error, falling back to the standard LIST semantics", "resource", c.resource) - } - result, err := c.list(ctx, opts) - if err == nil { - consistencydetector.CheckListFromCacheDataConsistencyIfRequested(ctx, fmt.Sprintf("list request for %v", c.resource), c.list, opts, result) - } - return result, err -} - -func (c *client) list(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) { result := c.client.client.Get().AbsPath(c.makeURLSegments("")...). SetHeader("Accept", "application/vnd.kubernetes.protobuf;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json"). SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). @@ -269,25 +249,6 @@ func (c *client) list(ctx context.Context, opts metav1.ListOptions) (*metav1.Par return partial, nil } -// watchList establishes a watch stream with the server and returns PartialObjectMetadataList. -func (c *client) watchList(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - - result := &metav1.PartialObjectMetadataList{} - err := c.client.client.Get(). - AbsPath(c.makeURLSegments("")...). - SetHeader("Accept", "application/vnd.kubernetes.protobuf;as=PartialObjectMetadata;g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1,application/json"). - SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). - Timeout(timeout). - WatchList(ctx). - Into(result) - - return result, err -} - // Watch finds all changes to the resources in the specified scope (namespace or cluster). func (c *client) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { var timeout time.Duration From 0d5578b83957de90611ebdb847d200908e632e28 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Fri, 6 Jun 2025 16:46:15 +0200 Subject: [PATCH 2/2] test/apimachinery/watchlist: prove metadata client's List method not streaming --- test/e2e/apimachinery/watchlist.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/e2e/apimachinery/watchlist.go b/test/e2e/apimachinery/watchlist.go index da50cdbf616..7db72c4fc20 100644 --- a/test/e2e/apimachinery/watchlist.go +++ b/test/e2e/apimachinery/watchlist.go @@ -139,7 +139,7 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithFeatureGate( expectedRequestsMadeByDynamicClient := getExpectedRequestsMadeByClientFor(secretList.GetResourceVersion()) gomega.Expect(rt.actualRequests).To(gomega.Equal(expectedRequestsMadeByDynamicClient)) }) - ginkgo.It("should be requested by metadata client's List method when WatchListClient is enabled", func(ctx context.Context) { + ginkgo.It("should NOT be requested by metadata client's List method when WatchListClient is enabled", func(ctx context.Context) { featuregatetesting.SetFeatureGateDuringTest(ginkgo.GinkgoTB(), utilfeature.DefaultFeatureGate, featuregate.Feature(clientfeatures.WatchListClient), true) metaClient, err := metadata.NewForConfig(f.ClientConfig()) @@ -155,16 +155,16 @@ var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithFeatureGate( wrappedMetaClient, err := metadata.NewForConfig(clientConfig) framework.ExpectNoError(err) - ginkgo.By("Streaming secrets metadata from the server") + ginkgo.By("Getting secrets metadata from the server") secretMetaList, err := wrappedMetaClient.Resource(v1.SchemeGroupVersion.WithResource("secrets")).Namespace(f.Namespace.Name).List(ctx, metav1.ListOptions{LabelSelector: "watchlist=true"}) framework.ExpectNoError(err) ginkgo.By("Verifying if the secret meta list was properly streamed") - streamedMetaSecrets := secretMetaList.Items - gomega.Expect(cmp.Equal(expectedMetaSecrets, streamedMetaSecrets)).To(gomega.BeTrueBecause("data received via watchlist must match the added data")) + actualMetaSecrets := secretMetaList.Items + gomega.Expect(cmp.Equal(expectedMetaSecrets, actualMetaSecrets)).To(gomega.BeTrueBecause("data received via list must match the added data")) ginkgo.By("Verifying if expected requests were sent to the server") - expectedRequestsMadeByMetaClient := getExpectedRequestsMadeByClientFor(secretMetaList.GetResourceVersion()) + expectedRequestsMadeByMetaClient := []string{expectedListRequestMadeByClient} gomega.Expect(rt.actualRequests).To(gomega.Equal(expectedRequestsMadeByMetaClient)) }) @@ -288,6 +288,12 @@ var expectedStreamingRequestMadeByClient = func() string { return params.Encode() }() +var expectedListRequestMadeByClient = func() string { + params := url.Values{} + params.Add("labelSelector", "watchlist=true") + return params.Encode() +}() + func getExpectedListRequestMadeByConsistencyDetectorFor(rv string) string { params := url.Values{} params.Add("labelSelector", "watchlist=true")