apiserver: fix apf enablement with runtime-config

This commit is contained in:
Abu Kashem 2023-10-28 14:09:55 -04:00
parent acd6089659
commit 233bc2449d
No known key found for this signature in database
GPG Key ID: E5ECC1124B5F9C68
2 changed files with 23 additions and 3 deletions

View File

@ -56,7 +56,7 @@ func validateAPIPriorityAndFairness(options *Options) []error {
// APF is assumed to be turned on. The internal APF controller uses
// v1 so it should be enabled.
enabledAPIString := options.APIEnablement.RuntimeConfig.String()
testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1", "api/all"} // in the order of precedence
testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1", "api/ga", "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)}

View File

@ -46,6 +46,14 @@ func TestValidateAPIPriorityAndFairness(t *testing.T) {
runtimeConfig: "api/beta=false",
errShouldContain: "",
},
{
runtimeConfig: "api/ga=false",
errShouldContain: conflict,
},
{
runtimeConfig: "api/ga=true",
errShouldContain: "",
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta1=false",
errShouldContain: "",
@ -70,6 +78,10 @@ func TestValidateAPIPriorityAndFairness(t *testing.T) {
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1=false",
errShouldContain: conflict,
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta3=true,flowcontrol.apiserver.k8s.io/v1=false",
errShouldContain: conflict,
},
}
for _, test := range tests {
@ -86,8 +98,16 @@ func TestValidateAPIPriorityAndFairness(t *testing.T) {
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)
switch {
case len(test.errShouldContain) == 0:
if len(errMessageGot) > 0 {
t.Errorf("Expected no error, but got: %q", errMessageGot)
}
default:
if !strings.Contains(errMessageGot, test.errShouldContain) {
t.Errorf("Expected error message to contain: %q, but got: %q", test.errShouldContain, errMessageGot)
}
}
})
}