From 226af4adc42dc4ad4b77ae34e99e3c9679389f2b Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 7 Feb 2017 13:43:13 -0500 Subject: [PATCH] move --runtime-config to kubeapiserver --- cmd/kube-apiserver/app/options/options.go | 3 ++ cmd/kube-apiserver/app/server.go | 2 +- .../app/options/options.go | 3 ++ .../cmd/federation-apiserver/app/server.go | 2 +- pkg/kubeapiserver/options/BUILD | 2 + pkg/kubeapiserver/options/api_enablement.go | 44 +++++++++++++++++++ .../pkg/server/options/server_run_options.go | 9 ---- 7 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 pkg/kubeapiserver/options/api_enablement.go diff --git a/cmd/kube-apiserver/app/options/options.go b/cmd/kube-apiserver/app/options/options.go index 66072c25fe..ba4410de8d 100644 --- a/cmd/kube-apiserver/app/options/options.go +++ b/cmd/kube-apiserver/app/options/options.go @@ -48,6 +48,7 @@ type ServerRunOptions struct { Authorization *kubeoptions.BuiltInAuthorizationOptions CloudProvider *kubeoptions.CloudProviderOptions StorageSerialization *kubeoptions.StorageSerializationOptions + APIEnablement *kubeoptions.APIEnablementOptions AllowPrivileged bool EventTTL time.Duration @@ -72,6 +73,7 @@ func NewServerRunOptions() *ServerRunOptions { Authorization: kubeoptions.NewBuiltInAuthorizationOptions(), CloudProvider: kubeoptions.NewCloudProviderOptions(), StorageSerialization: kubeoptions.NewStorageSerializationOptions(), + APIEnablement: kubeoptions.NewAPIEnablementOptions(), EventTTL: 1 * time.Hour, MasterCount: 1, @@ -107,6 +109,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { s.Authorization.AddFlags(fs) s.CloudProvider.AddFlags(fs) s.StorageSerialization.AddFlags(fs) + s.APIEnablement.AddFlags(fs) // Note: the weird ""+ in below lines seems to be the only way to get gofmt to // arrange these text blocks sensibly. Grrr. diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index d58ab2ef7b..c25e0cf707 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -203,7 +203,7 @@ func Run(s *options.ServerRunOptions) error { genericapiserver.NewDefaultResourceEncodingConfig(api.Registry), storageGroupsToEncodingVersion, // FIXME: this GroupVersionResource override should be configurable []schema.GroupVersionResource{batch.Resource("cronjobs").WithVersion("v2alpha1")}, - master.DefaultAPIResourceConfigSource(), s.GenericServerRunOptions.RuntimeConfig) + master.DefaultAPIResourceConfigSource(), s.APIEnablement.RuntimeConfig) if err != nil { return fmt.Errorf("error in initializing storage factory: %s", err) } diff --git a/federation/cmd/federation-apiserver/app/options/options.go b/federation/cmd/federation-apiserver/app/options/options.go index bb6139cf7d..12f753744f 100644 --- a/federation/cmd/federation-apiserver/app/options/options.go +++ b/federation/cmd/federation-apiserver/app/options/options.go @@ -40,6 +40,7 @@ type ServerRunOptions struct { Authorization *kubeoptions.BuiltInAuthorizationOptions CloudProvider *kubeoptions.CloudProviderOptions StorageSerialization *kubeoptions.StorageSerializationOptions + APIEnablement *kubeoptions.APIEnablementOptions EventTTL time.Duration } @@ -55,6 +56,7 @@ func NewServerRunOptions() *ServerRunOptions { Authorization: kubeoptions.NewBuiltInAuthorizationOptions(), CloudProvider: kubeoptions.NewCloudProviderOptions(), StorageSerialization: kubeoptions.NewStorageSerializationOptions(), + APIEnablement: kubeoptions.NewAPIEnablementOptions(), EventTTL: 1 * time.Hour, } @@ -74,6 +76,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { s.Authorization.AddFlags(fs) s.CloudProvider.AddFlags(fs) s.StorageSerialization.AddFlags(fs) + s.APIEnablement.AddFlags(fs) fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL, "Amount of time to retain events. Default is 1h.") diff --git a/federation/cmd/federation-apiserver/app/server.go b/federation/cmd/federation-apiserver/app/server.go index f55b4485c7..27582fc313 100644 --- a/federation/cmd/federation-apiserver/app/server.go +++ b/federation/cmd/federation-apiserver/app/server.go @@ -118,7 +118,7 @@ func Run(s *options.ServerRunOptions) error { storageFactory, err := kubeapiserver.BuildDefaultStorageFactory( s.Etcd.StorageConfig, s.GenericServerRunOptions.DefaultStorageMediaType, api.Codecs, genericapiserver.NewDefaultResourceEncodingConfig(api.Registry), storageGroupsToEncodingVersion, - []schema.GroupVersionResource{}, resourceConfig, s.GenericServerRunOptions.RuntimeConfig) + []schema.GroupVersionResource{}, resourceConfig, s.APIEnablement.RuntimeConfig) if err != nil { return fmt.Errorf("error in initializing storage factory: %s", err) } diff --git a/pkg/kubeapiserver/options/BUILD b/pkg/kubeapiserver/options/BUILD index 788ef10785..70efdfed67 100644 --- a/pkg/kubeapiserver/options/BUILD +++ b/pkg/kubeapiserver/options/BUILD @@ -11,6 +11,7 @@ load( go_library( name = "go_default_library", srcs = [ + "api_enablement.go", "authentication.go", "authorization.go", "cloudprovider.go", @@ -29,6 +30,7 @@ go_library( "//vendor:k8s.io/apimachinery/pkg/runtime/schema", "//vendor:k8s.io/apiserver/pkg/server", "//vendor:k8s.io/apiserver/pkg/server/options", + "//vendor:k8s.io/apiserver/pkg/util/flag", ], ) diff --git a/pkg/kubeapiserver/options/api_enablement.go b/pkg/kubeapiserver/options/api_enablement.go new file mode 100644 index 0000000000..fe5accd4f1 --- /dev/null +++ b/pkg/kubeapiserver/options/api_enablement.go @@ -0,0 +1,44 @@ +/* +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" + + utilflag "k8s.io/apiserver/pkg/util/flag" +) + +// APIEnablementOptions contains the options for which resources to turn on and off. +// Given small aggregated API servers, this option isn't required for "normal" API servers +type APIEnablementOptions struct { + RuntimeConfig utilflag.ConfigurationMap +} + +func NewAPIEnablementOptions() *APIEnablementOptions { + return &APIEnablementOptions{ + RuntimeConfig: make(utilflag.ConfigurationMap), + } +} + +// AddFlags adds flags for a specific APIServer to the specified FlagSet +func (s *APIEnablementOptions) AddFlags(fs *pflag.FlagSet) { + fs.Var(&s.RuntimeConfig, "runtime-config", ""+ + "A set of key=value pairs that describe runtime configuration that may be passed "+ + "to apiserver. apis/ key can be used to turn on/off specific api versions. "+ + "apis// can be used to turn on/off specific resources. api/all and "+ + "api/legacy are special keys to control all and legacy api versions respectively.") +} 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 3e39d64938..b5599df9aa 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 @@ -25,7 +25,6 @@ import ( "k8s.io/apiserver/pkg/admission" "k8s.io/apiserver/pkg/server" utilfeature "k8s.io/apiserver/pkg/util/feature" - utilflag "k8s.io/apiserver/pkg/util/flag" // add the generic feature gates _ "k8s.io/apiserver/pkg/features" @@ -58,7 +57,6 @@ type ServerRunOptions struct { MaxRequestsInFlight int MaxMutatingRequestsInFlight int MinRequestTimeout int - RuntimeConfig utilflag.ConfigurationMap TargetRAMMB int WatchCacheSizes []string } @@ -77,7 +75,6 @@ func NewServerRunOptions() *ServerRunOptions { MaxRequestsInFlight: defaults.MaxRequestsInFlight, MaxMutatingRequestsInFlight: defaults.MaxMutatingRequestsInFlight, MinRequestTimeout: defaults.MinRequestTimeout, - RuntimeConfig: make(utilflag.ConfigurationMap), } } @@ -218,12 +215,6 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) { "handler, which picks a randomized value above this number as the connection timeout, "+ "to spread out load.") - fs.Var(&s.RuntimeConfig, "runtime-config", ""+ - "A set of key=value pairs that describe runtime configuration that may be passed "+ - "to apiserver. apis/ key can be used to turn on/off specific api versions. "+ - "apis// can be used to turn on/off specific resources. api/all and "+ - "api/legacy are special keys to control all and legacy api versions respectively.") - fs.StringSliceVar(&s.WatchCacheSizes, "watch-cache-sizes", s.WatchCacheSizes, ""+ "List of watch cache sizes for every resource (pods, nodes, etc.), comma separated. "+ "The individual override format: resource#size, where size is a number. It takes effect "+