mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-24 12:43:56 +00:00
dynamic-resource-allocation/client: expose IsWatchListSemanticsUnSupported
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user