From 2e34520350e1e802e028f0927ce50fba6c470cf5 Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 7 Feb 2017 13:22:38 -0500 Subject: [PATCH] add feature enablement options to recommendedoptions --- pkg/server/options/feature.go | 62 ++++++++++++++++++++++++ pkg/server/options/recommended.go | 6 +++ pkg/server/options/server_run_options.go | 23 --------- 3 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 pkg/server/options/feature.go diff --git a/pkg/server/options/feature.go b/pkg/server/options/feature.go new file mode 100644 index 000000000..ef2b8c00a --- /dev/null +++ b/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/pkg/server/options/recommended.go b/pkg/server/options/recommended.go index 1a9c8d9ad..fde701fdf 100644 --- a/pkg/server/options/recommended.go +++ b/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/pkg/server/options/server_run_options.go b/pkg/server/options/server_run_options.go index 95c39b65d..395bd69f6 100644 --- a/pkg/server/options/server_run_options.go +++ b/pkg/server/options/server_run_options.go @@ -43,10 +43,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 @@ -63,9 +59,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, @@ -76,10 +69,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 @@ -146,18 +135,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")