Skip to content

Commit

Permalink
apiserver: enable apf v1 API
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashem committed Oct 30, 2023
1 parent 5cb0306 commit b24dd44
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/kube-apiserver/app/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
{Group: "node.k8s.io", Version: "v1beta1"}: {group: 16300, version: 9},
{Group: "discovery.k8s.io", Version: "v1"}: {group: 16200, version: 15},
{Group: "discovery.k8s.io", Version: "v1beta1"}: {group: 16200, version: 12},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1"}: {group: 16100, version: 21},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta3"}: {group: 16100, version: 18},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta2"}: {group: 16100, version: 15},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta1"}: {group: 16100, version: 12},
Expand Down
1 change: 1 addition & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ scheduling.k8s.io/v1 \
storage.k8s.io/v1beta1 \
storage.k8s.io/v1 \
storage.k8s.io/v1alpha1 \
flowcontrol.apiserver.k8s.io/v1 \
flowcontrol.apiserver.k8s.io/v1beta1 \
flowcontrol.apiserver.k8s.io/v1beta2 \
flowcontrol.apiserver.k8s.io/v1beta3 \
Expand Down
10 changes: 8 additions & 2 deletions pkg/apis/flowcontrol/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/flowcontrol"
flowcontrolv1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1"
flowcontrolv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
flowcontrolv1beta3 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3"
Expand All @@ -38,6 +39,11 @@ func Install(scheme *runtime.Scheme) {
utilruntime.Must(flowcontrolv1beta1.AddToScheme(scheme))
utilruntime.Must(flowcontrolv1beta2.AddToScheme(scheme))
utilruntime.Must(flowcontrolv1beta3.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(flowcontrolv1beta3.SchemeGroupVersion, flowcontrolv1beta2.SchemeGroupVersion,
flowcontrolv1beta1.SchemeGroupVersion))
utilruntime.Must(flowcontrolv1.AddToScheme(scheme))

// TODO(#121119): This controls serialization order, for 1.29, we continue
// to use v1beta3 as the serialization version because vN-1 understands that
// level. In 1.30, we should set the serialization version to v1.
utilruntime.Must(scheme.SetVersionPriority(flowcontrolv1beta3.SchemeGroupVersion, flowcontrolv1.SchemeGroupVersion,
flowcontrolv1beta2.SchemeGroupVersion, flowcontrolv1beta1.SchemeGroupVersion))
}
4 changes: 2 additions & 2 deletions pkg/controlplane/apiserver/options/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func validateAPIPriorityAndFairness(options *Options) []error {
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && options.Features.EnablePriorityAndFairness {
// 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.
// v1 so it should be enabled.
enabledAPIString := options.APIEnablement.RuntimeConfig.String()
testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1beta3", "api/beta", "api/all"} // in the order of precedence
testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1", "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)}
Expand Down
12 changes: 10 additions & 2 deletions pkg/controlplane/apiserver/options/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestValidateAPIPriorityAndFairness(t *testing.T) {
},
{
runtimeConfig: "api/beta=false",
errShouldContain: conflict,
errShouldContain: "",
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta1=false",
Expand All @@ -56,12 +56,20 @@ func TestValidateAPIPriorityAndFairness(t *testing.T) {
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta3=false",
errShouldContain: conflict,
errShouldContain: "",
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1beta3=true",
errShouldContain: "",
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1=true",
errShouldContain: "",
},
{
runtimeConfig: "flowcontrol.apiserver.k8s.io/v1=false",
errShouldContain: conflict,
},
}

