Skip to content

Commit 45c2f45

Browse files
committed
add flag check to ensure that flowcontrol API is present
1 parent 46b2891 commit 45c2f45

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cmd/kube-apiserver/app/options/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ go_library(
2828
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver:go_default_library",
2929
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
3030
"//staging/src/k8s.io/apiserver/pkg/admission:go_default_library",
31+
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",
3132
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
3233
"//staging/src/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
3334
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",

cmd/kube-apiserver/app/options/validation.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
apiextensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
26+
genericfeatures "k8s.io/apiserver/pkg/features"
2627
utilfeature "k8s.io/apiserver/pkg/util/feature"
2728
"k8s.io/component-base/metrics"
2829
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
@@ -127,6 +128,25 @@ func validateTokenRequest(options *ServerRunOptions) []error {
127128
return errs
128129
}
129130

131+
func validateAPIPriorityAndFairness(options *ServerRunOptions) []error {
132+
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && options.GenericServerRunOptions.EnablePriorityAndFairness {
133+
// we know we need the alpha API enabled. There are only a few ways to turn it on
134+
enabledAPIString := options.APIEnablement.RuntimeConfig.String()
135+
switch {
136+
case strings.Contains(enabledAPIString, "api/all=true"):
137+
return nil
138+
case strings.Contains(enabledAPIString, "api/alpha=true"):
139+
return nil
140+
case strings.Contains(enabledAPIString, "flowcontrol.apiserver.k8s.io/v1alpha1=true"):
141+
return nil
142+
default:
143+
return []error{fmt.Errorf("enabling APIPriorityAndFairness requires --runtime-confg=flowcontrol.apiserver.k8s.io/v1alpha1=true to enable the required API")}
144+
}
145+
}
146+
147+
return []error{}
148+
}
149+
130150
// Validate checks ServerRunOptions and return a slice of found errs.
131151
func (s *ServerRunOptions) Validate() []error {
132152
var errs []error
@@ -136,6 +156,7 @@ func (s *ServerRunOptions) Validate() []error {
136156
errs = append(errs, s.Etcd.Validate()...)
137157
errs = append(errs, validateClusterIPFlags(s)...)
138158
errs = append(errs, validateServiceNodePort(s)...)
159+
errs = append(errs, validateAPIPriorityAndFairness(s)...)
139160
errs = append(errs, s.SecureServing.Validate()...)
140161
errs = append(errs, s.Authentication.Validate()...)
141162
errs = append(errs, s.Authorization.Validate()...)

0 commit comments

Comments
 (0)