mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
apiserver: set borrowing defaults for flowcontrol API
This commit is contained in:
parent
a76223f8da
commit
ca949d5188
@ -176,6 +176,14 @@ func TestDefaulting(t *testing.T) {
|
|||||||
{Group: "scheduling.k8s.io", Version: "v1alpha1", Kind: "PriorityClassList"}: {},
|
{Group: "scheduling.k8s.io", Version: "v1alpha1", Kind: "PriorityClassList"}: {},
|
||||||
{Group: "scheduling.k8s.io", Version: "v1beta1", Kind: "PriorityClassList"}: {},
|
{Group: "scheduling.k8s.io", Version: "v1beta1", Kind: "PriorityClassList"}: {},
|
||||||
{Group: "scheduling.k8s.io", Version: "v1", Kind: "PriorityClassList"}: {},
|
{Group: "scheduling.k8s.io", Version: "v1", Kind: "PriorityClassList"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1alpha1", Kind: "PriorityLevelConfiguration"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1alpha1", Kind: "PriorityLevelConfigurationList"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta1", Kind: "PriorityLevelConfiguration"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta1", Kind: "PriorityLevelConfigurationList"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta2", Kind: "PriorityLevelConfiguration"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta2", Kind: "PriorityLevelConfigurationList"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta3", Kind: "PriorityLevelConfiguration"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta3", Kind: "PriorityLevelConfigurationList"}: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
f := fuzz.New().NilChance(.5).NumElements(1, 1).RandSource(rand.NewSource(1))
|
f := fuzz.New().NilChance(.5).NumElements(1, 1).RandSource(rand.NewSource(1))
|
||||||
|
@ -38,6 +38,7 @@ import (
|
|||||||
corefuzzer "k8s.io/kubernetes/pkg/apis/core/fuzzer"
|
corefuzzer "k8s.io/kubernetes/pkg/apis/core/fuzzer"
|
||||||
discoveryfuzzer "k8s.io/kubernetes/pkg/apis/discovery/fuzzer"
|
discoveryfuzzer "k8s.io/kubernetes/pkg/apis/discovery/fuzzer"
|
||||||
extensionsfuzzer "k8s.io/kubernetes/pkg/apis/extensions/fuzzer"
|
extensionsfuzzer "k8s.io/kubernetes/pkg/apis/extensions/fuzzer"
|
||||||
|
flowcontrolfuzzer "k8s.io/kubernetes/pkg/apis/flowcontrol/fuzzer"
|
||||||
networkingfuzzer "k8s.io/kubernetes/pkg/apis/networking/fuzzer"
|
networkingfuzzer "k8s.io/kubernetes/pkg/apis/networking/fuzzer"
|
||||||
policyfuzzer "k8s.io/kubernetes/pkg/apis/policy/fuzzer"
|
policyfuzzer "k8s.io/kubernetes/pkg/apis/policy/fuzzer"
|
||||||
rbacfuzzer "k8s.io/kubernetes/pkg/apis/rbac/fuzzer"
|
rbacfuzzer "k8s.io/kubernetes/pkg/apis/rbac/fuzzer"
|
||||||
@ -107,4 +108,5 @@ var FuzzerFuncs = fuzzer.MergeFuzzerFuncs(
|
|||||||
metafuzzer.Funcs,
|
metafuzzer.Funcs,
|
||||||
schedulingfuzzer.Funcs,
|
schedulingfuzzer.Funcs,
|
||||||
discoveryfuzzer.Funcs,
|
discoveryfuzzer.Funcs,
|
||||||
|
flowcontrolfuzzer.Funcs,
|
||||||
)
|
)
|
||||||
|
37
pkg/apis/flowcontrol/fuzzer/fuzzer.go
Normal file
37
pkg/apis/flowcontrol/fuzzer/fuzzer.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 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 fuzzer
|
||||||
|
|
||||||
|
import (
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
|
||||||
|
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/flowcontrol"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Funcs returns the fuzzer functions for the flowcontrol api group.
|
||||||
|
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||||
|
return []interface{}{
|
||||||
|
func(obj *flowcontrol.LimitedPriorityLevelConfiguration, c fuzz.Continue) {
|
||||||
|
c.FuzzNoCustom(obj) // fuzz self without calling this function again
|
||||||
|
if obj.LendablePercent == nil {
|
||||||
|
i := int32(0)
|
||||||
|
obj.LendablePercent = &i
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,10 @@ func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1alpha1.LimitedPriorit
|
|||||||
if lplc.AssuredConcurrencyShares == 0 {
|
if lplc.AssuredConcurrencyShares == 0 {
|
||||||
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
|
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
|
||||||
}
|
}
|
||||||
|
if lplc.LendablePercent == nil {
|
||||||
|
lplc.LendablePercent = new(int32)
|
||||||
|
*lplc.LendablePercent = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults_FlowSchema sets default values for flow schema
|
// SetDefaults_FlowSchema sets default values for flow schema
|
||||||
|
79
pkg/apis/flowcontrol/v1alpha1/defaults_test.go
Normal file
79
pkg/apis/flowcontrol/v1alpha1/defaults_test.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 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 v1alpha1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
flowcontrolv1alpha1 "k8s.io/api/flowcontrol/v1alpha1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
original runtime.Object
|
||||||
|
expected runtime.Object
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "LendablePercent is not specified, should default to zero",
|
||||||
|
original: &flowcontrolv1alpha1.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1alpha1.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1alpha1.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1alpha1.LimitedPriorityLevelConfiguration{
|
||||||
|
AssuredConcurrencyShares: 5,
|
||||||
|
LimitResponse: flowcontrolv1alpha1.LimitResponse{
|
||||||
|
Type: flowcontrolv1alpha1.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &flowcontrolv1alpha1.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1alpha1.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1alpha1.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1alpha1.LimitedPriorityLevelConfiguration{
|
||||||
|
AssuredConcurrencyShares: 5,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
|
LimitResponse: flowcontrolv1alpha1.LimitResponse{
|
||||||
|
Type: flowcontrolv1alpha1.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme := runtime.NewScheme()
|
||||||
|
if err := AddToScheme(scheme); err != nil {
|
||||||
|
t.Fatalf("Failed to add to scheme: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
original := test.original
|
||||||
|
expected := test.expected
|
||||||
|
|
||||||
|
scheme.Default(original)
|
||||||
|
if !reflect.DeepEqual(expected, original) {
|
||||||
|
t.Errorf("Expected defaulting to work - diff: %s", cmp.Diff(expected, original))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,10 @@ func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta1.LimitedPriority
|
|||||||
if lplc.AssuredConcurrencyShares == 0 {
|
if lplc.AssuredConcurrencyShares == 0 {
|
||||||
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
|
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
|
||||||
}
|
}
|
||||||
|
if lplc.LendablePercent == nil {
|
||||||
|
lplc.LendablePercent = new(int32)
|
||||||
|
*lplc.LendablePercent = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults_FlowSchema sets default values for flow schema
|
// SetDefaults_FlowSchema sets default values for flow schema
|
||||||
|
79
pkg/apis/flowcontrol/v1beta1/defaults_test.go
Normal file
79
pkg/apis/flowcontrol/v1beta1/defaults_test.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 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 (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
original runtime.Object
|
||||||
|
expected runtime.Object
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "LendablePercent is not specified, should default to zero",
|
||||||
|
original: &flowcontrolv1beta1.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1beta1.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1beta1.LimitedPriorityLevelConfiguration{
|
||||||
|
AssuredConcurrencyShares: 5,
|
||||||
|
LimitResponse: flowcontrolv1beta1.LimitResponse{
|
||||||
|
Type: flowcontrolv1beta1.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &flowcontrolv1beta1.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1beta1.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1beta1.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1beta1.LimitedPriorityLevelConfiguration{
|
||||||
|
AssuredConcurrencyShares: 5,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
|
LimitResponse: flowcontrolv1beta1.LimitResponse{
|
||||||
|
Type: flowcontrolv1beta1.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme := runtime.NewScheme()
|
||||||
|
if err := AddToScheme(scheme); err != nil {
|
||||||
|
t.Fatalf("Failed to add to scheme: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
original := test.original
|
||||||
|
expected := test.expected
|
||||||
|
|
||||||
|
scheme.Default(original)
|
||||||
|
if !reflect.DeepEqual(expected, original) {
|
||||||
|
t.Errorf("Expected defaulting to work - diff: %s", cmp.Diff(expected, original))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,10 @@ func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta2.LimitedPriority
|
|||||||
if lplc.AssuredConcurrencyShares == 0 {
|
if lplc.AssuredConcurrencyShares == 0 {
|
||||||
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
|
lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
|
||||||
}
|
}
|
||||||
|
if lplc.LendablePercent == nil {
|
||||||
|
lplc.LendablePercent = new(int32)
|
||||||
|
*lplc.LendablePercent = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults_FlowSchema sets default values for flow schema
|
// SetDefaults_FlowSchema sets default values for flow schema
|
||||||
|
79
pkg/apis/flowcontrol/v1beta2/defaults_test.go
Normal file
79
pkg/apis/flowcontrol/v1beta2/defaults_test.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 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 v1beta2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
original runtime.Object
|
||||||
|
expected runtime.Object
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "LendablePercent is not specified, should default to zero",
|
||||||
|
original: &flowcontrolv1beta2.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1beta2.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1beta2.LimitedPriorityLevelConfiguration{
|
||||||
|
AssuredConcurrencyShares: 5,
|
||||||
|
LimitResponse: flowcontrolv1beta2.LimitResponse{
|
||||||
|
Type: flowcontrolv1beta2.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &flowcontrolv1beta2.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1beta2.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1beta2.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1beta2.LimitedPriorityLevelConfiguration{
|
||||||
|
AssuredConcurrencyShares: 5,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
|
LimitResponse: flowcontrolv1beta2.LimitResponse{
|
||||||
|
Type: flowcontrolv1beta2.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme := runtime.NewScheme()
|
||||||
|
if err := AddToScheme(scheme); err != nil {
|
||||||
|
t.Fatalf("Failed to add to scheme: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
original := test.original
|
||||||
|
expected := test.expected
|
||||||
|
|
||||||
|
scheme.Default(original)
|
||||||
|
if !reflect.DeepEqual(expected, original) {
|
||||||
|
t.Errorf("Expected defaulting to work - diff: %s", cmp.Diff(expected, original))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,10 @@ func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1beta3.LimitedPriority
|
|||||||
if lplc.NominalConcurrencyShares == 0 {
|
if lplc.NominalConcurrencyShares == 0 {
|
||||||
lplc.NominalConcurrencyShares = PriorityLevelConfigurationDefaultNominalConcurrencyShares
|
lplc.NominalConcurrencyShares = PriorityLevelConfigurationDefaultNominalConcurrencyShares
|
||||||
}
|
}
|
||||||
|
if lplc.LendablePercent == nil {
|
||||||
|
lplc.LendablePercent = new(int32)
|
||||||
|
*lplc.LendablePercent = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults_FlowSchema sets default values for flow schema
|
// SetDefaults_FlowSchema sets default values for flow schema
|
||||||
|
79
pkg/apis/flowcontrol/v1beta3/defaults_test.go
Normal file
79
pkg/apis/flowcontrol/v1beta3/defaults_test.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2022 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 v1beta3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
flowcontrolv1beta3 "k8s.io/api/flowcontrol/v1beta3"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
original runtime.Object
|
||||||
|
expected runtime.Object
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "LendablePercent is not specified, should default to zero",
|
||||||
|
original: &flowcontrolv1beta3.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1beta3.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1beta3.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1beta3.LimitedPriorityLevelConfiguration{
|
||||||
|
NominalConcurrencyShares: 5,
|
||||||
|
LimitResponse: flowcontrolv1beta3.LimitResponse{
|
||||||
|
Type: flowcontrolv1beta3.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &flowcontrolv1beta3.PriorityLevelConfiguration{
|
||||||
|
Spec: flowcontrolv1beta3.PriorityLevelConfigurationSpec{
|
||||||
|
Type: flowcontrolv1beta3.PriorityLevelEnablementLimited,
|
||||||
|
Limited: &flowcontrolv1beta3.LimitedPriorityLevelConfiguration{
|
||||||
|
NominalConcurrencyShares: 5,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
|
LimitResponse: flowcontrolv1beta3.LimitResponse{
|
||||||
|
Type: flowcontrolv1beta3.LimitResponseTypeReject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme := runtime.NewScheme()
|
||||||
|
if err := AddToScheme(scheme); err != nil {
|
||||||
|
t.Fatalf("Failed to add to scheme: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
original := test.original
|
||||||
|
expected := test.expected
|
||||||
|
|
||||||
|
scheme.Default(original)
|
||||||
|
if !reflect.DeepEqual(expected, original) {
|
||||||
|
t.Errorf("Expected defaulting to work - diff: %s", cmp.Diff(expected, original))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user