for _, test := range tests {
Expand Down
2 changes: 2 additions & 0 deletions pkg/controlplane/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import (
"k8s.io/component-helpers/apimachinery/lease"
"k8s.io/klog/v2"
api "k8s.io/kubernetes/pkg/apis/core"
flowcontrolv1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1"
flowcontrolv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
flowcontrolv1beta3 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3"
Expand Down Expand Up @@ -735,6 +736,7 @@ var (
rbacv1.SchemeGroupVersion,
storageapiv1.SchemeGroupVersion,
schedulingapiv1.SchemeGroupVersion,
flowcontrolv1.SchemeGroupVersion,
}

// legacyBetaEnabledByDefaultResources is the list of beta resources we enable. You may only add to this list
Expand Down
18 changes: 9 additions & 9 deletions pkg/printers/internalversion/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
apiv1 "k8s.io/api/core/v1"
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
flowcontrolv1beta3 "k8s.io/api/flowcontrol/v1beta3"
flowcontrolv1 "k8s.io/api/flowcontrol/v1"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1"
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
resourcev1alpha2 "k8s.io/api/resource/v1alpha2"
Expand Down Expand Up @@ -569,9 +569,9 @@ func AddHandlers(h printers.PrintHandler) {

flowSchemaColumnDefinitions := []metav1.TableColumnDefinition{
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
{Name: "PriorityLevel", Type: "string", Description: flowcontrolv1beta3.PriorityLevelConfigurationReference{}.SwaggerDoc()["name"]},
{Name: "MatchingPrecedence", Type: "string", Description: flowcontrolv1beta3.FlowSchemaSpec{}.SwaggerDoc()["matchingPrecedence"]},
{Name: "DistinguisherMethod", Type: "string", Description: flowcontrolv1beta3.FlowSchemaSpec{}.SwaggerDoc()["distinguisherMethod"]},
{Name: "PriorityLevel", Type: "string", Description: flowcontrolv1.PriorityLevelConfigurationReference{}.SwaggerDoc()["name"]},
{Name: "MatchingPrecedence", Type: "string", Description: flowcontrolv1.FlowSchemaSpec{}.SwaggerDoc()["matchingPrecedence"]},
{Name: "DistinguisherMethod", Type: "string", Description: flowcontrolv1.FlowSchemaSpec{}.SwaggerDoc()["distinguisherMethod"]},
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
{Name: "MissingPL", Type: "string", Description: "references a broken or non-existent PriorityLevelConfiguration"},
}
Expand All @@ -580,11 +580,11 @@ func AddHandlers(h printers.PrintHandler) {

priorityLevelColumnDefinitions := []metav1.TableColumnDefinition{
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
{Name: "Type", Type: "string", Description: flowcontrolv1beta3.PriorityLevelConfigurationSpec{}.SwaggerDoc()["type"]},
{Name: "NominalConcurrencyShares", Type: "string", Description: flowcontrolv1beta3.LimitedPriorityLevelConfiguration{}.SwaggerDoc()["nominalConcurrencyShares"]},
{Name: "Queues", Type: "string", Description: flowcontrolv1beta3.QueuingConfiguration{}.SwaggerDoc()["queues"]},
{Name: "HandSize", Type: "string", Description: flowcontrolv1beta3.QueuingConfiguration{}.SwaggerDoc()["handSize"]},
{Name: "QueueLengthLimit", Type: "string", Description: flowcontrolv1beta3.QueuingConfiguration{}.SwaggerDoc()["queueLengthLimit"]},
{Name: "Type", Type: "string", Description: flowcontrolv1.PriorityLevelConfigurationSpec{}.SwaggerDoc()["type"]},
{Name: "NominalConcurrencyShares", Type: "string", Description: flowcontrolv1.LimitedPriorityLevelConfiguration{}.SwaggerDoc()["nominalConcurrencyShares"]},
{Name: "Queues", Type: "string", Description: flowcontrolv1.QueuingConfiguration{}.SwaggerDoc()["queues"]},
{Name: "HandSize", Type: "string", Description: flowcontrolv1.QueuingConfiguration{}.SwaggerDoc()["handSize"]},
{Name: "QueueLengthLimit", Type: "string", Description: flowcontrolv1.QueuingConfiguration{}.SwaggerDoc()["queueLengthLimit"]},
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
}
_ = h.TableHandler(priorityLevelColumnDefinitions, printPriorityLevelConfiguration)
Expand Down
7 changes: 7 additions & 0 deletions pkg/registry/flowcontrol/flowschema/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (flowSchemaStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.S
"flowcontrol.apiserver.k8s.io/v1beta3": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
"flowcontrol.apiserver.k8s.io/v1": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
}

return fields
Expand Down Expand Up @@ -136,6 +139,10 @@ func (flowSchemaStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*field
fieldpath.MakePathOrDie("metadata"),
fieldpath.MakePathOrDie("spec"),
),
"flowcontrol.apiserver.k8s.io/v1": fieldpath.NewSet(
fieldpath.MakePathOrDie("metadata"),
fieldpath.MakePathOrDie("spec"),
),
}

return fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (priorityLevelConfigurationStrategy) GetResetFields() map[fieldpath.APIVers
"flowcontrol.apiserver.k8s.io/v1beta3": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
"flowcontrol.apiserver.k8s.io/v1": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
}

return fields
Expand Down Expand Up @@ -138,6 +141,10 @@ func (priorityLevelConfigurationStatusStrategy) GetResetFields() map[fieldpath.A
fieldpath.MakePathOrDie("spec"),
fieldpath.MakePathOrDie("metadata"),
),
"flowcontrol.apiserver.k8s.io/v1": fieldpath.NewSet(
fieldpath.MakePathOrDie("spec"),
fieldpath.MakePathOrDie("metadata"),
),
}

return fields
Expand Down
7 changes: 7 additions & 0 deletions pkg/registry/flowcontrol/rest/storage_flowcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/flowcontrol"
flowcontrolapisv1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1"
flowcontrolapisv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolapisv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
flowcontrolapisv1beta3 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3"
Expand Down Expand Up @@ -76,6 +77,12 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag
apiGroupInfo.VersionedResourcesStorageMap[flowcontrolapisv1beta3.SchemeGroupVersion.Version] = storageMap
}

if storageMap, err := p.storage(apiResourceConfigSource, restOptionsGetter, flowcontrolapisv1.SchemeGroupVersion); err != nil {
return genericapiserver.APIGroupInfo{}, err
} else if len(storageMap) > 0 {
apiGroupInfo.VersionedResourcesStorageMap[flowcontrolapisv1.SchemeGroupVersion.Version] = storageMap
}

return apiGroupInfo, nil
}

Expand Down
1 change: 1 addition & 0 deletions test/integration/apiserver/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestServerSidePrint(t *testing.T) {
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta1"},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta2"},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta3"},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1"},
{Group: "internal.apiserver.k8s.io", Version: "v1alpha1"},
},
[]schema.GroupVersionResource{},
Expand Down

0 comments on commit b24dd44

Please sign in to comment.