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{}{},
|
muxAndDiscoveryCompleteSignals: map[string]<-chan struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
if c.FeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
||||||
manager := c.AggregatedDiscoveryGroupManager
|
manager := c.AggregatedDiscoveryGroupManager
|
||||||
if manager == nil {
|
if manager == nil {
|
||||||
manager = discoveryendpoint.NewResourceManager("apis")
|
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.WithRetryAfter(handler, c.lifecycleSignals.NotAcceptingNewRequest.Signaled())
|
||||||
}
|
}
|
||||||
handler = genericfilters.WithHTTPLogging(handler)
|
handler = genericfilters.WithHTTPLogging(handler)
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerTracing) {
|
if c.FeatureGate.Enabled(genericfeatures.APIServerTracing) {
|
||||||
handler = genericapifilters.WithTracing(handler, c.TracerProvider)
|
handler = genericapifilters.WithTracing(handler, c.TracerProvider)
|
||||||
}
|
}
|
||||||
handler = genericapifilters.WithLatencyTrackers(handler)
|
handler = genericapifilters.WithLatencyTrackers(handler)
|
||||||
// WithRoutine will execute future handlers in a separate goroutine and serving
|
// WithRoutine will execute future handlers in a separate goroutine and serving
|
||||||
// handler in current goroutine to minimize the stack memory usage. It must be
|
// handler in current goroutine to minimize the stack memory usage. It must be
|
||||||
// after WithPanicRecover() to be protected from panics.
|
// 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 = genericfilters.WithRoutine(handler, c.LongRunningFunc)
|
||||||
}
|
}
|
||||||
handler = genericapifilters.WithRequestInfo(handler, c.RequestInfoResolver)
|
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)
|
routes.Version{Version: c.EffectiveVersion.BinaryVersion().Info()}.Install(s.Handler.GoRestfulContainer)
|
||||||
|
|
||||||
if c.EnableDiscovery {
|
if c.EnableDiscovery {
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
if c.FeatureGate.Enabled(genericfeatures.AggregatedDiscoveryEndpoint) {
|
||||||
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)
|
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(s.DiscoveryGroupManager, s.AggregatedDiscoveryGroupManager)
|
||||||
s.Handler.GoRestfulContainer.Add(wrapped.GenerateWebService("/apis", metav1.APIGroupList{}))
|
s.Handler.GoRestfulContainer.Add(wrapped.GenerateWebService("/apis", metav1.APIGroupList{}))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import (
|
||||||
"k8s.io/apiserver/pkg/authentication/user"
|
"k8s.io/apiserver/pkg/authentication/user"
|
||||||
"k8s.io/apiserver/pkg/endpoints/request"
|
"k8s.io/apiserver/pkg/endpoints/request"
|
||||||
"k8s.io/apiserver/pkg/server/healthz"
|
"k8s.io/apiserver/pkg/server/healthz"
|
||||||
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
|
|
@ -308,6 +309,7 @@ func TestAuthenticationAuditAnnotationsDefaultChain(t *testing.T) {
|
||||||
LongRunningFunc: func(_ *http.Request, _ *request.RequestInfo) bool { return false },
|
LongRunningFunc: func(_ *http.Request, _ *request.RequestInfo) bool { return false },
|
||||||
lifecycleSignals: newLifecycleSignals(),
|
lifecycleSignals: newLifecycleSignals(),
|
||||||
TracerProvider: tracing.NewNoopTracerProvider(),
|
TracerProvider: tracing.NewNoopTracerProvider(),
|
||||||
|
FeatureGate: utilfeature.DefaultFeatureGate,
|
||||||
}
|
}
|
||||||
|
|
||||||
h := DefaultBuildHandlerChain(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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/healthz"
|
||||||
"k8s.io/apiserver/pkg/server/routes"
|
"k8s.io/apiserver/pkg/server/routes"
|
||||||
"k8s.io/apiserver/pkg/storageversion"
|
"k8s.io/apiserver/pkg/storageversion"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
|
||||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/component-base/featuregate"
|
"k8s.io/component-base/featuregate"
|
||||||
|
|
@ -780,7 +779,7 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A
|
||||||
}
|
}
|
||||||
resourceInfos = append(resourceInfos, r...)
|
resourceInfos = append(resourceInfos, r...)
|
||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.AggregatedDiscoveryEndpoint) {
|
if s.FeatureGate.Enabled(features.AggregatedDiscoveryEndpoint) {
|
||||||
// Aggregated discovery only aggregates resources under /apis
|
// Aggregated discovery only aggregates resources under /apis
|
||||||
if apiPrefix == APIGroupPrefix {
|
if apiPrefix == APIGroupPrefix {
|
||||||
s.AggregatedDiscoveryGroupManager.AddGroupVersion(
|
s.AggregatedDiscoveryGroupManager.AddGroupVersion(
|
||||||
|
|
@ -808,8 +807,8 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A
|
||||||
|
|
||||||
s.RegisterDestroyFunc(apiGroupInfo.destroyStorage)
|
s.RegisterDestroyFunc(apiGroupInfo.destroyStorage)
|
||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.StorageVersionAPI) &&
|
if s.FeatureGate.Enabled(features.StorageVersionAPI) &&
|
||||||
utilfeature.DefaultFeatureGate.Enabled(features.APIServerIdentity) {
|
s.FeatureGate.Enabled(features.APIServerIdentity) {
|
||||||
// API installation happens before we start listening on the handlers,
|
// API installation happens before we start listening on the handlers,
|
||||||
// therefore it is safe to register ResourceInfos here. The handler will block
|
// therefore it is safe to register ResourceInfos here. The handler will block
|
||||||
// write requests until the storage versions of the targeting resources are updated.
|
// 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.
|
// Install the version handler.
|
||||||
// Add a handler at /<apiPrefix> to enumerate the supported api versions.
|
// Add a handler at /<apiPrefix> to enumerate the supported api versions.
|
||||||
legacyRootAPIHandler := discovery.NewLegacyRootAPIHandler(s.discoveryAddresses, s.Serializer, apiPrefix)
|
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)
|
wrapped := discoveryendpoint.WrapAggregatedDiscoveryToHandler(legacyRootAPIHandler, s.AggregatedLegacyDiscoveryGroupManager)
|
||||||
s.Handler.GoRestfulContainer.Add(wrapped.GenerateWebService("/api", metav1.APIVersions{}))
|
s.Handler.GoRestfulContainer.Add(wrapped.GenerateWebService("/api", metav1.APIVersions{}))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ func (f fakeGroupRegistry) IsGroupRegistered(group string) bool {
|
||||||
func TestAPIEnablementOptionsValidate(t *testing.T) {
|
func TestAPIEnablementOptionsValidate(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
testOptions *APIEnablementOptions
|
|
||||||
runtimeConfig cliflag.ConfigurationMap
|
runtimeConfig cliflag.ConfigurationMap
|
||||||
expectErr string
|
expectErr string
|
||||||
}{
|
}{
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,10 @@ import (
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
"k8s.io/apimachinery/pkg/util/errors"
|
"k8s.io/apimachinery/pkg/util/errors"
|
||||||
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apiserver/pkg/server"
|
"k8s.io/apiserver/pkg/server"
|
||||||
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||||
"k8s.io/component-base/featuregate"
|
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
@ -91,12 +92,23 @@ type ServerRunOptions struct {
|
||||||
// it is not overridden by any other grace period.
|
// it is not overridden by any other grace period.
|
||||||
ShutdownWatchTerminationGracePeriod time.Duration
|
ShutdownWatchTerminationGracePeriod time.Duration
|
||||||
|
|
||||||
// FeatureGate are the featuregate to install on the CLI
|
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
|
||||||
FeatureGate featuregate.FeatureGate
|
ComponentGlobalsRegistry utilversion.ComponentGlobalsRegistry
|
||||||
EffectiveVersion utilversion.EffectiveVersion
|
// 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{})
|
defaults := server.NewConfig(serializer.CodecFactory{})
|
||||||
return &ServerRunOptions{
|
return &ServerRunOptions{
|
||||||
MaxRequestsInFlight: defaults.MaxRequestsInFlight,
|
MaxRequestsInFlight: defaults.MaxRequestsInFlight,
|
||||||
|
|
@ -109,13 +121,16 @@ func NewServerRunOptions(featureGate featuregate.FeatureGate, effectiveVersion u
|
||||||
JSONPatchMaxCopyBytes: defaults.JSONPatchMaxCopyBytes,
|
JSONPatchMaxCopyBytes: defaults.JSONPatchMaxCopyBytes,
|
||||||
MaxRequestBodyBytes: defaults.MaxRequestBodyBytes,
|
MaxRequestBodyBytes: defaults.MaxRequestBodyBytes,
|
||||||
ShutdownSendRetryAfter: false,
|
ShutdownSendRetryAfter: false,
|
||||||
FeatureGate: featureGate,
|
ComponentName: componentName,
|
||||||
EffectiveVersion: effectiveVersion,
|
ComponentGlobalsRegistry: componentGlobalsRegistry,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyTo applies the run options to the method receiver and returns self
|
// ApplyTo applies the run options to the method receiver and returns self
|
||||||
func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
|
func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
|
||||||
|
if err := s.ComponentGlobalsRegistry.SetFallback(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
c.CorsAllowedOriginList = s.CorsAllowedOriginList
|
c.CorsAllowedOriginList = s.CorsAllowedOriginList
|
||||||
c.HSTSDirectives = s.HSTSDirectives
|
c.HSTSDirectives = s.HSTSDirectives
|
||||||
c.ExternalAddress = s.ExternalHost
|
c.ExternalAddress = s.ExternalHost
|
||||||
|
|
@ -131,8 +146,8 @@ func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
|
||||||
c.PublicAddress = s.AdvertiseAddress
|
c.PublicAddress = s.AdvertiseAddress
|
||||||
c.ShutdownSendRetryAfter = s.ShutdownSendRetryAfter
|
c.ShutdownSendRetryAfter = s.ShutdownSendRetryAfter
|
||||||
c.ShutdownWatchTerminationGracePeriod = s.ShutdownWatchTerminationGracePeriod
|
c.ShutdownWatchTerminationGracePeriod = s.ShutdownWatchTerminationGracePeriod
|
||||||
c.EffectiveVersion = s.EffectiveVersion
|
c.EffectiveVersion = s.ComponentGlobalsRegistry.EffectiveVersionFor(s.ComponentName)
|
||||||
c.FeatureGate = s.FeatureGate
|
c.FeatureGate = s.ComponentGlobalsRegistry.FeatureGateFor(s.ComponentName)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -205,12 +220,7 @@ func (s *ServerRunOptions) Validate() []error {
|
||||||
if err := validateCorsAllowedOriginList(s.CorsAllowedOriginList); err != nil {
|
if err := validateCorsAllowedOriginList(s.CorsAllowedOriginList); err != nil {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
}
|
}
|
||||||
if s.FeatureGate != nil {
|
if errs := s.ComponentGlobalsRegistry.Validate(); len(errs) != 0 {
|
||||||
if errs := s.FeatureGate.Validate(); len(errs) != 0 {
|
|
||||||
errors = append(errors, errs...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if errs := s.EffectiveVersion.Validate(); len(errs) != 0 {
|
|
||||||
errors = append(errors, errs...)
|
errors = append(errors, errs...)
|
||||||
}
|
}
|
||||||
return errors
|
return errors
|
||||||
|
|
@ -353,15 +363,11 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
|
||||||
fs.DurationVar(&s.ShutdownWatchTerminationGracePeriod, "shutdown-watch-termination-grace-period", s.ShutdownWatchTerminationGracePeriod, ""+
|
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 "+
|
"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.")
|
"for active watch request(s) to drain during the graceful server shutdown window.")
|
||||||
|
|
||||||
|
s.ComponentGlobalsRegistry.AddFlags(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete fills missing fields with defaults.
|
// Complete fills missing fields with defaults.
|
||||||
func (s *ServerRunOptions) Complete() error {
|
func (s *ServerRunOptions) Complete() error {
|
||||||
if s.FeatureGate == nil {
|
return s.ComponentGlobalsRegistry.SetFallback()
|
||||||
return fmt.Errorf("nil FeatureGate in ServerRunOptions")
|
|
||||||
}
|
|
||||||
if s.EffectiveVersion == nil {
|
|
||||||
return fmt.Errorf("nil EffectiveVersion in ServerRunOptions")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,21 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
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"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||||
netutils "k8s.io/utils/net"
|
netutils "k8s.io/utils/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerRunOptionsValidate(t *testing.T) {
|
func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
|
testRegistry := utilversion.NewComponentGlobalsRegistry()
|
||||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
||||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
||||||
|
effectiveVersion.SetEmulationVersion(version.MajorMinor(1, 32))
|
||||||
|
testComponent := "test"
|
||||||
|
utilruntime.Must(testRegistry.Register(testComponent, effectiveVersion, featureGate))
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
testOptions *ServerRunOptions
|
testOptions *ServerRunOptions
|
||||||
|
|
@ -47,8 +54,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "--max-requests-inflight can not be negative value",
|
expectErr: "--max-requests-inflight can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -63,8 +69,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "--max-mutating-requests-inflight can not be negative value",
|
expectErr: "--max-mutating-requests-inflight can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -79,8 +84,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "--request-timeout can not be negative value",
|
expectErr: "--request-timeout can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -95,8 +99,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: -1800,
|
MinRequestTimeout: -1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "--min-request-timeout can not be negative value",
|
expectErr: "--min-request-timeout can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -111,8 +114,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: -10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: -10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "ServerRunOptions.JSONPatchMaxCopyBytes can not be negative value",
|
expectErr: "ServerRunOptions.JSONPatchMaxCopyBytes can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -127,8 +129,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: -10 * 1024 * 1024,
|
MaxRequestBodyBytes: -10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "ServerRunOptions.MaxRequestBodyBytes can not be negative value",
|
expectErr: "ServerRunOptions.MaxRequestBodyBytes can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -144,8 +145,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
LivezGracePeriod: -time.Second,
|
LivezGracePeriod: -time.Second,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "--livez-grace-period can not be a negative value",
|
expectErr: "--livez-grace-period can not be a negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -161,8 +161,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
ShutdownDelayDuration: -time.Second,
|
ShutdownDelayDuration: -time.Second,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
expectErr: "--shutdown-delay-duration can not be negative value",
|
expectErr: "--shutdown-delay-duration can not be negative value",
|
||||||
},
|
},
|
||||||
|
|
@ -178,11 +177,27 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
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",
|
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",
|
name: "Test when ServerRunOptions is valid",
|
||||||
testOptions: &ServerRunOptions{
|
testOptions: &ServerRunOptions{
|
||||||
|
|
@ -195,8 +210,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
MinRequestTimeout: 1800,
|
MinRequestTimeout: 1800,
|
||||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||||
FeatureGate: featureGate,
|
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||||
EffectiveVersion: effectiveVersion,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -216,8 +230,6 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateCorsAllowedOriginList(t *testing.T) {
|
func TestValidateCorsAllowedOriginList(t *testing.T) {
|
||||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
|
||||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
regexp [][]string
|
regexp [][]string
|
||||||
errShouldContain string
|
errShouldContain string
|
||||||
|
|
@ -265,7 +277,7 @@ func TestValidateCorsAllowedOriginList(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
for _, regexp := range test.regexp {
|
for _, regexp := range test.regexp {
|
||||||
t.Run(fmt.Sprintf("regexp/%s", regexp), func(t *testing.T) {
|
t.Run(fmt.Sprintf("regexp/%s", regexp), func(t *testing.T) {
|
||||||
options := NewServerRunOptions(featureGate, effectiveVersion)
|
options := NewServerRunOptions()
|
||||||
if errs := options.Validate(); len(errs) != 0 {
|
if errs := options.Validate(); len(errs) != 0 {
|
||||||
t.Fatalf("wrong test setup: %#v", errs)
|
t.Fatalf("wrong test setup: %#v", errs)
|
||||||
}
|
}
|
||||||
|
|
@ -289,8 +301,6 @@ func TestValidateCorsAllowedOriginList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
||||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
|
||||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
optionsFn func() *ServerRunOptions
|
optionsFn func() *ServerRunOptions
|
||||||
|
|
@ -299,13 +309,13 @@ func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "default should be valid",
|
name: "default should be valid",
|
||||||
optionsFn: func() *ServerRunOptions {
|
optionsFn: func() *ServerRunOptions {
|
||||||
return NewServerRunOptions(featureGate, effectiveVersion)
|
return NewServerRunOptions()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "negative not allowed",
|
name: "negative not allowed",
|
||||||
optionsFn: func() *ServerRunOptions {
|
optionsFn: func() *ServerRunOptions {
|
||||||
o := NewServerRunOptions(featureGate, effectiveVersion)
|
o := NewServerRunOptions()
|
||||||
o.ShutdownWatchTerminationGracePeriod = -time.Second
|
o.ShutdownWatchTerminationGracePeriod = -time.Second
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
|
|
@ -332,7 +342,7 @@ func TestServerRunOptionsWithShutdownWatchTerminationGracePeriod(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("default should be zero", func(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) {
|
if options.ShutdownWatchTerminationGracePeriod != time.Duration(0) {
|
||||||
t.Errorf("expected default of ShutdownWatchTerminationGracePeriod to be zero, but got: %s", options.ShutdownWatchTerminationGracePeriod)
|
t.Errorf("expected default of ShutdownWatchTerminationGracePeriod to be zero, but got: %s", options.ShutdownWatchTerminationGracePeriod)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,8 @@ type ComponentGlobalsRegistry interface {
|
||||||
AddFlags(fs *pflag.FlagSet)
|
AddFlags(fs *pflag.FlagSet)
|
||||||
// Set sets the flags for all global variables for all components registered.
|
// Set sets the flags for all global variables for all components registered.
|
||||||
Set() error
|
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 calls the Validate() function for all the global variables for all components registered.
|
||||||
Validate() []error
|
Validate() []error
|
||||||
// Reset removes all stored ComponentGlobals, configurations, and version mappings.
|
// Reset removes all stored ComponentGlobals, configurations, and version mappings.
|
||||||
|
|
@ -120,6 +122,8 @@ type componentGlobalsRegistry struct {
|
||||||
emulationVersionConfig []string
|
emulationVersionConfig []string
|
||||||
// map of component name to the list of feature gates set from the flag.
|
// map of component name to the list of feature gates set from the flag.
|
||||||
featureGatesConfig map[string][]string
|
featureGatesConfig map[string][]string
|
||||||
|
// set stores if the Set() function for the registry is already called.
|
||||||
|
set bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewComponentGlobalsRegistry() *componentGlobalsRegistry {
|
func NewComponentGlobalsRegistry() *componentGlobalsRegistry {
|
||||||
|
|
@ -136,6 +140,7 @@ func (r *componentGlobalsRegistry) Reset() {
|
||||||
r.componentGlobals = make(map[string]*ComponentGlobals)
|
r.componentGlobals = make(map[string]*ComponentGlobals)
|
||||||
r.emulationVersionConfig = nil
|
r.emulationVersionConfig = nil
|
||||||
r.featureGatesConfig = nil
|
r.featureGatesConfig = nil
|
||||||
|
r.set = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *componentGlobalsRegistry) EffectiveVersionFor(component string) EffectiveVersion {
|
func (r *componentGlobalsRegistry) EffectiveVersionFor(component string) EffectiveVersion {
|
||||||
|
|
@ -330,9 +335,22 @@ func toVersionMap(versionConfig []string) (map[string]*version.Version, error) {
|
||||||
return m, nil
|
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 {
|
func (r *componentGlobalsRegistry) Set() error {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
r.set = true
|
||||||
emulationVersionConfigMap, err := toVersionMap(r.emulationVersionConfig)
|
emulationVersionConfigMap, err := toVersionMap(r.emulationVersionConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -111,12 +111,6 @@ func (m *effectiveVersion) Validate() []error {
|
||||||
// emulationVersion can only be 1.{binaryMinor-1}...1.{binaryMinor}.
|
// emulationVersion can only be 1.{binaryMinor-1}...1.{binaryMinor}.
|
||||||
maxEmuVer := binaryVersion
|
maxEmuVer := binaryVersion
|
||||||
minEmuVer := binaryVersion.SubtractMinor(1)
|
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) {
|
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()))
|
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
|
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||||
// latest K8s release.
|
// latest K8s release.
|
||||||
// Should update for each minor release!
|
|
||||||
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
||||||
binaryVersion := version.MustParse("1.31").WithInfo(baseversion.Get())
|
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
|
||||||
return newEffectiveVersion(binaryVersion)
|
return newEffectiveVersion(binaryVersion)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,25 +42,6 @@ func TestValidate(t *testing.T) {
|
||||||
emulationVersion: "v1.31.0",
|
emulationVersion: "v1.31.0",
|
||||||
minCompatibilityVersion: "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",
|
name: "emulation version two minor lower than binary not ok",
|
||||||
binaryVersion: "v1.33.2",
|
binaryVersion: "v1.33.2",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue