Skip to content

Commit

Permalink
APF: graduate API and types to beta
Browse files Browse the repository at this point in the history
Signed-off-by: Adhityaa Chandrasekar <adtac@google.com>
  • Loading branch information
yue9944882 authored and Adhityaa Chandrasekar committed Nov 13, 2020
1 parent 5cfce4e commit 849be44
Show file tree
Hide file tree
Showing 102 changed files with 13,258 additions and 616 deletions.
2,883 changes: 2,741 additions & 142 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/kazel_generated.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tags_values_pkgs = {"openapi-gen": {
"staging/src/k8s.io/api/events/v1beta1",
"staging/src/k8s.io/api/extensions/v1beta1",
"staging/src/k8s.io/api/flowcontrol/v1alpha1",
"staging/src/k8s.io/api/flowcontrol/v1beta1",
"staging/src/k8s.io/api/imagepolicy/v1alpha1",
"staging/src/k8s.io/api/networking/v1",
"staging/src/k8s.io/api/networking/v1beta1",
Expand Down Expand Up @@ -150,6 +151,7 @@ tags_pkgs_values = {"openapi-gen": {
"staging/src/k8s.io/api/events/v1beta1": ["true"],
"staging/src/k8s.io/api/extensions/v1beta1": ["true"],
"staging/src/k8s.io/api/flowcontrol/v1alpha1": ["true"],
"staging/src/k8s.io/api/flowcontrol/v1beta1": ["true"],
"staging/src/k8s.io/api/imagepolicy/v1alpha1": ["true"],
"staging/src/k8s.io/api/networking/v1": ["true"],
"staging/src/k8s.io/api/networking/v1beta1": ["true"],
Expand Down
1 change: 1 addition & 0 deletions cmd/kube-apiserver/app/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
{Group: "node.k8s.io", Version: "v1beta1"}: {group: 16300, version: 9},
{Group: "discovery.k8s.io", Version: "v1beta1"}: {group: 16200, version: 12},
{Group: "discovery.k8s.io", Version: "v1alpha1"}: {group: 16200, version: 9},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta1"}: {group: 16100, version: 12},
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1alpha1"}: {group: 16100, version: 9},
{Group: "internal.apiserver.k8s.io", Version: "v1alpha1"}: {group: 16000, version: 9},
// Append a new group to the end of the list if unsure.
Expand Down
20 changes: 10 additions & 10 deletions cmd/kube-apiserver/app/options/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ func validateTokenRequest(options *ServerRunOptions) []error {

func validateAPIPriorityAndFairness(options *ServerRunOptions) []error {
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && options.GenericServerRunOptions.EnablePriorityAndFairness {
// We need the alpha API enabled. There are only a few ways to turn it on
// If none of the following runtime config options are specified, APF is
// assumed to be turned 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")}
testConfigs := []string{"flowcontrol.apiserver.k8s.io/v1beta1", "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("%s=false conflicts with APIPriorityAndFairness feature gate", testConfig)}
}
if strings.Contains(enabledAPIString, fmt.Sprintf("%s=true", testConfig)) {
return nil
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func BuildAuthorizer(s *options.ServerRunOptions, EgressSelector *egressselector
func BuildPriorityAndFairness(s *options.ServerRunOptions, extclient clientgoclientset.Interface, versionedInformer clientgoinformers.SharedInformerFactory) utilflowcontrol.Interface {
return utilflowcontrol.New(
versionedInformer,
extclient.FlowcontrolV1alpha1(),
extclient.FlowcontrolV1beta1(),
s.GenericServerRunOptions.MaxRequestsInFlight+s.GenericServerRunOptions.MaxMutatingRequestsInFlight,
s.GenericServerRunOptions.RequestTimeout/4,
)
Expand Down
1 change: 1 addition & 0 deletions hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pkg/apis/events/v1
pkg/apis/events/v1beta1
pkg/apis/extensions/v1beta1
pkg/apis/flowcontrol/v1alpha1
pkg/apis/flowcontrol/v1beta1
pkg/apis/networking/v1
pkg/apis/networking/v1beta1
pkg/apis/node/v1alpha1
Expand Down
1 change: 1 addition & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ storage.k8s.io/v1beta1 \
storage.k8s.io/v1 \
storage.k8s.io/v1alpha1 \
flowcontrol.apiserver.k8s.io/v1alpha1 \
flowcontrol.apiserver.k8s.io/v1beta1 \
internal.apiserver.k8s.io/v1alpha1 \
}"

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/flowcontrol/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ filegroup(
"//pkg/apis/flowcontrol/internalbootstrap:all-srcs",
"//pkg/apis/flowcontrol/util:all-srcs",
"//pkg/apis/flowcontrol/v1alpha1:all-srcs",
"//pkg/apis/flowcontrol/v1beta1:all-srcs",
"//pkg/apis/flowcontrol/validation:all-srcs",
],
tags = ["automanaged"],
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/flowcontrol/install/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/flowcontrol:go_default_library",
"//pkg/apis/flowcontrol/v1alpha1:go_default_library",
"//pkg/apis/flowcontrol/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
],
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/flowcontrol/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/flowcontrol"
flowcontrolv1alpha1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1alpha1"
flowcontrolv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
)

func init() {
Expand All @@ -34,5 +35,6 @@ func init() {
func Install(scheme *runtime.Scheme) {
utilruntime.Must(flowcontrol.AddToScheme(scheme))
utilruntime.Must(flowcontrolv1alpha1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(flowcontrolv1alpha1.SchemeGroupVersion))
utilruntime.Must(flowcontrolv1beta1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(flowcontrolv1beta1.SchemeGroupVersion, flowcontrolv1alpha1.SchemeGroupVersion))
}
4 changes: 2 additions & 2 deletions pkg/apis/flowcontrol/internalbootstrap/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
deps = [
"//pkg/apis/flowcontrol:go_default_library",
"//pkg/apis/flowcontrol/install:go_default_library",
"//staging/src/k8s.io/api/flowcontrol/v1alpha1:go_default_library",
"//staging/src/k8s.io/api/flowcontrol/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap:go_default_library",
],
Expand All @@ -33,7 +33,7 @@ go_test(
srcs = ["defaults_test.go"],
embed = [":go_default_library"],
deps = [
"//staging/src/k8s.io/api/flowcontrol/v1alpha1:go_default_library",
"//staging/src/k8s.io/api/flowcontrol/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap:go_default_library",
],
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/flowcontrol/internalbootstrap/default-internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package internalbootstrap

import (
fcv1a1 "k8s.io/api/flowcontrol/v1alpha1"
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
"k8s.io/kubernetes/pkg/apis/flowcontrol"
Expand Down Expand Up @@ -46,7 +46,7 @@ func NewAPFScheme() *runtime.Scheme {
return scheme
}

func internalizeFSes(exts []*fcv1a1.FlowSchema) map[string]*flowcontrol.FlowSchema {
func internalizeFSes(exts []*flowcontrolv1beta1.FlowSchema) map[string]*flowcontrol.FlowSchema {
ans := make(map[string]*flowcontrol.FlowSchema, len(exts))
scheme := NewAPFScheme()
for _, ext := range exts {
Expand All @@ -59,7 +59,7 @@ func internalizeFSes(exts []*fcv1a1.FlowSchema) map[string]*flowcontrol.FlowSche
return ans
}

func internalizePLs(exts []*fcv1a1.PriorityLevelConfiguration) map[string]*flowcontrol.PriorityLevelConfiguration {
func internalizePLs(exts []*flowcontrolv1beta1.PriorityLevelConfiguration) map[string]*flowcontrol.PriorityLevelConfiguration {
ans := make(map[string]*flowcontrol.PriorityLevelConfiguration, len(exts))
scheme := NewAPFScheme()
for _, ext := range exts {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/flowcontrol/internalbootstrap/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package internalbootstrap
import (
"testing"

fcv1a1 "k8s.io/api/flowcontrol/v1alpha1"
flowcontrol "k8s.io/api/flowcontrol/v1beta1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
)

func TestMandatoryAlreadyDefaulted(t *testing.T) {
scheme := NewAPFScheme()
for _, obj := range bootstrap.MandatoryFlowSchemas {
obj2 := obj.DeepCopyObject().(*fcv1a1.FlowSchema)
obj2 := obj.DeepCopyObject().(*flowcontrol.FlowSchema)
scheme.Default(obj2)
if apiequality.Semantic.DeepEqual(obj, obj2) {
t.Logf("Defaulting makes no change to %#+v", *obj)
Expand All @@ -36,7 +36,7 @@ func TestMandatoryAlreadyDefaulted(t *testing.T) {
}
}
for _, obj := range bootstrap.MandatoryPriorityLevelConfigurations {
obj2 := obj.DeepCopyObject().(*fcv1a1.PriorityLevelConfiguration)
obj2 := obj.DeepCopyObject().(*flowcontrol.PriorityLevelConfiguration)
scheme.Default(obj2)
if apiequality.Semantic.DeepEqual(obj, obj2) {
t.Logf("Defaulting makes no change to %#+v", *obj)
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/flowcontrol/v1beta1/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"defaults.go",
"doc.go",
"register.go",
"zz_generated.conversion.go",
"zz_generated.defaults.go",
],
importpath = "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/flowcontrol:go_default_library",
"//staging/src/k8s.io/api/flowcontrol/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
60 changes: 60 additions & 0 deletions pkg/apis/flowcontrol/v1beta1/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
"k8s.io/api/flowcontrol/v1beta1"
)

// Default settings for flow-schema
const (
FlowSchemaDefaultMatchingPrecedence int32 = 1000
)

// Default settings for priority-level-configuration
const (
PriorityLevelConfigurationDefaultHandSize int32 = 8
PriorityLevelConfigurationDefaultQueues int32 = 64
PriorityLevelConfigurationDefaultQueueLengthLimit int32 = 50
PriorityLevelConfigurationDefaultAssuredConcurrencyShares int32 = 30
)

// SetDefaults_FlowSchema sets default values for flow schema
func SetDefaults_FlowSchemaSpec(spec *v1beta1.FlowSchemaSpec) {
if spec.MatchingPrecedence == 0 {
spec.MatchingPrecedence = FlowSchemaDefaultMatchingPrecedence
}
}

func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta1.LimitedPriorityLevelConfiguration) {
if lplc.AssuredConcurrencyShares == 0 {
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
}
}

// SetDefaults_FlowSchema sets default values for flow schema
func SetDefaults_QueuingConfiguration(cfg *v1beta1.QueuingConfiguration) {
if cfg.HandSize == 0 {
cfg.HandSize = PriorityLevelConfigurationDefaultHandSize
}
if cfg.Queues == 0 {
cfg.Queues = PriorityLevelConfigurationDefaultQueues
}
if cfg.QueueLengthLimit == 0 {
cfg.QueueLengthLimit = PriorityLevelConfigurationDefaultQueueLengthLimit
}
}
24 changes: 24 additions & 0 deletions pkg/apis/flowcontrol/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/flowcontrol
// +k8s:conversion-gen-external-types=k8s.io/api/flowcontrol/v1beta1
// +k8s:defaulter-gen=TypeMeta
// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/flowcontrol/v1beta1

// +groupName=flowcontrol.apiserver.k8s.io

package v1beta1 // import "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
46 changes: 46 additions & 0 deletions pkg/apis/flowcontrol/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName is the group name use in this package
const GroupName = "flowcontrol.apiserver.k8s.io"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
localSchemeBuilder = &flowcontrolv1beta1.SchemeBuilder
// AddToScheme adds api to a scheme
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(RegisterDefaults)
}
Loading

0 comments on commit 849be44

Please sign in to comment.