Merge pull request #104399 from tkashem/apf-v1beta2

apf: introduce v1beta2
This commit is contained in:
Kubernetes Prow Robot
2021-09-13 18:01:08 -07:00
committed by GitHub
95 changed files with 14572 additions and 179 deletions

View File

@@ -21,13 +21,13 @@ import (
"errors"
"fmt"
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta1"
flowcontrolapisv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta2"
flowcontrolapisv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
)
var (
@@ -36,7 +36,7 @@ var (
// FlowSchemaEnsurer ensures the specified bootstrap configuration objects
type FlowSchemaEnsurer interface {
Ensure([]*flowcontrolv1beta1.FlowSchema) error
Ensure([]*flowcontrolv1beta2.FlowSchema) error
}
// FlowSchemaRemover removes the specified bootstrap configuration objects
@@ -82,7 +82,7 @@ func NewFlowSchemaRemover(client flowcontrolclient.FlowSchemaInterface) FlowSche
// names that are candidates for deletion from the cluster.
// bootstrap: a set of hard coded FlowSchema configuration objects
// kube-apiserver maintains in-memory.
func GetFlowSchemaRemoveCandidate(client flowcontrolclient.FlowSchemaInterface, bootstrap []*flowcontrolv1beta1.FlowSchema) ([]string, error) {
func GetFlowSchemaRemoveCandidate(client flowcontrolclient.FlowSchemaInterface, bootstrap []*flowcontrolv1beta2.FlowSchema) ([]string, error) {
// TODO(101667): Use a lister here to avoid periodic LIST calls
fsList, err := client.List(context.TODO(), metav1.ListOptions{})
if err != nil {
@@ -107,7 +107,7 @@ type fsEnsurer struct {
wrapper configurationWrapper
}
func (e *fsEnsurer) Ensure(flowSchemas []*flowcontrolv1beta1.FlowSchema) error {
func (e *fsEnsurer) Ensure(flowSchemas []*flowcontrolv1beta2.FlowSchema) error {
for _, flowSchema := range flowSchemas {
if err := ensureConfiguration(e.wrapper, e.strategy, flowSchema); err != nil {
return err
@@ -138,7 +138,7 @@ func (fs *flowSchemaWrapper) TypeName() string {
}
func (fs *flowSchemaWrapper) Create(object runtime.Object) (runtime.Object, error) {
fsObject, ok := object.(*flowcontrolv1beta1.FlowSchema)
fsObject, ok := object.(*flowcontrolv1beta2.FlowSchema)
if !ok {
return nil, errObjectNotFlowSchema
}
@@ -147,7 +147,7 @@ func (fs *flowSchemaWrapper) Create(object runtime.Object) (runtime.Object, erro
}
func (fs *flowSchemaWrapper) Update(object runtime.Object) (runtime.Object, error) {
fsObject, ok := object.(*flowcontrolv1beta1.FlowSchema)
fsObject, ok := object.(*flowcontrolv1beta2.FlowSchema)
if !ok {
return nil, errObjectNotFlowSchema
}
@@ -164,11 +164,11 @@ func (fs *flowSchemaWrapper) Delete(name string) error {
}
func (fs *flowSchemaWrapper) CopySpec(bootstrap, current runtime.Object) error {
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta1.FlowSchema)
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta2.FlowSchema)
if !ok {
return errObjectNotFlowSchema
}
currentFS, ok := current.(*flowcontrolv1beta1.FlowSchema)
currentFS, ok := current.(*flowcontrolv1beta2.FlowSchema)
if !ok {
return errObjectNotFlowSchema
}
@@ -179,11 +179,11 @@ func (fs *flowSchemaWrapper) CopySpec(bootstrap, current runtime.Object) error {
}
func (fs *flowSchemaWrapper) HasSpecChanged(bootstrap, current runtime.Object) (bool, error) {
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta1.FlowSchema)
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta2.FlowSchema)
if !ok {
return false, errObjectNotFlowSchema
}
currentFS, ok := current.(*flowcontrolv1beta1.FlowSchema)
currentFS, ok := current.(*flowcontrolv1beta2.FlowSchema)
if !ok {
return false, errObjectNotFlowSchema
}
@@ -191,8 +191,8 @@ func (fs *flowSchemaWrapper) HasSpecChanged(bootstrap, current runtime.Object) (
return flowSchemaSpecChanged(bootstrapFS, currentFS), nil
}
func flowSchemaSpecChanged(expected, actual *flowcontrolv1beta1.FlowSchema) bool {
func flowSchemaSpecChanged(expected, actual *flowcontrolv1beta2.FlowSchema) bool {
copiedExpectedFlowSchema := expected.DeepCopy()
flowcontrolapisv1beta1.SetObjectDefaults_FlowSchema(copiedExpectedFlowSchema)
flowcontrolapisv1beta2.SetObjectDefaults_FlowSchema(copiedExpectedFlowSchema)
return !equality.Semantic.DeepEqual(copiedExpectedFlowSchema.Spec, actual.Spec)
}

View File

@@ -21,13 +21,13 @@ import (
"reflect"
"testing"
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
"k8s.io/client-go/kubernetes/fake"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta1"
flowcontrolapisv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta2"
flowcontrolapisv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
@@ -37,9 +37,9 @@ func TestEnsureFlowSchema(t *testing.T) {
tests := []struct {
name string
strategy func(flowcontrolclient.FlowSchemaInterface) FlowSchemaEnsurer
current *flowcontrolv1beta1.FlowSchema
bootstrap *flowcontrolv1beta1.FlowSchema
expected *flowcontrolv1beta1.FlowSchema
current *flowcontrolv1beta2.FlowSchema
bootstrap *flowcontrolv1beta2.FlowSchema
expected *flowcontrolv1beta2.FlowSchema
}{
// for suggested configurations
{
@@ -102,14 +102,14 @@ func TestEnsureFlowSchema(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := fake.NewSimpleClientset().FlowcontrolV1beta1().FlowSchemas()
client := fake.NewSimpleClientset().FlowcontrolV1beta2().FlowSchemas()
if test.current != nil {
client.Create(context.TODO(), test.current, metav1.CreateOptions{})
}
ensurer := test.strategy(client)
err := ensurer.Ensure([]*flowcontrolv1beta1.FlowSchema{test.bootstrap})
err := ensurer.Ensure([]*flowcontrolv1beta2.FlowSchema{test.bootstrap})
if err != nil {
t.Fatalf("Expected no error, but got: %v", err)
}
@@ -134,9 +134,9 @@ func TestEnsureFlowSchema(t *testing.T) {
func TestSuggestedFSEnsureStrategy_ShouldUpdate(t *testing.T) {
tests := []struct {
name string
current *flowcontrolv1beta1.FlowSchema
bootstrap *flowcontrolv1beta1.FlowSchema
newObjectExpected *flowcontrolv1beta1.FlowSchema
current *flowcontrolv1beta2.FlowSchema
bootstrap *flowcontrolv1beta2.FlowSchema
newObjectExpected *flowcontrolv1beta2.FlowSchema
}{
{
name: "auto update is enabled, first generation, spec does not match - spec update expected",
@@ -241,23 +241,23 @@ func TestSuggestedFSEnsureStrategy_ShouldUpdate(t *testing.T) {
}
func TestFlowSchemaSpecChanged(t *testing.T) {
fs1 := &flowcontrolv1beta1.FlowSchema{
Spec: flowcontrolv1beta1.FlowSchemaSpec{},
fs1 := &flowcontrolv1beta2.FlowSchema{
Spec: flowcontrolv1beta2.FlowSchemaSpec{},
}
fs2 := &flowcontrolv1beta1.FlowSchema{
Spec: flowcontrolv1beta1.FlowSchemaSpec{
fs2 := &flowcontrolv1beta2.FlowSchema{
Spec: flowcontrolv1beta2.FlowSchemaSpec{
MatchingPrecedence: 1,
},
}
fs1Defaulted := &flowcontrolv1beta1.FlowSchema{
Spec: flowcontrolv1beta1.FlowSchemaSpec{
MatchingPrecedence: flowcontrolapisv1beta1.FlowSchemaDefaultMatchingPrecedence,
fs1Defaulted := &flowcontrolv1beta2.FlowSchema{
Spec: flowcontrolv1beta2.FlowSchemaSpec{
MatchingPrecedence: flowcontrolapisv1beta2.FlowSchemaDefaultMatchingPrecedence,
},
}
testCases := []struct {
name string
expected *flowcontrolv1beta1.FlowSchema
actual *flowcontrolv1beta1.FlowSchema
expected *flowcontrolv1beta2.FlowSchema
actual *flowcontrolv1beta2.FlowSchema
specChanged bool
}{
{
@@ -290,7 +290,7 @@ func TestFlowSchemaSpecChanged(t *testing.T) {
func TestRemoveFlowSchema(t *testing.T) {
tests := []struct {
name string
current *flowcontrolv1beta1.FlowSchema
current *flowcontrolv1beta2.FlowSchema
bootstrapName string
removeExpected bool
}{
@@ -321,7 +321,7 @@ func TestRemoveFlowSchema(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := fake.NewSimpleClientset().FlowcontrolV1beta1().FlowSchemas()
client := fake.NewSimpleClientset().FlowcontrolV1beta2().FlowSchemas()
if test.current != nil {
client.Create(context.TODO(), test.current, metav1.CreateOptions{})
}
@@ -353,18 +353,18 @@ func TestRemoveFlowSchema(t *testing.T) {
func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
tests := []struct {
name string
current []*flowcontrolv1beta1.FlowSchema
bootstrap []*flowcontrolv1beta1.FlowSchema
current []*flowcontrolv1beta2.FlowSchema
bootstrap []*flowcontrolv1beta2.FlowSchema
expected []string
}{
{
name: "no object has been removed from the bootstrap configuration",
bootstrap: []*flowcontrolv1beta1.FlowSchema{
bootstrap: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs2", "pl2", 200).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs3", "pl3", 300).WithAutoUpdateAnnotation("true").Object(),
},
current: []*flowcontrolv1beta1.FlowSchema{
current: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs2", "pl2", 200).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs3", "pl3", 300).WithAutoUpdateAnnotation("true").Object(),
@@ -373,8 +373,8 @@ func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
},
{
name: "bootstrap is empty, all current objects with the annotation should be candidates",
bootstrap: []*flowcontrolv1beta1.FlowSchema{},
current: []*flowcontrolv1beta1.FlowSchema{
bootstrap: []*flowcontrolv1beta2.FlowSchema{},
current: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs2", "pl2", 200).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs3", "pl3", 300).Object(),
@@ -383,10 +383,10 @@ func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
},
{
name: "object(s) have been removed from the bootstrap configuration",
bootstrap: []*flowcontrolv1beta1.FlowSchema{
bootstrap: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
},
current: []*flowcontrolv1beta1.FlowSchema{
current: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs2", "pl2", 200).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs3", "pl3", 300).WithAutoUpdateAnnotation("true").Object(),
@@ -395,10 +395,10 @@ func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
},
{
name: "object(s) without the annotation key are ignored",
bootstrap: []*flowcontrolv1beta1.FlowSchema{
bootstrap: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
},
current: []*flowcontrolv1beta1.FlowSchema{
current: []*flowcontrolv1beta2.FlowSchema{
newFlowSchema("fs1", "pl1", 100).WithAutoUpdateAnnotation("true").Object(),
newFlowSchema("fs2", "pl2", 200).Object(),
newFlowSchema("fs3", "pl3", 300).Object(),
@@ -409,7 +409,7 @@ func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := fake.NewSimpleClientset().FlowcontrolV1beta1().FlowSchemas()
client := fake.NewSimpleClientset().FlowcontrolV1beta2().FlowSchemas()
for i := range test.current {
client.Create(context.TODO(), test.current[i], metav1.CreateOptions{})
}
@@ -427,17 +427,17 @@ func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
}
type fsBuilder struct {
object *flowcontrolv1beta1.FlowSchema
object *flowcontrolv1beta2.FlowSchema
}
func newFlowSchema(name, plName string, matchingPrecedence int32) *fsBuilder {
return &fsBuilder{
object: &flowcontrolv1beta1.FlowSchema{
object: &flowcontrolv1beta2.FlowSchema{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: flowcontrolv1beta1.FlowSchemaSpec{
PriorityLevelConfiguration: flowcontrolv1beta1.PriorityLevelConfigurationReference{
Spec: flowcontrolv1beta2.FlowSchemaSpec{
PriorityLevelConfiguration: flowcontrolv1beta2.PriorityLevelConfigurationReference{
Name: plName,
},
MatchingPrecedence: matchingPrecedence,
@@ -446,7 +446,7 @@ func newFlowSchema(name, plName string, matchingPrecedence int32) *fsBuilder {
}
}
func (b *fsBuilder) Object() *flowcontrolv1beta1.FlowSchema {
func (b *fsBuilder) Object() *flowcontrolv1beta2.FlowSchema {
return b.object
}
@@ -465,5 +465,5 @@ func setAnnotation(accessor metav1.Object, value string) {
accessor.SetAnnotations(map[string]string{})
}
accessor.GetAnnotations()[flowcontrolv1beta1.AutoUpdateAnnotationKey] = value
accessor.GetAnnotations()[flowcontrolv1beta2.AutoUpdateAnnotationKey] = value
}

View File

@@ -21,13 +21,13 @@ import (
"errors"
"fmt"
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta1"
flowcontrolapisv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta2"
flowcontrolapisv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
)
var (
@@ -36,7 +36,7 @@ var (
// PriorityLevelEnsurer ensures the specified bootstrap configuration objects
type PriorityLevelEnsurer interface {
Ensure([]*flowcontrolv1beta1.PriorityLevelConfiguration) error
Ensure([]*flowcontrolv1beta2.PriorityLevelConfiguration) error
}
// PriorityLevelRemover removes the specified bootstrap configuration objects
@@ -82,7 +82,7 @@ func NewPriorityLevelRemover(client flowcontrolclient.PriorityLevelConfiguration
// names that are candidates for removal from the cluster.
// bootstrap: a set of hard coded PriorityLevelConfiguration configuration
// objects kube-apiserver maintains in-memory.
func GetPriorityLevelRemoveCandidate(client flowcontrolclient.PriorityLevelConfigurationInterface, bootstrap []*flowcontrolv1beta1.PriorityLevelConfiguration) ([]string, error) {
func GetPriorityLevelRemoveCandidate(client flowcontrolclient.PriorityLevelConfigurationInterface, bootstrap []*flowcontrolv1beta2.PriorityLevelConfiguration) ([]string, error) {
// TODO(101667): Use a lister here to avoid periodic LIST calls
plList, err := client.List(context.TODO(), metav1.ListOptions{})
if err != nil {
@@ -107,7 +107,7 @@ type plEnsurer struct {
wrapper configurationWrapper
}
func (e *plEnsurer) Ensure(priorityLevels []*flowcontrolv1beta1.PriorityLevelConfiguration) error {
func (e *plEnsurer) Ensure(priorityLevels []*flowcontrolv1beta2.PriorityLevelConfiguration) error {
for _, priorityLevel := range priorityLevels {
if err := ensureConfiguration(e.wrapper, e.strategy, priorityLevel); err != nil {
return err
@@ -138,7 +138,7 @@ func (fs *priorityLevelConfigurationWrapper) TypeName() string {
}
func (fs *priorityLevelConfigurationWrapper) Create(object runtime.Object) (runtime.Object, error) {
plObject, ok := object.(*flowcontrolv1beta1.PriorityLevelConfiguration)
plObject, ok := object.(*flowcontrolv1beta2.PriorityLevelConfiguration)
if !ok {
return nil, errObjectNotPriorityLevel
}
@@ -147,7 +147,7 @@ func (fs *priorityLevelConfigurationWrapper) Create(object runtime.Object) (runt
}
func (fs *priorityLevelConfigurationWrapper) Update(object runtime.Object) (runtime.Object, error) {
fsObject, ok := object.(*flowcontrolv1beta1.PriorityLevelConfiguration)
fsObject, ok := object.(*flowcontrolv1beta2.PriorityLevelConfiguration)
if !ok {
return nil, errObjectNotPriorityLevel
}
@@ -164,11 +164,11 @@ func (fs *priorityLevelConfigurationWrapper) Delete(name string) error {
}
func (fs *priorityLevelConfigurationWrapper) CopySpec(bootstrap, current runtime.Object) error {
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta1.PriorityLevelConfiguration)
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta2.PriorityLevelConfiguration)
if !ok {
return errObjectNotPriorityLevel
}
currentFS, ok := current.(*flowcontrolv1beta1.PriorityLevelConfiguration)
currentFS, ok := current.(*flowcontrolv1beta2.PriorityLevelConfiguration)
if !ok {
return errObjectNotPriorityLevel
}
@@ -179,11 +179,11 @@ func (fs *priorityLevelConfigurationWrapper) CopySpec(bootstrap, current runtime
}
func (fs *priorityLevelConfigurationWrapper) HasSpecChanged(bootstrap, current runtime.Object) (bool, error) {
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta1.PriorityLevelConfiguration)
bootstrapFS, ok := bootstrap.(*flowcontrolv1beta2.PriorityLevelConfiguration)
if !ok {
return false, errObjectNotPriorityLevel
}
currentFS, ok := current.(*flowcontrolv1beta1.PriorityLevelConfiguration)
currentFS, ok := current.(*flowcontrolv1beta2.PriorityLevelConfiguration)
if !ok {
return false, errObjectNotPriorityLevel
}
@@ -191,8 +191,8 @@ func (fs *priorityLevelConfigurationWrapper) HasSpecChanged(bootstrap, current r
return priorityLevelSpecChanged(bootstrapFS, currentFS), nil
}
func priorityLevelSpecChanged(expected, actual *flowcontrolv1beta1.PriorityLevelConfiguration) bool {
func priorityLevelSpecChanged(expected, actual *flowcontrolv1beta2.PriorityLevelConfiguration) bool {
copiedExpectedPriorityLevel := expected.DeepCopy()
flowcontrolapisv1beta1.SetObjectDefaults_PriorityLevelConfiguration(copiedExpectedPriorityLevel)
flowcontrolapisv1beta2.SetObjectDefaults_PriorityLevelConfiguration(copiedExpectedPriorityLevel)
return !equality.Semantic.DeepEqual(copiedExpectedPriorityLevel.Spec, actual.Spec)
}

View File

@@ -21,13 +21,13 @@ import (
"reflect"
"testing"
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
"k8s.io/client-go/kubernetes/fake"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta1"
flowcontrolapisv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta2"
flowcontrolapisv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
@@ -37,9 +37,9 @@ func TestEnsurePriorityLevel(t *testing.T) {
tests := []struct {
name string
strategy func(flowcontrolclient.PriorityLevelConfigurationInterface) PriorityLevelEnsurer
current *flowcontrolv1beta1.PriorityLevelConfiguration
bootstrap *flowcontrolv1beta1.PriorityLevelConfiguration
expected *flowcontrolv1beta1.PriorityLevelConfiguration
current *flowcontrolv1beta2.PriorityLevelConfiguration
bootstrap *flowcontrolv1beta2.PriorityLevelConfiguration
expected *flowcontrolv1beta2.PriorityLevelConfiguration
}{
// for suggested configurations
{
@@ -102,14 +102,14 @@ func TestEnsurePriorityLevel(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := fake.NewSimpleClientset().FlowcontrolV1beta1().PriorityLevelConfigurations()
client := fake.NewSimpleClientset().FlowcontrolV1beta2().PriorityLevelConfigurations()
if test.current != nil {
client.Create(context.TODO(), test.current, metav1.CreateOptions{})
}
ensurer := test.strategy(client)
err := ensurer.Ensure([]*flowcontrolv1beta1.PriorityLevelConfiguration{test.bootstrap})
err := ensurer.Ensure([]*flowcontrolv1beta2.PriorityLevelConfiguration{test.bootstrap})
if err != nil {
t.Fatalf("Expected no error, but got: %v", err)
}
@@ -134,9 +134,9 @@ func TestEnsurePriorityLevel(t *testing.T) {
func TestSuggestedPLEnsureStrategy_ShouldUpdate(t *testing.T) {
tests := []struct {
name string
current *flowcontrolv1beta1.PriorityLevelConfiguration
bootstrap *flowcontrolv1beta1.PriorityLevelConfiguration
newObjectExpected *flowcontrolv1beta1.PriorityLevelConfiguration
current *flowcontrolv1beta2.PriorityLevelConfiguration
bootstrap *flowcontrolv1beta2.PriorityLevelConfiguration
newObjectExpected *flowcontrolv1beta2.PriorityLevelConfiguration
}{
{
name: "auto update is enabled, first generation, spec does not match - spec update expected",
@@ -241,39 +241,39 @@ func TestSuggestedPLEnsureStrategy_ShouldUpdate(t *testing.T) {
}
func TestPriorityLevelSpecChanged(t *testing.T) {
pl1 := &flowcontrolv1beta1.PriorityLevelConfiguration{
Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{
Type: flowcontrolv1beta1.PriorityLevelEnablementLimited,
Limited: &flowcontrolv1beta1.LimitedPriorityLevelConfiguration{
LimitResponse: flowcontrolv1beta1.LimitResponse{
Type: flowcontrolv1beta1.LimitResponseTypeReject,
pl1 := &flowcontrolv1beta2.PriorityLevelConfiguration{
Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{
Type: flowcontrolv1beta2.PriorityLevelEnablementLimited,
Limited: &flowcontrolv1beta2.LimitedPriorityLevelConfiguration{
LimitResponse: flowcontrolv1beta2.LimitResponse{
Type: flowcontrolv1beta2.LimitResponseTypeReject,
},
},
},
}
pl2 := &flowcontrolv1beta1.PriorityLevelConfiguration{
Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{
Type: flowcontrolv1beta1.PriorityLevelEnablementLimited,
Limited: &flowcontrolv1beta1.LimitedPriorityLevelConfiguration{
pl2 := &flowcontrolv1beta2.PriorityLevelConfiguration{
Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{
Type: flowcontrolv1beta2.PriorityLevelEnablementLimited,
Limited: &flowcontrolv1beta2.LimitedPriorityLevelConfiguration{
AssuredConcurrencyShares: 1,
},
},
}
pl1Defaulted := &flowcontrolv1beta1.PriorityLevelConfiguration{
Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{
Type: flowcontrolv1beta1.PriorityLevelEnablementLimited,
Limited: &flowcontrolv1beta1.LimitedPriorityLevelConfiguration{
AssuredConcurrencyShares: flowcontrolapisv1beta1.PriorityLevelConfigurationDefaultAssuredConcurrencyShares,
LimitResponse: flowcontrolv1beta1.LimitResponse{
Type: flowcontrolv1beta1.LimitResponseTypeReject,
pl1Defaulted := &flowcontrolv1beta2.PriorityLevelConfiguration{
Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{
Type: flowcontrolv1beta2.PriorityLevelEnablementLimited,
Limited: &flowcontrolv1beta2.LimitedPriorityLevelConfiguration{
AssuredConcurrencyShares: flowcontrolapisv1beta2.PriorityLevelConfigurationDefaultAssuredConcurrencyShares,
LimitResponse: flowcontrolv1beta2.LimitResponse{
Type: flowcontrolv1beta2.LimitResponseTypeReject,
},
},
},
}
testCases := []struct {
name string
expected *flowcontrolv1beta1.PriorityLevelConfiguration
actual *flowcontrolv1beta1.PriorityLevelConfiguration
expected *flowcontrolv1beta2.PriorityLevelConfiguration
actual *flowcontrolv1beta2.PriorityLevelConfiguration
specChanged bool
}{
{
@@ -306,7 +306,7 @@ func TestPriorityLevelSpecChanged(t *testing.T) {
func TestRemovePriorityLevelConfiguration(t *testing.T) {
tests := []struct {
name string
current *flowcontrolv1beta1.PriorityLevelConfiguration
current *flowcontrolv1beta2.PriorityLevelConfiguration
bootstrapName string
removeExpected bool
}{
@@ -337,7 +337,7 @@ func TestRemovePriorityLevelConfiguration(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := fake.NewSimpleClientset().FlowcontrolV1beta1().PriorityLevelConfigurations()
client := fake.NewSimpleClientset().FlowcontrolV1beta2().PriorityLevelConfigurations()
if test.current != nil {
client.Create(context.TODO(), test.current, metav1.CreateOptions{})
}
@@ -369,18 +369,18 @@ func TestRemovePriorityLevelConfiguration(t *testing.T) {
func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
tests := []struct {
name string
current []*flowcontrolv1beta1.PriorityLevelConfiguration
bootstrap []*flowcontrolv1beta1.PriorityLevelConfiguration
current []*flowcontrolv1beta2.PriorityLevelConfiguration
bootstrap []*flowcontrolv1beta2.PriorityLevelConfiguration
expected []string
}{
{
name: "no object has been removed from the bootstrap configuration",
bootstrap: []*flowcontrolv1beta1.PriorityLevelConfiguration{
bootstrap: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl2").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl3").WithAutoUpdateAnnotation("true").Object(),
},
current: []*flowcontrolv1beta1.PriorityLevelConfiguration{
current: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl2").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl3").WithAutoUpdateAnnotation("true").Object(),
@@ -389,8 +389,8 @@ func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
},
{
name: "bootstrap is empty, all current objects with the annotation should be candidates",
bootstrap: []*flowcontrolv1beta1.PriorityLevelConfiguration{},
current: []*flowcontrolv1beta1.PriorityLevelConfiguration{
bootstrap: []*flowcontrolv1beta2.PriorityLevelConfiguration{},
current: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl2").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl3").Object(),
@@ -399,10 +399,10 @@ func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
},
{
name: "object(s) have been removed from the bootstrap configuration",
bootstrap: []*flowcontrolv1beta1.PriorityLevelConfiguration{
bootstrap: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
},
current: []*flowcontrolv1beta1.PriorityLevelConfiguration{
current: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl2").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl3").WithAutoUpdateAnnotation("true").Object(),
@@ -411,10 +411,10 @@ func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
},
{
name: "object(s) without the annotation key are ignored",
bootstrap: []*flowcontrolv1beta1.PriorityLevelConfiguration{
bootstrap: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
},
current: []*flowcontrolv1beta1.PriorityLevelConfiguration{
current: []*flowcontrolv1beta2.PriorityLevelConfiguration{
newPLConfiguration("pl1").WithAutoUpdateAnnotation("true").Object(),
newPLConfiguration("pl2").Object(),
newPLConfiguration("pl3").Object(),
@@ -425,7 +425,7 @@ func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := fake.NewSimpleClientset().FlowcontrolV1beta1().PriorityLevelConfigurations()
client := fake.NewSimpleClientset().FlowcontrolV1beta2().PriorityLevelConfigurations()
for i := range test.current {
client.Create(context.TODO(), test.current[i], metav1.CreateOptions{})
}
@@ -443,12 +443,12 @@ func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
}
type plBuilder struct {
object *flowcontrolv1beta1.PriorityLevelConfiguration
object *flowcontrolv1beta2.PriorityLevelConfiguration
}
func newPLConfiguration(name string) *plBuilder {
return &plBuilder{
object: &flowcontrolv1beta1.PriorityLevelConfiguration{
object: &flowcontrolv1beta2.PriorityLevelConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
@@ -456,7 +456,7 @@ func newPLConfiguration(name string) *plBuilder {
}
}
func (b *plBuilder) Object() *flowcontrolv1beta1.PriorityLevelConfiguration {
func (b *plBuilder) Object() *flowcontrolv1beta2.PriorityLevelConfiguration {
return b.object
}
@@ -471,11 +471,11 @@ func (b *plBuilder) WithAutoUpdateAnnotation(value string) *plBuilder {
}
func (b *plBuilder) WithLimited(assuredConcurrencyShares int32) *plBuilder {
b.object.Spec.Type = flowcontrolv1beta1.PriorityLevelEnablementLimited
b.object.Spec.Limited = &flowcontrolv1beta1.LimitedPriorityLevelConfiguration{
b.object.Spec.Type = flowcontrolv1beta2.PriorityLevelEnablementLimited
b.object.Spec.Limited = &flowcontrolv1beta2.LimitedPriorityLevelConfiguration{
AssuredConcurrencyShares: assuredConcurrencyShares,
LimitResponse: flowcontrolv1beta1.LimitResponse{
Type: flowcontrolv1beta1.LimitResponseTypeReject,
LimitResponse: flowcontrolv1beta2.LimitResponse{
Type: flowcontrolv1beta2.LimitResponseTypeReject,
},
}
return b
@@ -488,8 +488,8 @@ func (b *plBuilder) WithQueuing(queues, handSize, queueLengthLimit int32) *plBui
return b
}
limited.LimitResponse.Type = flowcontrolv1beta1.LimitResponseTypeQueue
limited.LimitResponse.Queuing = &flowcontrolv1beta1.QueuingConfiguration{
limited.LimitResponse.Type = flowcontrolv1beta2.LimitResponseTypeQueue
limited.LimitResponse.Queuing = &flowcontrolv1beta2.QueuingConfiguration{
Queues: queues,
HandSize: handSize,
QueueLengthLimit: queueLengthLimit,

View File

@@ -53,6 +53,9 @@ func (flowSchemaStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.S
"flowcontrol.apiserver.k8s.io/v1beta1": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
"flowcontrol.apiserver.k8s.io/v1beta2": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
}
return fields
@@ -129,6 +132,10 @@ func (flowSchemaStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*field
fieldpath.MakePathOrDie("metadata"),
fieldpath.MakePathOrDie("spec"),
),
"flowcontrol.apiserver.k8s.io/v1beta2": fieldpath.NewSet(
fieldpath.MakePathOrDie("metadata"),
fieldpath.MakePathOrDie("spec"),
),
}
return fields

View File

@@ -53,6 +53,9 @@ func (priorityLevelConfigurationStrategy) GetResetFields() map[fieldpath.APIVers
"flowcontrol.apiserver.k8s.io/v1beta1": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
"flowcontrol.apiserver.k8s.io/v1beta2": fieldpath.NewSet(
fieldpath.MakePathOrDie("status"),
),
}
return fields
@@ -129,6 +132,10 @@ func (priorityLevelConfigurationStatusStrategy) GetResetFields() map[fieldpath.A
fieldpath.MakePathOrDie("spec"),
fieldpath.MakePathOrDie("metadata"),
),
"flowcontrol.apiserver.k8s.io/v1beta2": fieldpath.NewSet(
fieldpath.MakePathOrDie("spec"),
fieldpath.MakePathOrDie("metadata"),
),
}
return fields

View File

@@ -27,12 +27,13 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
serverstorage "k8s.io/apiserver/pkg/server/storage"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta1"
flowcontrolclient "k8s.io/client-go/kubernetes/typed/flowcontrol/v1beta2"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/flowcontrol"
flowcontrolapisv1alpha1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1alpha1"
flowcontrolapisv1beta1 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta1"
flowcontrolapisv1beta2 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta2"
"k8s.io/kubernetes/pkg/registry/flowcontrol/ensurer"
flowschemastore "k8s.io/kubernetes/pkg/registry/flowcontrol/flowschema/storage"
prioritylevelconfigurationstore "k8s.io/kubernetes/pkg/registry/flowcontrol/prioritylevelconfiguration/storage"
@@ -66,6 +67,14 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag
apiGroupInfo.VersionedResourcesStorageMap[flowcontrolapisv1beta1.SchemeGroupVersion.Version] = flowControlStorage
}
if apiResourceConfigSource.VersionEnabled(flowcontrolapisv1beta2.SchemeGroupVersion) {
flowControlStorage, err := p.storage(apiResourceConfigSource, restOptionsGetter)
if err != nil {
return genericapiserver.APIGroupInfo{}, false, err
}
apiGroupInfo.VersionedResourcesStorageMap[flowcontrolapisv1beta2.SchemeGroupVersion.Version] = flowControlStorage
}
return apiGroupInfo, true, nil
}
@@ -144,7 +153,7 @@ func ensureAPFBootstrapConfiguration(hookContext genericapiserver.PostStartHookC
return nil
}
func ensure(clientset flowcontrolclient.FlowcontrolV1beta1Interface) error {
func ensure(clientset flowcontrolclient.FlowcontrolV1beta2Interface) error {
if err := ensureSuggestedConfiguration(clientset); err != nil {
// We should not attempt creation of mandatory objects if ensuring the suggested
// configuration resulted in an error.
@@ -163,7 +172,7 @@ func ensure(clientset flowcontrolclient.FlowcontrolV1beta1Interface) error {
return nil
}
func ensureSuggestedConfiguration(clientset flowcontrolclient.FlowcontrolV1beta1Interface) error {
func ensureSuggestedConfiguration(clientset flowcontrolclient.FlowcontrolV1beta2Interface) error {
fsEnsurer := ensurer.NewSuggestedFlowSchemaEnsurer(clientset.FlowSchemas())
if err := fsEnsurer.Ensure(flowcontrolbootstrap.SuggestedFlowSchemas); err != nil {
return err
@@ -173,7 +182,7 @@ func ensureSuggestedConfiguration(clientset flowcontrolclient.FlowcontrolV1beta1
return plEnsurer.Ensure(flowcontrolbootstrap.SuggestedPriorityLevelConfigurations)
}
func ensureMandatoryConfiguration(clientset flowcontrolclient.FlowcontrolV1beta1Interface) error {
func ensureMandatoryConfiguration(clientset flowcontrolclient.FlowcontrolV1beta2Interface) error {
fsEnsurer := ensurer.NewMandatoryFlowSchemaEnsurer(clientset.FlowSchemas())
if err := fsEnsurer.Ensure(flowcontrolbootstrap.MandatoryFlowSchemas); err != nil {
return err
@@ -183,7 +192,7 @@ func ensureMandatoryConfiguration(clientset flowcontrolclient.FlowcontrolV1beta1
return plEnsurer.Ensure(flowcontrolbootstrap.MandatoryPriorityLevelConfigurations)
}
func removeConfiguration(clientset flowcontrolclient.FlowcontrolV1beta1Interface) error {
func removeConfiguration(clientset flowcontrolclient.FlowcontrolV1beta2Interface) error {
if err := removeFlowSchema(clientset.FlowSchemas()); err != nil {
return err
}