Merge pull request #122791 from p0lyn0mial/upstream-cleanup-watch-list-env-var
cleanup: replace ENABLE_CLIENT_GO_WATCH_LIST_ALPHA with WatchListClient gate
This commit is contained in:
		@@ -22,7 +22,6 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
@@ -39,6 +38,7 @@ import (
 | 
				
			|||||||
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
						utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 | 
				
			||||||
	"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"
 | 
				
			||||||
	"k8s.io/client-go/tools/pager"
 | 
						"k8s.io/client-go/tools/pager"
 | 
				
			||||||
	"k8s.io/klog/v2"
 | 
						"k8s.io/klog/v2"
 | 
				
			||||||
	"k8s.io/utils/clock"
 | 
						"k8s.io/utils/clock"
 | 
				
			||||||
@@ -254,9 +254,7 @@ func NewReflectorWithOptions(lw ListerWatcher, expectedType interface{}, store S
 | 
				
			|||||||
	// don't overwrite UseWatchList if already set
 | 
						// don't overwrite UseWatchList if already set
 | 
				
			||||||
	// because the higher layers (e.g. storage/cacher) disabled it on purpose
 | 
						// because the higher layers (e.g. storage/cacher) disabled it on purpose
 | 
				
			||||||
	if r.UseWatchList == nil {
 | 
						if r.UseWatchList == nil {
 | 
				
			||||||
		if s := os.Getenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA"); len(s) > 0 {
 | 
							r.UseWatchList = ptr.To(clientfeatures.FeatureGates().Enabled(clientfeatures.WatchListClient))
 | 
				
			||||||
			r.UseWatchList = ptr.To(true)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r
 | 
						return r
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ package apimachinery
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,6 +30,7 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
						"k8s.io/apimachinery/pkg/runtime"
 | 
				
			||||||
	"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"
 | 
				
			||||||
	"k8s.io/client-go/tools/cache"
 | 
						"k8s.io/client-go/tools/cache"
 | 
				
			||||||
	"k8s.io/kubernetes/test/e2e/feature"
 | 
						"k8s.io/kubernetes/test/e2e/feature"
 | 
				
			||||||
	"k8s.io/kubernetes/test/e2e/framework"
 | 
						"k8s.io/kubernetes/test/e2e/framework"
 | 
				
			||||||
@@ -38,16 +38,14 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), feature.WatchList, func() {
 | 
					var _ = SIGDescribe("API Streaming (aka. WatchList)", framework.WithSerial(), feature.WatchList, func() {
 | 
				
			||||||
	f := framework.NewDefaultFramework("watchlist")
 | 
						f := framework.NewDefaultFramework("watchlist")
 | 
				
			||||||
	ginkgo.It("should be requested when ENABLE_CLIENT_GO_WATCH_LIST_ALPHA is set", func(ctx context.Context) {
 | 
						ginkgo.It("should be requested when WatchListClient is enabled", func(ctx context.Context) {
 | 
				
			||||||
		prevWatchListEnvValue, wasWatchListEnvSet := os.LookupEnv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA")
 | 
							// TODO(p0lyn0mial): use https://github.com/kubernetes/kubernetes/pull/123974
 | 
				
			||||||
		os.Setenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA", "true")
 | 
							//  instead of using directly clientfeatures.ReplaceFeatureGates
 | 
				
			||||||
 | 
							prevClientFeatureGates := clientfeatures.FeatureGates()
 | 
				
			||||||
		defer func() {
 | 
							defer func() {
 | 
				
			||||||
			if !wasWatchListEnvSet {
 | 
								clientfeatures.ReplaceFeatureGates(prevClientFeatureGates)
 | 
				
			||||||
				os.Unsetenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA")
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			os.Setenv("ENABLE_CLIENT_GO_WATCH_LIST_ALPHA", prevWatchListEnvValue)
 | 
					 | 
				
			||||||
		}()
 | 
							}()
 | 
				
			||||||
 | 
							clientfeatures.ReplaceFeatureGates(newEnabledWatchListClientFeatureGateRegistry(prevClientFeatureGates))
 | 
				
			||||||
		stopCh := make(chan struct{})
 | 
							stopCh := make(chan struct{})
 | 
				
			||||||
		defer close(stopCh)
 | 
							defer close(stopCh)
 | 
				
			||||||
		secretInformer := cache.NewSharedIndexInformer(
 | 
							secretInformer := cache.NewSharedIndexInformer(
 | 
				
			||||||
@@ -123,3 +121,18 @@ func newSecret(name string) *v1.Secret {
 | 
				
			|||||||
		ObjectMeta: metav1.ObjectMeta{Name: name},
 | 
							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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user