diff --git a/cmd/kube-apiserver/app/options/validation.go b/cmd/kube-apiserver/app/options/validation.go index 38250a7a819..d96a6a41b17 100644 --- a/cmd/kube-apiserver/app/options/validation.go +++ b/cmd/kube-apiserver/app/options/validation.go @@ -124,10 +124,11 @@ func validateTokenRequest(options *ServerRunOptions) []error { func validateAPIPriorityAndFairness(options *ServerRunOptions) []error { if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && options.GenericServerRunOptions.EnablePriorityAndFairness { - // If none of the following runtime config options are specified, APF is - // assumed to be turned on. + // If none of the following runtime config options are specified, + // APF is assumed to be turned on. The internal APF controller uses + // v1beta3 so it should be enabled. enabledAPIString := options.APIEnablement.RuntimeConfig.String() - testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1beta2", "flowcontrol.apiserver.k8s.io/v1beta1", "api/beta", "api/all"} // in the order of precedence + testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1beta3", "api/beta", "api/all"} // in the order of precedence for _, testConfig := range testConfigs { if strings.Contains(enabledAPIString, fmt.Sprintf("%s=false", testConfig)) { return []error{fmt.Errorf("--runtime-config=%s=false conflicts with --enable-priority-and-fairness=true and --feature-gates=APIPriorityAndFairness=true", testConfig)} diff --git a/cmd/kube-apiserver/app/options/validation_test.go b/cmd/kube-apiserver/app/options/validation_test.go index 1a997a43317..e77517e372a 100644 --- a/cmd/kube-apiserver/app/options/validation_test.go +++ b/cmd/kube-apiserver/app/options/validation_test.go @@ -18,9 +18,11 @@ package options import ( "net" + "strings" "testing" utilnet "k8s.io/apimachinery/pkg/util/net" + genericoptions "k8s.io/apiserver/pkg/server/options" netutils "k8s.io/utils/net" ) @@ -250,3 +252,52 @@ func TestValidateMaxCIDRRange(t *testing.T) { }) } } + +func TestValidateAPIPriorityAndFairness(t *testing.T) { + const conflict = "conflicts with --enable-priority-and-fairness=true and --feature-gates=APIPriorityAndFairness=true" + tests := []struct { + runtimeConfig string + errShouldContain string + }{ + { + runtimeConfig: "api/all=false", + errShouldContain: conflict, + }, + { + runtimeConfig: "api/beta=false", + errShouldContain: conflict, + }, + { + runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta1=false", + errShouldContain: "", + }, + { + runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta2=false", + errShouldContain: "", + }, + { + runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta3=false", + errShouldContain: conflict, + }, + } + + for _, test := range tests { + t.Run(test.runtimeConfig, func(t *testing.T) { + options := &ServerRunOptions{ + GenericServerRunOptions: &genericoptions.ServerRunOptions{ + EnablePriorityAndFairness: true, + }, + APIEnablement: genericoptions.NewAPIEnablementOptions(), + } + options.APIEnablement.RuntimeConfig.Set(test.runtimeConfig) + + var errMessageGot string + if errs := validateAPIPriorityAndFairness(options); len(errs) > 0 { + errMessageGot = errs[0].Error() + } + if !strings.Contains(errMessageGot, test.errShouldContain) { + t.Errorf("Expected error message to contain: %q, but got: %q", test.errShouldContain, errMessageGot) + } + }) + } +}