diff --git a/cmd/kube-apiserver/app/options/options.go b/cmd/kube-apiserver/app/options/options.go index 03c09a663e..ec6765e6eb 100644 --- a/cmd/kube-apiserver/app/options/options.go +++ b/cmd/kube-apiserver/app/options/options.go @@ -45,6 +45,7 @@ type ServerRunOptions struct { SecureServing *genericoptions.SecureServingOptions InsecureServing *genericoptions.ServingOptions Audit *genericoptions.AuditLogOptions + Features *genericoptions.FeatureOptions Authentication *kubeoptions.BuiltInAuthenticationOptions Authorization *kubeoptions.BuiltInAuthorizationOptions CloudProvider *kubeoptions.CloudProviderOptions @@ -70,6 +71,7 @@ func NewServerRunOptions() *ServerRunOptions { SecureServing: genericoptions.NewSecureServingOptions(), InsecureServing: genericoptions.NewInsecureServingOptions(), Audit: genericoptions.NewAuditLogOptions(), + Features: genericoptions.NewFeatureOptions(), Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(), Authorization: kubeoptions.NewBuiltInAuthorizationOptions(), CloudProvider: kubeoptions.NewCloudProviderOptions(), @@ -106,6 +108,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { s.InsecureServing.AddFlags(fs) s.InsecureServing.AddDeprecatedFlags(fs) s.Audit.AddFlags(fs) + s.Features.AddFlags(fs) s.Authentication.AddFlags(fs) s.Authorization.AddFlags(fs) s.CloudProvider.AddFlags(fs) diff --git a/cmd/kube-apiserver/app/options/options_test.go b/cmd/kube-apiserver/app/options/options_test.go index 021bdb1370..06eee371d5 100644 --- a/cmd/kube-apiserver/app/options/options_test.go +++ b/cmd/kube-apiserver/app/options/options_test.go @@ -28,7 +28,7 @@ func TestAddFlagsFlag(t *testing.T) { f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError) s := NewServerRunOptions() s.AddFlags(f) - if s.GenericServerRunOptions.EnableSwaggerUI { + if s.Features.EnableSwaggerUI { t.Errorf("Expected s.EnableSwaggerUI to be false by default") } @@ -36,7 +36,7 @@ func TestAddFlagsFlag(t *testing.T) { "--enable-swagger-ui=true", } f.Parse(args) - if !s.GenericServerRunOptions.EnableSwaggerUI { + if !s.Features.EnableSwaggerUI { t.Errorf("Expected s.EnableSwaggerUI to be true") } } diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index 4e84717d72..f22191c86a 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -123,6 +123,9 @@ func Run(s *options.ServerRunOptions) error { if err := s.Audit.ApplyTo(genericConfig); err != nil { return err } + if err := s.Features.ApplyTo(genericConfig); err != nil { + return err + } capabilities.Initialize(capabilities.Capabilities{ AllowPrivileged: s.AllowPrivileged, diff --git a/federation/cmd/federation-apiserver/app/options/options.go b/federation/cmd/federation-apiserver/app/options/options.go index 1b172d5388..4c734f5051 100644 --- a/federation/cmd/federation-apiserver/app/options/options.go +++ b/federation/cmd/federation-apiserver/app/options/options.go @@ -37,6 +37,7 @@ type ServerRunOptions struct { SecureServing *genericoptions.SecureServingOptions InsecureServing *genericoptions.ServingOptions Audit *genericoptions.AuditLogOptions + Features *genericoptions.FeatureOptions Authentication *kubeoptions.BuiltInAuthenticationOptions Authorization *kubeoptions.BuiltInAuthorizationOptions CloudProvider *kubeoptions.CloudProviderOptions @@ -53,6 +54,7 @@ func NewServerRunOptions() *ServerRunOptions { SecureServing: genericoptions.NewSecureServingOptions(), InsecureServing: genericoptions.NewInsecureServingOptions(), Audit: genericoptions.NewAuditLogOptions(), + Features: genericoptions.NewFeatureOptions(), Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(), Authorization: kubeoptions.NewBuiltInAuthorizationOptions(), CloudProvider: kubeoptions.NewCloudProviderOptions(), @@ -73,6 +75,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { s.SecureServing.AddFlags(fs) s.InsecureServing.AddFlags(fs) s.Audit.AddFlags(fs) + s.Features.AddFlags(fs) s.Authentication.AddFlags(fs) s.Authorization.AddFlags(fs) s.CloudProvider.AddFlags(fs) diff --git a/federation/cmd/federation-apiserver/app/server.go b/federation/cmd/federation-apiserver/app/server.go index 78d41c6ef9..d6efd5548c 100644 --- a/federation/cmd/federation-apiserver/app/server.go +++ b/federation/cmd/federation-apiserver/app/server.go @@ -106,6 +106,9 @@ func Run(s *options.ServerRunOptions) error { if err := s.Audit.ApplyTo(genericConfig); err != nil { return err } + if err := s.Features.ApplyTo(genericConfig); err != nil { + return err + } // TODO: register cluster federation resources here. resourceConfig := genericapiserver.NewResourceConfig() @@ -211,7 +214,7 @@ func Run(s *options.ServerRunOptions) error { // TODO: Refactor this code to share it with kube-apiserver rather than duplicating it here. restOptionsFactory := &restOptionsFactory{ storageFactory: storageFactory, - enableGarbageCollection: s.GenericServerRunOptions.EnableGarbageCollection, + enableGarbageCollection: s.Features.EnableGarbageCollection, deleteCollectionWorkers: s.GenericServerRunOptions.DeleteCollectionWorkers, } if s.GenericServerRunOptions.EnableWatchCache { diff --git a/staging/src/k8s.io/apiserver/pkg/server/options/feature.go b/staging/src/k8s.io/apiserver/pkg/server/options/feature.go new file mode 100644 index 0000000000..ef2b8c00a7 --- /dev/null +++ b/staging/src/k8s.io/apiserver/pkg/server/options/feature.go @@ -0,0 +1,62 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package options + +import ( + "github.com/spf13/pflag" + + "k8s.io/apiserver/pkg/server" +) + +type FeatureOptions struct { + EnableGarbageCollection bool + EnableProfiling bool + EnableContentionProfiling bool + EnableSwaggerUI bool +} + +func NewFeatureOptions() *FeatureOptions { + defaults := server.NewConfig() + + return &FeatureOptions{ + EnableGarbageCollection: defaults.EnableGarbageCollection, + EnableProfiling: defaults.EnableProfiling, + EnableContentionProfiling: defaults.EnableContentionProfiling, + EnableSwaggerUI: defaults.EnableSwaggerUI, + } +} + +func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) { + fs.BoolVar(&o.EnableGarbageCollection, "enable-garbage-collector", o.EnableGarbageCollection, ""+ + "Enables the generic garbage collector. MUST be synced with the corresponding flag "+ + "of the kube-controller-manager.") + fs.BoolVar(&o.EnableProfiling, "profiling", o.EnableProfiling, + "Enable profiling via web interface host:port/debug/pprof/") + fs.BoolVar(&o.EnableContentionProfiling, "contention-profiling", o.EnableContentionProfiling, + "Enable contention profiling. Requires --profiling to be set to work.") + fs.BoolVar(&o.EnableSwaggerUI, "enable-swagger-ui", o.EnableSwaggerUI, + "Enables swagger ui on the apiserver at /swagger-ui") +} + +func (o *FeatureOptions) ApplyTo(c *server.Config) error { + c.EnableGarbageCollection = o.EnableGarbageCollection + c.EnableProfiling = o.EnableProfiling + c.EnableContentionProfiling = o.EnableContentionProfiling + c.EnableSwaggerUI = o.EnableSwaggerUI + + return nil +} diff --git a/staging/src/k8s.io/apiserver/pkg/server/options/recommended.go b/staging/src/k8s.io/apiserver/pkg/server/options/recommended.go index 1a9c8d9adc..fde701fdf1 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/options/recommended.go +++ b/staging/src/k8s.io/apiserver/pkg/server/options/recommended.go @@ -31,6 +31,7 @@ type RecommendedOptions struct { Authentication *DelegatingAuthenticationOptions Authorization *DelegatingAuthorizationOptions Audit *AuditLogOptions + Features *FeatureOptions } func NewRecommendedOptions(scheme *runtime.Scheme) *RecommendedOptions { @@ -40,6 +41,7 @@ func NewRecommendedOptions(scheme *runtime.Scheme) *RecommendedOptions { Authentication: NewDelegatingAuthenticationOptions(), Authorization: NewDelegatingAuthorizationOptions(), Audit: NewAuditLogOptions(), + Features: NewFeatureOptions(), } } @@ -49,6 +51,7 @@ func (o *RecommendedOptions) AddFlags(fs *pflag.FlagSet) { o.Authentication.AddFlags(fs) o.Authorization.AddFlags(fs) o.Audit.AddFlags(fs) + o.Features.AddFlags(fs) } func (o *RecommendedOptions) ApplyTo(config *server.Config) error { @@ -64,6 +67,9 @@ func (o *RecommendedOptions) ApplyTo(config *server.Config) error { if err := o.Audit.ApplyTo(config); err != nil { return err } + if err := o.Features.ApplyTo(config); err != nil { + return err + } return nil } diff --git a/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go b/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go index ef2a0db434..eed8b4695d 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go +++ b/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go @@ -44,10 +44,6 @@ type ServerRunOptions struct { // to set it to "application/vnd.kubernetes.protobuf". DefaultStorageMediaType string DeleteCollectionWorkers int - EnableGarbageCollection bool - EnableProfiling bool - EnableContentionProfiling bool - EnableSwaggerUI bool EnableWatchCache bool ExternalHost string MaxRequestsInFlight int @@ -65,9 +61,6 @@ func NewServerRunOptions() *ServerRunOptions { AdmissionControl: "AlwaysAdmit", DefaultStorageMediaType: "application/json", DeleteCollectionWorkers: 1, - EnableGarbageCollection: defaults.EnableGarbageCollection, - EnableProfiling: defaults.EnableProfiling, - EnableContentionProfiling: false, EnableWatchCache: true, MaxRequestsInFlight: defaults.MaxRequestsInFlight, MaxMutatingRequestsInFlight: defaults.MaxMutatingRequestsInFlight, @@ -79,10 +72,6 @@ func NewServerRunOptions() *ServerRunOptions { // ApplyOptions applies the run options to the method receiver and returns self func (s *ServerRunOptions) ApplyTo(c *server.Config) error { c.CorsAllowedOriginList = s.CorsAllowedOriginList - c.EnableGarbageCollection = s.EnableGarbageCollection - c.EnableProfiling = s.EnableProfiling - c.EnableContentionProfiling = s.EnableContentionProfiling - c.EnableSwaggerUI = s.EnableSwaggerUI c.ExternalAddress = s.ExternalHost c.MaxRequestsInFlight = s.MaxRequestsInFlight c.MaxMutatingRequestsInFlight = s.MaxMutatingRequestsInFlight @@ -149,18 +138,6 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) { fs.IntVar(&s.DeleteCollectionWorkers, "delete-collection-workers", s.DeleteCollectionWorkers, "Number of workers spawned for DeleteCollection call. These are used to speed up namespace cleanup.") - fs.BoolVar(&s.EnableGarbageCollection, "enable-garbage-collector", s.EnableGarbageCollection, ""+ - "Enables the generic garbage collector. MUST be synced with the corresponding flag "+ - "of the kube-controller-manager.") - - fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling, - "Enable profiling via web interface host:port/debug/pprof/") - fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", s.EnableContentionProfiling, - "Enable contention profiling. Requires --profiling to be set to work.") - - fs.BoolVar(&s.EnableSwaggerUI, "enable-swagger-ui", s.EnableSwaggerUI, - "Enables swagger ui on the apiserver at /swagger-ui") - // TODO: enable cache in integration tests. fs.BoolVar(&s.EnableWatchCache, "watch-cache", s.EnableWatchCache, "Enable watch caching in the apiserver") diff --git a/vendor/BUILD b/vendor/BUILD index 83559d317c..5fafb7842e 100644 --- a/vendor/BUILD +++ b/vendor/BUILD @@ -14094,6 +14094,7 @@ go_library( "k8s.io/apiserver/pkg/server/options/authorization.go", "k8s.io/apiserver/pkg/server/options/doc.go", "k8s.io/apiserver/pkg/server/options/etcd.go", + "k8s.io/apiserver/pkg/server/options/feature.go", "k8s.io/apiserver/pkg/server/options/recommended.go", "k8s.io/apiserver/pkg/server/options/server_run_options.go", "k8s.io/apiserver/pkg/server/options/serving.go",