add DefaultComponentGlobalsRegistry flags in ServerRunOptions
Signed-off-by: Siyuan Zhang <sizhang@google.com> Kubernetes-commit: 379676c4bef48e5d2add28851302b55b41fcabcf
This commit is contained in:
parent
00857ca9ec
commit
b26fefe178
|
@ -832,7 +832,7 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
|
|||
muxAndDiscoveryCompleteSignals: map[string]<-chan struct{}{},
|
||||
}
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
||||
if c.FeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
||||
manager := c.AggregatedDiscoveryGroupManager
|
||||
if manager == nil {
|
||||
manager = discoveryendpoint.NewResourceManager("apis")
|
||||
|
@ -1047,14 +1047,14 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
|
|||
handler = genericfilters.WithRetryAfter(handler, c.lifecycleSignals.NotAcceptingNewRequest.Signaled())
|
||||
}
|
||||
handler = genericfilters.WithHTTPLogging(handler)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerTracing) {
|
||||
if c.FeatureGate.Enabled(genericfeatures.APIServerTracing) {
|
||||
handler = genericapifilters.WithTracing(handler, c.TracerProvider)
|
||||
}
|
||||
handler = genericapifilters.WithLatencyTrackers(handler)
|
||||
// WithRoutine will execute future handlers in a separate goroutine and serving
|
||||
// handler in current goroutine to minimize the stack memory usage. It must be
|
||||
// after WithPanicRecover() to be protected from panics.
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServingWithRoutine) {
|
||||
if c.FeatureGate.Enabled(genericfeatures.APIServingWithRoutine) {
|
||||
handler = genericfilters.WithRoutine(handler, c.LongRunningFunc)
|
||||
}
|
||||
handler = genericapifilters.WithRequestInfo(handler, c.RequestInfoResolver)
|
||||
|
@ -1098,7 +1098,7 @@ func installAPI(s *GenericAPIServer, c *Config) {
|
|||
routes.Version{Version: c.EffectiveVersion.BinaryVersion().Info()}.Install(s.Handler.GoRestfulContainer)
|
||||
|
||||
if c.EnableDiscovery {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
||||
if c.FeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
||||
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)
|
||||
s.Handler.GoRestfulContainer.Add(wrapped.GenerateWebService("/apis", metav1.APIGroupList{}))
|
||||
} else {
|
||||
|
|
|
@ -40,6 +40,7 @@ import (
|
|||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/server/healthz"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
|
@ -308,6 +309,7 @@ func TestAuthenticationAuditAnnotationsDefaultChain(t *testing.T) {
|
|||
LongRunningFunc: func(_ *http.Request, _ *request.RequestInfo) bool { return false },
|
||||
lifecycleSignals: newLifecycleSignals(),
|
||||
TracerProvider: tracing.NewNoopTracerProvider(),
|
||||
FeatureGate: utilfeature.DefaultFeatureGate,
|
||||
}
|
||||
|
||||
h := DefaultBuildHandlerChain(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -51,7 +51,6 @@ import (
|
|||
"k8s.io/apiserver/pkg/server/healthz"
|
||||
"k8s.io/apiserver/pkg/server/routes"
|
||||
"k8s.io/apiserver/pkg/storageversion"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/component-base/featuregate"
|
||||
|
@ -780,7 +779,7 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A
|
|||
}
|
||||
resourceInfos = append(resourceInfos, r...)
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.AggregatedDiscoveryEndpoint) {
|
||||
if s.FeatureGate.Enabled(features.AggregatedDiscoveryEndpoint) {
|
||||
// Aggregated discovery only aggregates resources under /apis
|
||||
if apiPrefix == APIGroupPrefix {
|
||||
s.AggregatedDiscoveryGroupManager.AddGroupVersion(
|
||||
|
@ -808,8 +807,8 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A
|
|||
|
||||
s.RegisterDestroyFunc(apiGroupInfo.destroyStorage)
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.StorageVersionAPI) &&
|
||||
utilfeature.DefaultFeatureGate.Enabled(features.APIServerIdentity) {
|
||||
if s.FeatureGate.Enabled(features.StorageVersionAPI) &&
|
||||
s.FeatureGate.Enabled(features.APIServerIdentity) {
|
||||
// API installation happens before we start listening on the handlers,
|
||||
// therefore it is safe to register ResourceInfos here. The handler will block
|
||||
// write requests until the storage versions of the targeting resources are updated.
|
||||
|
@ -839,7 +838,7 @@ func (s *GenericAPIServer) InstallLegacyAPIGroup(apiPrefix string, apiGroupInfo
|
|||
// Install the version handler.
|
||||
// Add a handler at /<apiPrefix> to enumerate the supported api versions.
|
||||
legacyRootAPIHandler := discovery.NewLegacyRootAPIHandler(s.discoveryAddresses, s.Serializer, apiPrefix)
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.AggregatedDiscoveryEndpoint) {
|
||||
if s.FeatureGate.Enabled(features.AggregatedDiscoveryEndpoint) {
|
||||
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(legacyRootAPIHandler, s.AggregatedLegacyDiscoveryGroupManager)
|
||||
s.Handler.GoRestfulContainer.Add(wrapped.GenerateWebService("/api", metav1.APIVersions{}))
|
||||
} else {
|
||||
|
|
|
@ -33,7 +33,6 @@ func (f fakeGroupRegistry) IsGroupRegistered(group string) bool {
|
|||
func TestAPIEnablementOptionsValidate(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
testOptions *APIEnablementOptions
|
||||
runtimeConfig cliflag.ConfigurationMap
|
||||
expectErr string
|
||||
}{
|
||||
|
|
|
@ -25,9 +25,10 @@ import (
|
|||
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/apimachinery/pkg/util/errors"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apiserver/pkg/server"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||
"k8s.io/component-base/featuregate"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
@ -91,12 +92,23 @@ type ServerRunOptions struct {
|
|||
// it is not overridden by any other grace period.
|
||||
ShutdownWatchTerminationGracePeriod time.Duration
|
||||
|
||||
// FeatureGate are the featuregate to install on the CLI
|
||||
FeatureGate featuregate.FeatureGate
|
||||
EffectiveVersion utilversion.EffectiveVersion
|
||||
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
|
||||
ComponentGlobalsRegistry utilversion.ComponentGlobalsRegistry
|
||||
// ComponentName is name under which the server's global variabled are registered in the ComponentGlobalsRegistry.
|
||||
ComponentName string
|
||||
}
|
||||
|
||||
func NewServerRunOptions(featureGate featuregate.FeatureGate, effectiveVersion utilversion.EffectiveVersion) *ServerRunOptions {
|
||||
func NewServerRunOptions() *ServerRunOptions {
|
||||
if utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent) == nil {
|
||||
featureGate := utilfeature.DefaultMutableFeatureGate
|
||||
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
}
|
||||
|
||||
return NewServerRunOptionsForComponent(utilversion.DefaultKubeComponent, utilversion.DefaultComponentGlobalsRegistry)
|
||||
}
|
||||
|
||||
func NewServerRunOptionsForComponent(componentName string, componentGlobalsRegistry utilversion.ComponentGlobalsRegistry) *ServerRunOptions {
|
||||
defaults := server.NewConfig(serializer.CodecFactory{})
|
||||
return &ServerRunOptions{
|
||||
MaxRequestsInFlight: defaults.MaxRequestsInFlight,
|
||||
|
@ -109,13 +121,16 @@ func NewServerRunOptions(featureGate featuregate.FeatureGate, effectiveVersion u
|
|||
JSONPatchMaxCopyBytes: defaults.JSONPatchMaxCopyBytes,
|
||||
MaxRequestBodyBytes: defaults.MaxRequestBodyBytes,
|
||||
ShutdownSendRetryAfter: false,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentName: componentName,
|
||||
ComponentGlobalsRegistry: componentGlobalsRegistry,
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyTo applies the run options to the method receiver and returns self
|
||||
func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
|
||||
if err := s.ComponentGlobalsRegistry.SetFallback(); err != nil {
|
||||
return err
|
||||
}
|
||||
c.CorsAllowedOriginList = s.CorsAllowedOriginList
|
||||
c.HSTSDirectives = s.HSTSDirectives
|
||||
c.ExternalAddress = s.ExternalHost
|
||||
|
@ -131,8 +146,8 @@ func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
|
|||
c.PublicAddress = s.AdvertiseAddress
|
||||
c.ShutdownSendRetryAfter = s.ShutdownSendRetryAfter
|
||||
c.ShutdownWatchTerminationGracePeriod = s.ShutdownWatchTerminationGracePeriod
|
||||
c.EffectiveVersion = s.EffectiveVersion
|
||||
c.FeatureGate = s.FeatureGate
|
||||
c.EffectiveVersion = s.ComponentGlobalsRegistry.EffectiveVersionFor(s.ComponentName)
|
||||
c.FeatureGate = s.ComponentGlobalsRegistry.FeatureGateFor(s.ComponentName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -205,12 +220,7 @@ func (s *ServerRunOptions) Validate() []error {
|
|||
if err := validateCorsAllowedOriginList(s.CorsAllowedOriginList); err != nil {
|
||||
errors = append(errors, err)
|
||||
}
|
||||
if s.FeatureGate != nil {
|
||||
if errs := s.FeatureGate.Validate(); len(errs) != 0 {
|
||||
errors = append(errors, errs...)
|
||||
}
|
||||
}
|
||||
if errs := s.EffectiveVersion.Validate(); len(errs) != 0 {
|
||||
if errs := s.ComponentGlobalsRegistry.Validate(); len(errs) != 0 {
|
||||
errors = append(errors, errs...)
|
||||
}
|
||||
return errors
|
||||
|
@ -353,15 +363,11 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
|
|||
fs.DurationVar(&s.ShutdownWatchTerminationGracePeriod, "shutdown-watch-termination-grace-period", s.ShutdownWatchTerminationGracePeriod, ""+
|
||||
"This option, if set, represents the maximum amount of grace period the apiserver will wait "+
|
||||
"for active watch request(s) to drain during the graceful server shutdown window.")
|
||||
|
||||
s.ComponentGlobalsRegistry.AddFlags(fs)
|
||||
}
|
||||
|
||||
// Complete fills missing fields with defaults.
|
||||
func (s *ServerRunOptions) Complete() error {
|
||||
if s.FeatureGate == nil {
|
||||
return fmt.Errorf("nil FeatureGate in ServerRunOptions")
|
||||
}
|
||||
if s.EffectiveVersion == nil {
|
||||
return fmt.Errorf("nil EffectiveVersion in ServerRunOptions")
|
||||
}
|
||||
return nil
|
||||
return s.ComponentGlobalsRegistry.SetFallback()
|
||||
}
|
||||
|
|
|
@ -23,14 +23,21 @@ import (
|
|||
"time"
|
||||
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
func TestServerRunOptionsValidate(t *testing.T) {
|
||||
testRegistry := utilversion.NewComponentGlobalsRegistry()
|
||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
||||
effectiveVersion.SetEmulationVersion(version.MajorMinor(1, 32))
|
||||
testComponent := "test"
|
||||
utilruntime.Must(testRegistry.Register(testComponent, effectiveVersion, featureGate))
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
testOptions *ServerRunOptions
|
||||
|
@ -47,8 +54,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--max-requests-inflight can not be negative value",
|
||||
},
|
||||
|
@ -63,8 +69,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--max-mutating-requests-inflight can not be negative value",
|
||||
},
|
||||
|
@ -79,8 +84,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--request-timeout can not be negative value",
|
||||
},
|
||||
|
@ -95,8 +99,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: -1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--min-request-timeout can not be negative value",
|
||||
},
|
||||
|
@ -111,8 +114,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: -10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "ServerRunOptions.JSONPatchMaxCopyBytes can not be negative value",
|
||||
},
|
||||
|
@ -127,8 +129,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: -10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "ServerRunOptions.MaxRequestBodyBytes can not be negative value",
|
||||
},
|
||||
|
@ -144,8 +145,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
LivezGracePeriod: -time.Second,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--livez-grace-period can not be a negative value",
|
||||
},
|
||||
|
@ -161,8 +161,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ShutdownDelayDuration: -time.Second,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--shutdown-delay-duration can not be negative value",
|
||||
},
|
||||
|
@ -178,11 +177,27 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--strict-transport-security-directives invalid, allowed values: max-age=expireTime, includeSubDomains, preload. see https://tools.ietf.org/html/rfc6797#section-6.1 for more information",
|
||||
},
|
||||
{
|
||||
name: "Test when emulation version is invalid",
|
||||
testOptions: &ServerRunOptions{
|
||||
AdvertiseAddress: netutils.ParseIPSloppy("192.168.10.10"),
|
||||
CorsAllowedOriginList: []string{"^10.10.10.100$", "^10.10.10.200$"},
|
||||
HSTSDirectives: []string{"max-age=31536000", "includeSubDomains", "preload"},
|
||||
MaxRequestsInFlight: 400,
|
||||
MaxMutatingRequestsInFlight: 200,
|
||||
RequestTimeout: time.Duration(2) * time.Minute,
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentName: testComponent,
|
||||
ComponentGlobalsRegistry: testRegistry,
|
||||
},
|
||||
expectErr: "emulation version 1.32 is not between [1.29, 1.30.0]",
|
||||
},
|
||||
{
|
||||
name: "Test when ServerRunOptions is valid",
|
||||
testOptions: &ServerRunOptions{
|
||||
|
@ -195,8 +210,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
FeatureGate: featureGate,
|
||||
EffectiveVersion: effectiveVersion,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -216,8 +230,6 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestValidateCorsAllowedOriginList(t *testing.T) {
|
||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
||||
tests := []struct {
|
||||
regexp [][]string
|
||||
errShouldContain string
|
||||
|
@ -265,7 +277,7 @@ func TestValidateCorsAllowedOriginList(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
for _, regexp := range test.regexp {
|
||||
t.Run(fmt.Sprintf("regexp/%s", regexp), func(t *testing.T) {
|
||||
options := NewServerRunOptions(featureGate, effectiveVersion)
|
||||
options := NewServerRunOptions()
|
||||
if errs := options.Validate(); len(errs) != 0 {
|
||||
t.Fatalf("wrong test setup: %#v", errs)
|
||||
}
|
||||
|
@ -289,8 +301,6 @@ func TestValidateCorsAllowedOriginList(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
||||
tests := []struct {
|
||||
name string
|
||||
optionsFn func() *ServerRunOptions
|
||||
|
@ -299,13 +309,13 @@ func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
|||
{
|
||||
name: "default should be valid",
|
||||
optionsFn: func() *ServerRunOptions {
|
||||
return NewServerRunOptions(featureGate, effectiveVersion)
|
||||
return NewServerRunOptions()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "negative not allowed",
|
||||
optionsFn: func() *ServerRunOptions {
|
||||
o := NewServerRunOptions(featureGate, effectiveVersion)
|
||||
o := NewServerRunOptions()
|
||||
o.ShutdownWatchTerminationGracePeriod = -time.Second
|
||||
return o
|
||||
},
|
||||
|
@ -332,7 +342,7 @@ func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("default should be zero", func(t *testing.T) {
|
||||
options := NewServerRunOptions(featureGate, effectiveVersion)
|
||||
options := NewServerRunOptions()
|
||||
if options.ShutdownWatchTerminationGracePeriod != time.Duration(0) {
|
||||
t.Errorf("expected default of ShutdownWatchTerminationGracePeriod to be zero, but got: %s", options.ShutdownWatchTerminationGracePeriod)
|
||||
}
|
||||
|
|
|
@ -181,9 +181,9 @@ func emulatedStorageVersion(binaryVersionOfResource schema.GroupVersion, example
|
|||
// was being served which didn't exist at all in min-compatibility-version.
|
||||
//
|
||||
// In the alpha case - we do not support compatibility versioning of
|
||||
// alpha types and recommend users do not mix the two.
|
||||
// alpha types and recommend users do not mix the two.
|
||||
// In the skip-level case - The version of apiserver we are retaining
|
||||
// compatibility with has no knowledge of the type,
|
||||
// so storing it in another type is no issue.
|
||||
// compatibility with has no knowledge of the type,
|
||||
// so storing it in another type is no issue.
|
||||
return binaryVersionOfResource, nil
|
||||
}
|
||||
|
|
|
@ -101,6 +101,8 @@ type ComponentGlobalsRegistry interface {
|
|||
AddFlags(fs *pflag.FlagSet)
|
||||
// Set sets the flags for all global variables for all components registered.
|
||||
Set() error
|
||||
// SetFallback calls Set() if it has never been called.
|
||||
SetFallback() error
|
||||
// Validate calls the Validate() function for all the global variables for all components registered.
|
||||
Validate() []error
|
||||
// Reset removes all stored ComponentGlobals, configurations, and version mappings.
|
||||
|
@ -120,6 +122,8 @@ type componentGlobalsRegistry struct {
|
|||
emulationVersionConfig []string
|
||||
// map of component name to the list of feature gates set from the flag.
|
||||
featureGatesConfig map[string][]string
|
||||
// set stores if the Set() function for the registry is already called.
|
||||
set bool
|
||||
}
|
||||
|
||||
func NewComponentGlobalsRegistry() *componentGlobalsRegistry {
|
||||
|
@ -136,6 +140,7 @@ func (r *componentGlobalsRegistry) Reset() {
|
|||
r.componentGlobals = make(map[string]*ComponentGlobals)
|
||||
r.emulationVersionConfig = nil
|
||||
r.featureGatesConfig = nil
|
||||
r.set = false
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) EffectiveVersionFor(component string) EffectiveVersion {
|
||||
|
@ -330,9 +335,22 @@ func toVersionMap(versionConfig []string) (map[string]*version.Version, error) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) SetFallback() error {
|
||||
r.mutex.Lock()
|
||||
set := r.set
|
||||
r.mutex.Unlock()
|
||||
if set {
|
||||
return nil
|
||||
}
|
||||
klog.Warning("setting componentGlobalsRegistry in SetFallback. We recommend calling componentGlobalsRegistry.Set()" +
|
||||
" right after parsing flags to avoid using feature gates before their final values are set by the flags.")
|
||||
return r.Set()
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) Set() error {
|
||||
r.mutex.Lock()
|
||||
defer r.mutex.Unlock()
|
||||
r.set = true
|
||||
emulationVersionConfigMap, err := toVersionMap(r.emulationVersionConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -111,12 +111,6 @@ func (m *effectiveVersion) Validate() []error {
|
|||
// emulationVersion can only be 1.{binaryMinor-1}...1.{binaryMinor}.
|
||||
maxEmuVer := binaryVersion
|
||||
minEmuVer := binaryVersion.SubtractMinor(1)
|
||||
// TODO: remove in 1.32
|
||||
// emulationVersion is introduced in 1.31, so it cannot be lower than that.
|
||||
// binaryVersion could be lower than 1.31 in tests. So we are only checking 1.31.
|
||||
if binaryVersion.EqualTo(version.MajorMinor(1, 31)) {
|
||||
minEmuVer = version.MajorMinor(1, 31)
|
||||
}
|
||||
if emulationVersion.GreaterThan(maxEmuVer) || emulationVersion.LessThan(minEmuVer) {
|
||||
errs = append(errs, fmt.Errorf("emulation version %s is not between [%s, %s]", emulationVersion.String(), minEmuVer.String(), maxEmuVer.String()))
|
||||
}
|
||||
|
@ -157,8 +151,7 @@ func DefaultBuildEffectiveVersion() MutableEffectiveVersion {
|
|||
|
||||
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||
// latest K8s release.
|
||||
// Should update for each minor release!
|
||||
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
||||
binaryVersion := version.MustParse("1.31").WithInfo(baseversion.Get())
|
||||
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
|
||||
return newEffectiveVersion(binaryVersion)
|
||||
}
|
||||
|
|
|
@ -42,25 +42,6 @@ func TestValidate(t *testing.T) {
|
|||
emulationVersion: "v1.31.0",
|
||||
minCompatibilityVersion: "v1.31.0",
|
||||
},
|
||||
{
|
||||
name: "binary version 1.31, emulation version lower than 1.31",
|
||||
binaryVersion: "v1.31.2",
|
||||
emulationVersion: "v1.30.0",
|
||||
minCompatibilityVersion: "v1.30.0",
|
||||
expectErrors: true,
|
||||
},
|
||||
{
|
||||
name: "binary version 1.31, emulation version 1.31",
|
||||
binaryVersion: "v1.31.2",
|
||||
emulationVersion: "v1.31.0",
|
||||
minCompatibilityVersion: "v1.30.0",
|
||||
},
|
||||
{
|
||||
name: "binary version lower than 1.31",
|
||||
binaryVersion: "v1.30.2",
|
||||
emulationVersion: "v1.29.0",
|
||||
minCompatibilityVersion: "v1.29.0",
|
||||
},
|
||||
{
|
||||
name: "emulation version two minor lower than binary not ok",
|
||||
binaryVersion: "v1.33.2",
|
||||
|
|
Loading…
Reference in New Issue