From 51beeb26762d7debd9063aea82967ad583f31184 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Tue, 28 Oct 2025 09:40:01 +0100 Subject: [PATCH] dynamic-resource-allocation/client: expose IsWatchListSemanticsUnSupported --- .../client/client.go | 12 ++++ .../client/client_test.go | 55 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 staging/src/k8s.io/dynamic-resource-allocation/client/client_test.go diff --git a/staging/src/k8s.io/dynamic-resource-allocation/client/client.go b/staging/src/k8s.io/dynamic-resource-allocation/client/client.go index 9a02424b0ad..43676d5d258 100644 --- a/staging/src/k8s.io/dynamic-resource-allocation/client/client.go +++ b/staging/src/k8s.io/dynamic-resource-allocation/client/client.go @@ -23,6 +23,7 @@ import ( "k8s.io/client-go/kubernetes" cgoresource "k8s.io/client-go/kubernetes/typed/resource/v1" rest "k8s.io/client-go/rest" + "k8s.io/client-go/util/watchlist" ) // Enumerate all supported APIs, most preferred first. @@ -102,3 +103,14 @@ func (c *Client) ResourceSlices() cgoresource.ResourceSliceInterface { c.clientSet.ResourceV1beta2().ResourceSlices(), ) } + +// IsWatchListSemanticsSupported informs the reflector that this client +// doesn't support WatchList semantics. +// +// This is a synthetic method whose sole purpose is to satisfy the optional +// interface check performed by the reflector. +// Returning true signals that WatchList can NOT be used. +// No additional logic is implemented here. +func (c *Client) IsWatchListSemanticsUnSupported() bool { + return watchlist.DoesClientNotSupportWatchListSemantics(c.clientSet) +} diff --git a/staging/src/k8s.io/dynamic-resource-allocation/client/client_test.go b/staging/src/k8s.io/dynamic-resource-allocation/client/client_test.go new file mode 100644 index 00000000000..c8ec55ecdb2 --- /dev/null +++ b/staging/src/k8s.io/dynamic-resource-allocation/client/client_test.go @@ -0,0 +1,55 @@ +/* +Copyright 2025 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package client + +import ( + "testing" + + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/fake" + restclient "k8s.io/client-go/rest" + "k8s.io/client-go/util/watchlist" +) + +func TestDoesClientSupportWatchListSemantics(t *testing.T) { + scenarios := []struct { + name string + clientSet kubernetes.Interface + expectedDoesClientNotSupportWatchListSemantics bool + }{ + { + name: "DR with real kube client supports WatchList semantics", + clientSet: kubernetes.NewForConfigOrDie(&restclient.Config{}), + expectedDoesClientNotSupportWatchListSemantics: false, + }, + { + name: "DR with fake kube client does NOT support WatchList semantics", + clientSet: fake.NewClientset(), + expectedDoesClientNotSupportWatchListSemantics: true, + }, + } + + for _, scenario := range scenarios { + t.Run(scenario.name, func(t *testing.T) { + target := New(scenario.clientSet) + actual := watchlist.DoesClientNotSupportWatchListSemantics(target) + if actual != scenario.expectedDoesClientNotSupportWatchListSemantics { + t.Fatalf("watchlist.DoesClientNotSupportWatchListSemantics, got: %v, want: %v", actual, scenario.expectedDoesClientNotSupportWatchListSemantics) + } + }) + } +}