mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
apiserver: fix lint issue, defaulting and validation test for flowcontrol v1
This commit is contained in:
parent
90c091deda
commit
430c226709
@ -188,6 +188,8 @@ func TestDefaulting(t *testing.T) {
|
|||||||
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta2", Kind: "PriorityLevelConfigurationList"}: {},
|
{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: "PriorityLevelConfiguration"}: {},
|
||||||
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta3", Kind: "PriorityLevelConfigurationList"}: {},
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1beta3", Kind: "PriorityLevelConfigurationList"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1", Kind: "PriorityLevelConfiguration"}: {},
|
||||||
|
{Group: "flowcontrol.apiserver.k8s.io", Version: "v1", 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))
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
flowcontrolv1 "k8s.io/api/flowcontrol/v1"
|
flowcontrolv1 "k8s.io/api/flowcontrol/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
||||||
@ -45,8 +45,8 @@ func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
|||||||
Spec: flowcontrolv1.PriorityLevelConfigurationSpec{
|
Spec: flowcontrolv1.PriorityLevelConfigurationSpec{
|
||||||
Type: flowcontrolv1.PriorityLevelEnablementExempt,
|
Type: flowcontrolv1.PriorityLevelEnablementExempt,
|
||||||
Exempt: &flowcontrolv1.ExemptPriorityLevelConfiguration{
|
Exempt: &flowcontrolv1.ExemptPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: pointer.Int32(0),
|
NominalConcurrencyShares: ptr.To(int32(0)),
|
||||||
LendablePercent: pointer.Int32(0),
|
LendablePercent: ptr.To(int32(0)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -69,7 +69,7 @@ func TestDefaultWithPriorityLevelConfiguration(t *testing.T) {
|
|||||||
Type: flowcontrolv1.PriorityLevelEnablementLimited,
|
Type: flowcontrolv1.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrolv1.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrolv1.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 5,
|
NominalConcurrencyShares: 5,
|
||||||
LendablePercent: pointer.Int32(0),
|
LendablePercent: ptr.To(int32(0)),
|
||||||
LimitResponse: flowcontrolv1.LimitResponse{
|
LimitResponse: flowcontrolv1.LimitResponse{
|
||||||
Type: flowcontrolv1.LimitResponseTypeReject,
|
Type: flowcontrolv1.LimitResponseTypeReject,
|
||||||
},
|
},
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
flowcontrolv1 "k8s.io/api/flowcontrol/v1"
|
||||||
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
|
flowcontrolv1beta1 "k8s.io/api/flowcontrol/v1beta1"
|
||||||
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
|
flowcontrolv1beta2 "k8s.io/api/flowcontrol/v1beta2"
|
||||||
flowcontrolv1beta3 "k8s.io/api/flowcontrol/v1beta3"
|
flowcontrolv1beta3 "k8s.io/api/flowcontrol/v1beta3"
|
||||||
@ -1290,9 +1291,7 @@ func TestValidateLimitedPriorityLevelConfiguration(t *testing.T) {
|
|||||||
concurrencyShares: 0,
|
concurrencyShares: 0,
|
||||||
errExpected: errExpectedFn("nominalConcurrencyShares"),
|
errExpected: errExpectedFn("nominalConcurrencyShares"),
|
||||||
}, {
|
}, {
|
||||||
// let's simulate a post v1beta3 version, we expect the
|
requestVersion: flowcontrolv1.SchemeGroupVersion,
|
||||||
// error to return the new field introduced in v1beta3.
|
|
||||||
requestVersion: schema.GroupVersion{Group: flowcontrolv1beta3.GroupName, Version: "v1"},
|
|
||||||
concurrencyShares: 0,
|
concurrencyShares: 0,
|
||||||
errExpected: errExpectedFn("nominalConcurrencyShares"),
|
errExpected: errExpectedFn("nominalConcurrencyShares"),
|
||||||
}, {
|
}, {
|
||||||
@ -1395,7 +1394,7 @@ func TestValidateLimitedPriorityLevelConfigurationWithBorrowing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
specPath := field.NewPath("spec").Child("limited")
|
specPath := field.NewPath("spec").Child("limited")
|
||||||
|
|
||||||
errGot := ValidateLimitedPriorityLevelConfiguration(configuration, flowcontrolv1beta3.SchemeGroupVersion, specPath)
|
errGot := ValidateLimitedPriorityLevelConfiguration(configuration, flowcontrolv1.SchemeGroupVersion, specPath)
|
||||||
if !cmp.Equal(test.errExpected, errGot) {
|
if !cmp.Equal(test.errExpected, errGot) {
|
||||||
t.Errorf("Expected error: %v, diff: %s", test.errExpected, cmp.Diff(test.errExpected, errGot))
|
t.Errorf("Expected error: %v, diff: %s", test.errExpected, cmp.Diff(test.errExpected, errGot))
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func (s *strategy[ObjectType]) ReviseIfNeeded(objectOps objectLocalOps[ObjectTyp
|
|||||||
// shouldUpdateSpec inspects the auto-update annotation key and generation field to determine
|
// shouldUpdateSpec inspects the auto-update annotation key and generation field to determine
|
||||||
// whether the config object should be auto-updated.
|
// whether the config object should be auto-updated.
|
||||||
func shouldUpdateSpec(accessor metav1.Object) bool {
|
func shouldUpdateSpec(accessor metav1.Object) bool {
|
||||||
value, _ := accessor.GetAnnotations()[flowcontrolv1.AutoUpdateAnnotationKey]
|
value := accessor.GetAnnotations()[flowcontrolv1.AutoUpdateAnnotationKey]
|
||||||
if autoUpdate, err := strconv.ParseBool(value); err == nil {
|
if autoUpdate, err := strconv.ParseBool(value); err == nil {
|
||||||
return autoUpdate
|
return autoUpdate
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,9 @@ func Test_GetMaxSeats(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c.digestConfigObjects([]*flowcontrolv1.PriorityLevelConfiguration{testPriorityLevel}, nil)
|
if _, err := c.digestConfigObjects([]*flowcontrolv1.PriorityLevelConfiguration{testPriorityLevel}, nil); err != nil {
|
||||||
|
t.Errorf("unexpected error from digestConfigObjects: %v", err)
|
||||||
|
}
|
||||||
maxSeats := c.GetMaxSeats("test-pl")
|
maxSeats := c.GetMaxSeats("test-pl")
|
||||||
if maxSeats != testcase.expectedMaxSeats {
|
if maxSeats != testcase.expectedMaxSeats {
|
||||||
t.Errorf("unexpected max seats, got=%d, want=%d", maxSeats, testcase.expectedMaxSeats)
|
t.Errorf("unexpected max seats, got=%d, want=%d", maxSeats, testcase.expectedMaxSeats)
|
||||||
|
Loading…
Reference in New Issue
Block a user