add flag check to ensure that flowcontrol API is present

This commit is contained in:
David Eads 2020-04-07 13:31:18 -04:00
parent 46b2891089
commit 45c2f4534c
2 changed files with 22 additions and 0 deletions

View File

@ -28,6 +28,7 @@ go_library(
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",

View File

@ -23,6 +23,7 @@ import (
"strings"
apiextensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
genericfeatures "k8s.io/apiserver/pkg/features"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/component-base/metrics"
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
@ -127,6 +128,25 @@ func validateTokenRequest(options *ServerRunOptions) []error {
return errs
}
func validateAPIPriorityAndFairness(options *ServerRunOptions) []error {
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && options.GenericServerRunOptions.EnablePriorityAndFairness {
// we know we need the alpha API enabled. There are only a few ways to turn it on
enabledAPIString := options.APIEnablement.RuntimeConfig.String()
switch {
case strings.Contains(enabledAPIString, "api/all=true"):
return nil
case strings.Contains(enabledAPIString, "api/alpha=true"):
return nil
case strings.Contains(enabledAPIString, "flowcontrol.apiserver.k8s.io/v1alpha1=true"):
return nil
default:
return []error{fmt.Errorf("enabling APIPriorityAndFairness requires --runtime-confg=flowcontrol.apiserver.k8s.io/v1alpha1=true to enable the required API")}
}
}
return []error{}
}
// Validate checks ServerRunOptions and return a slice of found errs.
func (s *ServerRunOptions) Validate() []error {
var errs []error
@ -136,6 +156,7 @@ func (s *ServerRunOptions) Validate() []error {
errs = append(errs, s.Etcd.Validate()...)
errs = append(errs, validateClusterIPFlags(s)...)
errs = append(errs, validateServiceNodePort(s)...)
errs = append(errs, validateAPIPriorityAndFairness(s)...)
errs = append(errs, s.SecureServing.Validate()...)
errs = append(errs, s.Authentication.Validate()...)
errs = append(errs, s.Authorization.Validate()...)