mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-31 22:59:34 +00:00
client-go/reflector: stop exposing UseWatchList (#132453)
* client-go/reflector: stop exposing UseWatchList * apiserver/cacher: stop setting reflector.UseWatchList * test/integration/watchlist: fix TestReflectorWatchListFallback Kubernetes-commit: b8b3984874e930c92057589fd1a7668dbdffc117
This commit is contained in:
committed by
Kubernetes Publisher
parent
bb7300621b
commit
1785b5afec
18
tools/cache/reflector.go
vendored
18
tools/cache/reflector.go
vendored
@@ -43,7 +43,6 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/utils/clock"
|
"k8s.io/utils/clock"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/pointer"
|
||||||
"k8s.io/utils/ptr"
|
|
||||||
"k8s.io/utils/trace"
|
"k8s.io/utils/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -130,7 +129,7 @@ type Reflector struct {
|
|||||||
ShouldResync func() bool
|
ShouldResync func() bool
|
||||||
// MaxInternalErrorRetryDuration defines how long we should retry internal errors returned by watch.
|
// MaxInternalErrorRetryDuration defines how long we should retry internal errors returned by watch.
|
||||||
MaxInternalErrorRetryDuration time.Duration
|
MaxInternalErrorRetryDuration time.Duration
|
||||||
// UseWatchList if turned on instructs the reflector to open a stream to bring data from the API server.
|
// useWatchList if turned on instructs the reflector to open a stream to bring data from the API server.
|
||||||
// Streaming has the primary advantage of using fewer server's resources to fetch data.
|
// Streaming has the primary advantage of using fewer server's resources to fetch data.
|
||||||
//
|
//
|
||||||
// The old behaviour establishes a LIST request which gets data in chunks.
|
// The old behaviour establishes a LIST request which gets data in chunks.
|
||||||
@@ -138,9 +137,7 @@ type Reflector struct {
|
|||||||
// might result in an increased memory consumption of the APIServer.
|
// might result in an increased memory consumption of the APIServer.
|
||||||
//
|
//
|
||||||
// See https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3157-watch-list#design-details
|
// See https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3157-watch-list#design-details
|
||||||
//
|
useWatchList bool
|
||||||
// TODO(#115478): Consider making reflector.UseWatchList a private field. Since we implemented "api streaming" on the etcd storage layer it should work.
|
|
||||||
UseWatchList *bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reflector) Name() string {
|
func (r *Reflector) Name() string {
|
||||||
@@ -293,11 +290,7 @@ func NewReflectorWithOptions(lw ListerWatcher, expectedType interface{}, store R
|
|||||||
r.expectedGVK = getExpectedGVKFromObject(expectedType)
|
r.expectedGVK = getExpectedGVKFromObject(expectedType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't overwrite UseWatchList if already set
|
r.useWatchList = clientfeatures.FeatureGates().Enabled(clientfeatures.WatchListClient)
|
||||||
// because the higher layers (e.g. storage/cacher) disabled it on purpose
|
|
||||||
if r.UseWatchList == nil {
|
|
||||||
r.UseWatchList = ptr.To(clientfeatures.FeatureGates().Enabled(clientfeatures.WatchListClient))
|
|
||||||
}
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -403,8 +396,7 @@ func (r *Reflector) ListAndWatchWithContext(ctx context.Context) error {
|
|||||||
logger.V(3).Info("Listing and watching", "type", r.typeDescription, "reflector", r.name)
|
logger.V(3).Info("Listing and watching", "type", r.typeDescription, "reflector", r.name)
|
||||||
var err error
|
var err error
|
||||||
var w watch.Interface
|
var w watch.Interface
|
||||||
useWatchList := ptr.Deref(r.UseWatchList, false)
|
fallbackToList := !r.useWatchList
|
||||||
fallbackToList := !useWatchList
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if w != nil {
|
if w != nil {
|
||||||
@@ -412,7 +404,7 @@ func (r *Reflector) ListAndWatchWithContext(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if useWatchList {
|
if r.useWatchList {
|
||||||
w, err = r.watchList(ctx)
|
w, err = r.watchList(ctx)
|
||||||
if w == nil && err == nil {
|
if w == nil && err == nil {
|
||||||
// stopCh was closed
|
// stopCh was closed
|
||||||
|
4
tools/cache/reflector_test.go
vendored
4
tools/cache/reflector_test.go
vendored
@@ -47,6 +47,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
clientfeatures "k8s.io/client-go/features"
|
||||||
|
clientfeaturestesting "k8s.io/client-go/features/testing"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
"k8s.io/utils/clock"
|
"k8s.io/utils/clock"
|
||||||
testingclock "k8s.io/utils/clock/testing"
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
@@ -533,6 +535,7 @@ func TestReflectorListAndWatch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range table {
|
for _, tc := range table {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
clientfeaturestesting.SetFeatureDuringTest(t, clientfeatures.WatchListClient, tc.useWatchList)
|
||||||
watcherCh := make(chan *watch.FakeWatcher)
|
watcherCh := make(chan *watch.FakeWatcher)
|
||||||
var listOpts, watchOpts []metav1.ListOptions
|
var listOpts, watchOpts []metav1.ListOptions
|
||||||
|
|
||||||
@@ -563,7 +566,6 @@ func TestReflectorListAndWatch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
s := NewFIFO(MetaNamespaceKeyFunc)
|
s := NewFIFO(MetaNamespaceKeyFunc)
|
||||||
r := NewReflector(lw, &v1.Pod{}, s, 0)
|
r := NewReflector(lw, &v1.Pod{}, s, 0)
|
||||||
r.UseWatchList = ptr.To(tc.useWatchList)
|
|
||||||
|
|
||||||
// Start ListAndWatch in the background.
|
// Start ListAndWatch in the background.
|
||||||
// When it returns, it will send an error or nil on the error
|
// When it returns, it will send an error or nil on the error
|
||||||
|
8
tools/cache/reflector_watchlist_test.go
vendored
8
tools/cache/reflector_watchlist_test.go
vendored
@@ -36,10 +36,11 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
clientfeatures "k8s.io/client-go/features"
|
||||||
|
clientfeaturestesting "k8s.io/client-go/features/testing"
|
||||||
"k8s.io/klog/v2/ktesting"
|
"k8s.io/klog/v2/ktesting"
|
||||||
testingclock "k8s.io/utils/clock/testing"
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/pointer"
|
||||||
"k8s.io/utils/ptr"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInitialEventsEndBookmarkTicker(t *testing.T) {
|
func TestInitialEventsEndBookmarkTicker(t *testing.T) {
|
||||||
@@ -474,6 +475,7 @@ func TestWatchList(t *testing.T) {
|
|||||||
t.Run(s.name, func(t *testing.T) {
|
t.Run(s.name, func(t *testing.T) {
|
||||||
scenario := s // capture as local variable
|
scenario := s // capture as local variable
|
||||||
_, ctx := ktesting.NewTestContext(t)
|
_, ctx := ktesting.NewTestContext(t)
|
||||||
|
clientfeaturestesting.SetFeatureDuringTest(t, clientfeatures.WatchListClient, !scenario.disableUseWatchList)
|
||||||
listWatcher, store, reflector, ctx, cancel := testData(ctx)
|
listWatcher, store, reflector, ctx, cancel := testData(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
for i, e := range scenario.watchEvents {
|
for i, e := range scenario.watchEvents {
|
||||||
@@ -491,9 +493,6 @@ func TestWatchList(t *testing.T) {
|
|||||||
listWatcher.closeAfterWatchRequests = scenario.closeAfterWatchRequests
|
listWatcher.closeAfterWatchRequests = scenario.closeAfterWatchRequests
|
||||||
listWatcher.customListResponse = scenario.podList
|
listWatcher.customListResponse = scenario.podList
|
||||||
listWatcher.closeAfterListRequests = scenario.closeAfterListRequests
|
listWatcher.closeAfterListRequests = scenario.closeAfterListRequests
|
||||||
if scenario.disableUseWatchList {
|
|
||||||
reflector.UseWatchList = ptr.To(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := reflector.ListAndWatchWithContext(ctx)
|
err := reflector.ListAndWatchWithContext(ctx)
|
||||||
if scenario.expectedError != nil && err == nil {
|
if scenario.expectedError != nil && err == nil {
|
||||||
@@ -582,7 +581,6 @@ func testData(ctx context.Context) (*fakeListWatcher, Store, *Reflector, context
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
r := NewReflector(lw, &v1.Pod{}, s, 0)
|
r := NewReflector(lw, &v1.Pod{}, s, 0)
|
||||||
r.UseWatchList = ptr.To(true)
|
|
||||||
|
|
||||||
return lw, s, r, ctx, cancel
|
return lw, s, r, ctx, cancel
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user