From 3422dafac70d4dfb7ebf5d9d2a626a6c3501473e Mon Sep 17 00:00:00 2001 From: p0lyn0mial Date: Tue, 18 Apr 2017 18:32:14 +0200 Subject: [PATCH] Split out AdmissionOptions In the long term AdmissionOptions will accepts various dependencies and spit out AdmissionControl Kubernetes-commit: de9706bc15ffc3a6a4ef30a00d5c7ea9a8881396 --- pkg/server/options/admission.go | 49 ++++++++++++++++++++++++ pkg/server/options/server_run_options.go | 19 +-------- 2 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 pkg/server/options/admission.go diff --git a/pkg/server/options/admission.go b/pkg/server/options/admission.go new file mode 100644 index 000000000..6f1774a72 --- /dev/null +++ b/pkg/server/options/admission.go @@ -0,0 +1,49 @@ +/* +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 ( + "strings" + + "github.com/spf13/pflag" + "k8s.io/apiserver/pkg/admission" +) + +// AdmissionOptions holds the admission options +type AdmissionOptions struct { + Control string + ControlConfigFile string + Plugins *admission.Plugins +} + +// NewAdmissionOptions creates a new instance of AdmissionOptions +func NewAdmissionOptions(plugins *admission.Plugins) *AdmissionOptions { + return &AdmissionOptions{ + Plugins: plugins, + Control: "AlwaysAdmit", + } +} + +// AddFlags adds flags related to admission for a specific APIServer to the specified FlagSet +func (a *AdmissionOptions) AddFlags(fs *pflag.FlagSet) { + fs.StringVar(&a.Control, "admission-control", a.Control, ""+ + "Ordered list of plug-ins to do admission control of resources into cluster. "+ + "Comma-delimited list of: "+strings.Join(a.Plugins.Registered(), ", ")+".") + + fs.StringVar(&a.ControlConfigFile, "admission-control-config-file", a.ControlConfigFile, + "File with admission control configuration.") +} diff --git a/pkg/server/options/server_run_options.go b/pkg/server/options/server_run_options.go index 40fef0dab..0ca9d5973 100644 --- a/pkg/server/options/server_run_options.go +++ b/pkg/server/options/server_run_options.go @@ -19,11 +19,9 @@ package options import ( "fmt" "net" - "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apiserver/pkg/admission" "k8s.io/apiserver/pkg/server" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -35,9 +33,7 @@ import ( // ServerRunOptions contains the options while running a generic api server. type ServerRunOptions struct { - AdmissionControl string - AdmissionControlConfigFile string - AdvertiseAddress net.IP + AdvertiseAddress net.IP CorsAllowedOriginList []string ExternalHost string @@ -46,18 +42,14 @@ type ServerRunOptions struct { MinRequestTimeout int TargetRAMMB int WatchCacheSizes []string - - AdmissionPlugins *admission.Plugins } -func NewServerRunOptions(admissionPlugins *admission.Plugins) *ServerRunOptions { +func NewServerRunOptions() *ServerRunOptions { defaults := server.NewConfig(serializer.CodecFactory{}) return &ServerRunOptions{ - AdmissionControl: "AlwaysAdmit", MaxRequestsInFlight: defaults.MaxRequestsInFlight, MaxMutatingRequestsInFlight: defaults.MaxMutatingRequestsInFlight, MinRequestTimeout: defaults.MinRequestTimeout, - AdmissionPlugins: admissionPlugins, } } @@ -96,13 +88,6 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) { // Note: the weird ""+ in below lines seems to be the only way to get gofmt to // arrange these text blocks sensibly. Grrr. - fs.StringVar(&s.AdmissionControl, "admission-control", s.AdmissionControl, ""+ - "Ordered list of plug-ins to do admission control of resources into cluster. "+ - "Comma-delimited list of: "+strings.Join(s.AdmissionPlugins.Registered(), ", ")+".") - - fs.StringVar(&s.AdmissionControlConfigFile, "admission-control-config-file", s.AdmissionControlConfigFile, - "File with admission control configuration.") - fs.IPVar(&s.AdvertiseAddress, "advertise-address", s.AdvertiseAddress, ""+ "The IP address on which to advertise the apiserver to members of the cluster. This "+ "address must be reachable by the rest of the cluster. If blank, the --bind-address "+