mirror of
https://github.com/kubernetes/client-go.git
synced 2025-12-26 14:42:27 +00:00
Merge pull request #134396 from p0lyn0mial/upstream-watchlist-unsupported-wl-semantics
client-go/util/watchlist/watch_list: intro DoesClientNotSupportWatchListSemantics Kubernetes-commit: b6d7517d2a27a5cf4ca85c19fde88a3a3efc3e6e
This commit is contained in:
2
go.mod
2
go.mod
@@ -24,7 +24,7 @@ require (
|
||||
golang.org/x/time v0.9.0
|
||||
google.golang.org/protobuf v1.36.8
|
||||
gopkg.in/evanphx/json-patch.v4 v4.13.0
|
||||
k8s.io/api v0.0.0-20251008212439-8ac373c4a0f3
|
||||
k8s.io/api v0.0.0-20251009052703-6cf0026d4343
|
||||
k8s.io/apimachinery v0.0.0-20251008212151-ff7ddf5d4ebc
|
||||
k8s.io/klog/v2 v2.130.1
|
||||
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912
|
||||
|
||||
4
go.sum
4
go.sum
@@ -117,8 +117,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/api v0.0.0-20251008212439-8ac373c4a0f3 h1:YgVQ+Qgh7rVCCPTCDJ+MYvwnQWyLbgqS2K/cBaQzZSQ=
|
||||
k8s.io/api v0.0.0-20251008212439-8ac373c4a0f3/go.mod h1:2QWI4G7Z29PJMgZodjE0JE4CUpVhg3xyP/aAiHciRh8=
|
||||
k8s.io/api v0.0.0-20251009052703-6cf0026d4343 h1:pA4ii8vdj8LpDHoSXCSpZcjVuY1+OG4jqRDIbmqGCcc=
|
||||
k8s.io/api v0.0.0-20251009052703-6cf0026d4343/go.mod h1:2QWI4G7Z29PJMgZodjE0JE4CUpVhg3xyP/aAiHciRh8=
|
||||
k8s.io/apimachinery v0.0.0-20251008212151-ff7ddf5d4ebc h1:QUNPCNgaM5vq8hPZ3ia8pbKf8pLBz+3s2Oevtgwlp5o=
|
||||
k8s.io/apimachinery v0.0.0-20251008212151-ff7ddf5d4ebc/go.mod h1:wE5nOmI8k5gdg4Nuo6Csst6CE+WgeB7ZNhh7K5lLUbs=
|
||||
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
||||
|
||||
@@ -80,3 +80,20 @@ func PrepareWatchListOptionsFromListOptions(listOptions metav1.ListOptions) (met
|
||||
|
||||
return watchListOptions, true, nil
|
||||
}
|
||||
|
||||
type unSupportedWatchListSemantics interface {
|
||||
IsWatchListSemanticsUnSupported() bool
|
||||
}
|
||||
|
||||
// DoesClientNotSupportWatchListSemantics reports whether the given client
|
||||
// does NOT support WatchList semantics.
|
||||
//
|
||||
// A client does NOT support WatchList only if
|
||||
// it implements `IsWatchListSemanticsUnSupported` and that returns true.
|
||||
func DoesClientNotSupportWatchListSemantics(client any) bool {
|
||||
lw, ok := client.(unSupportedWatchListSemantics)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return lw.IsWatchListSemanticsUnSupported()
|
||||
}
|
||||
|
||||
@@ -27,6 +27,52 @@ import (
|
||||
"k8s.io/utils/ptr"
|
||||
)
|
||||
|
||||
type supportsWLS struct{}
|
||||
|
||||
func (supportsWLS) IsWatchListSemanticsUnSupported() bool { return false }
|
||||
|
||||
type doesNotSupportWLS struct{}
|
||||
|
||||
func (doesNotSupportWLS) IsWatchListSemanticsUnSupported() bool { return true }
|
||||
|
||||
func TestDoesClientNotSupportWatchListSemantics(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
client any
|
||||
expectUnSupportedWatchListSemantics bool
|
||||
}{
|
||||
{
|
||||
name: "client implements the unSupportedWatchListSemantics interface and returns false",
|
||||
client: supportsWLS{},
|
||||
expectUnSupportedWatchListSemantics: false,
|
||||
},
|
||||
{
|
||||
name: "client implements the unSupportedWatchListSemantics interface and returns true",
|
||||
client: doesNotSupportWLS{},
|
||||
expectUnSupportedWatchListSemantics: true,
|
||||
},
|
||||
{
|
||||
name: "client does not implement the unSupportedWatchListSemantics interface",
|
||||
client: struct{}{},
|
||||
expectUnSupportedWatchListSemantics: false,
|
||||
},
|
||||
{
|
||||
name: "nil client",
|
||||
client: nil,
|
||||
expectUnSupportedWatchListSemantics: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, scenario := range scenarios {
|
||||
t.Run(scenario.name, func(t *testing.T) {
|
||||
got := DoesClientNotSupportWatchListSemantics(scenario.client)
|
||||
if got != scenario.expectUnSupportedWatchListSemantics {
|
||||
t.Errorf("DoesClientNotSupportWatchListSemantics returned: %v, want: %v", got, scenario.expectUnSupportedWatchListSemantics)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrepareWatchListOptionsFromListOptions test the following cases:
|
||||
//
|
||||
// +--------------------------+-----------------+---------+-----------------+
|
||||
|
||||
Reference in New Issue
Block a user