replace ENABLE_CLIENT_GO_WATCH_LIST_ALPHA with WatchListClient gate

This commit is contained in:
Lukasz Szaszkiewicz 2024-04-30 08:24:53 +02:00
parent a70089ab99
commit 9248cccc27
2 changed files with 24 additions and 13 deletions

View File

@ -22,7 +22,6 @@ import (
"fmt"
"io"
"math/rand"
"os"
"reflect"
"strings"
"sync"
@ -39,6 +38,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
clientfeatures "k8s.io/client-go/features"
"k8s.io/client-go/tools/pager"
"k8s.io/klog/v2"
"k8s.io/utils/clock"
@ -254,9 +254,7 @@ func NewReflectorWithOptions(lw ListerWatcher, expectedType interface{}, store S
// don't overwrite UseWatchList if already set
// because the higher layers (e.g. storage/cacher) disabled it on purpose
if r.UseWatchList == nil {
if s := os.Getenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA"); len(s) > 0 {
r.UseWatchList = ptr.To(true)
}
r.UseWatchList = ptr.To(clientfeatures.FeatureGates().Enabled(clientfeatures.WatchListClient))
}
return r

View File

@ -19,7 +19,6 @@ package apimachinery
import (
"context"
"fmt"
"os"
"sort"
"time"
@ -31,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
clientfeatures "k8s.io/client-go/features"
"k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/test/e2e/feature"
"k8s.io/kubernetes/test/e2e/framework"
@ -38,16 +38,14 @@ import (
var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), feature.WatchList, func() {
f := framework.NewDefaultFramework("watchlist")
ginkgo.It("should be requested when ENABLE_CLIENT_GO_WATCH_LIST_ALPHA is set", func(ctx context.Context) {
prevWatchListEnvValue, wasWatchListEnvSet := os.LookupEnv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA")
os.Setenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA", "true")
ginkgo.It("should be requested when WatchListClient is enabled", func(ctx context.Context) {
// TODO(p0lyn0mial): use https://github.com/kubernetes/kubernetes/pull/123974
// instead of using directly clientfeatures.ReplaceFeatureGates
prevClientFeatureGates := clientfeatures.FeatureGates()
defer func() {
if !wasWatchListEnvSet {
os.Unsetenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA")
return
}
os.Setenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA", prevWatchListEnvValue)
clientfeatures.ReplaceFeatureGates(prevClientFeatureGates)
}()
clientfeatures.ReplaceFeatureGates(newEnabledWatchListClientFeatureGateRegistry(prevClientFeatureGates))
stopCh := make(chan struct{})
defer close(stopCh)
secretInformer := cache.NewSharedIndexInformer(
@ -123,3 +121,18 @@ func newSecret(name string) *v1.Secret {
ObjectMeta: metav1.ObjectMeta{Name: name},
}
}
type enabledWatchListClientFeatureGateRegistry struct {
originalGates clientfeatures.Gates
}
func newEnabledWatchListClientFeatureGateRegistry(originalGates clientfeatures.Gates) *enabledWatchListClientFeatureGateRegistry {
return &enabledWatchListClientFeatureGateRegistry{originalGates: originalGates}
}
func (r *enabledWatchListClientFeatureGateRegistry) Enabled(feature clientfeatures.Feature) bool {
if feature == clientfeatures.WatchListClient {
return true
}
return r.originalGates.Enabled(feature)
}