mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
apiserver: fix defaulting for apf bootstrap configuration
This commit is contained in:
parent
284020cfdf
commit
424b23bb15
@ -17,31 +17,45 @@ limitations under the License.
|
|||||||
package internalbootstrap
|
package internalbootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
flowcontrol "k8s.io/api/flowcontrol/v1beta3"
|
flowcontrol "k8s.io/api/flowcontrol/v1beta3"
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
|
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMandatoryAlreadyDefaulted(t *testing.T) {
|
func TestBootstrapConfigurationWithDefaulted(t *testing.T) {
|
||||||
scheme := NewAPFScheme()
|
scheme := NewAPFScheme()
|
||||||
for _, obj := range bootstrap.MandatoryFlowSchemas {
|
|
||||||
obj2 := obj.DeepCopyObject().(*flowcontrol.FlowSchema)
|
bootstrapFlowSchemas := make([]*flowcontrol.FlowSchema, 0)
|
||||||
scheme.Default(obj2)
|
bootstrapFlowSchemas = append(bootstrapFlowSchemas, bootstrap.MandatoryFlowSchemas...)
|
||||||
if apiequality.Semantic.DeepEqual(obj, obj2) {
|
bootstrapFlowSchemas = append(bootstrapFlowSchemas, bootstrap.SuggestedFlowSchemas...)
|
||||||
t.Logf("Defaulting makes no change to %#+v", *obj)
|
for _, original := range bootstrapFlowSchemas {
|
||||||
} else {
|
t.Run(fmt.Sprintf("FlowSchema/%s", original.Name), func(t *testing.T) {
|
||||||
t.Errorf("Defaulting changed %#+v to %#+v", *obj, *obj2)
|
defaulted := original.DeepCopyObject().(*flowcontrol.FlowSchema)
|
||||||
}
|
scheme.Default(defaulted)
|
||||||
|
if apiequality.Semantic.DeepEqual(original, defaulted) {
|
||||||
|
t.Logf("Defaulting makes no change to FlowSchema: %q", original.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Errorf("Expected defaulting to not change FlowSchema: %q, diff: %s", original.Name, cmp.Diff(original, defaulted))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for _, obj := range bootstrap.MandatoryPriorityLevelConfigurations {
|
|
||||||
obj2 := obj.DeepCopyObject().(*flowcontrol.PriorityLevelConfiguration)
|
bootstrapPriorityLevels := make([]*flowcontrol.PriorityLevelConfiguration, 0)
|
||||||
scheme.Default(obj2)
|
bootstrapPriorityLevels = append(bootstrapPriorityLevels, bootstrap.MandatoryPriorityLevelConfigurations...)
|
||||||
if apiequality.Semantic.DeepEqual(obj, obj2) {
|
bootstrapPriorityLevels = append(bootstrapPriorityLevels, bootstrap.SuggestedPriorityLevelConfigurations...)
|
||||||
t.Logf("Defaulting makes no change to %#+v", *obj)
|
for _, original := range bootstrapPriorityLevels {
|
||||||
} else {
|
t.Run(fmt.Sprintf("PriorityLevelConfiguration/%s", original.Name), func(t *testing.T) {
|
||||||
t.Errorf("Defaulting changed %#+v to %#+v", *obj, *obj2)
|
defaulted := original.DeepCopyObject().(*flowcontrol.PriorityLevelConfiguration)
|
||||||
}
|
scheme.Default(defaulted)
|
||||||
|
if apiequality.Semantic.DeepEqual(original, defaulted) {
|
||||||
|
t.Logf("Defaulting makes no change to PriorityLevelConfiguration: %q", original.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Errorf("Expected defaulting to not change PriorityLevelConfiguration: %q, diff: %s", original.Name, cmp.Diff(original, defaulted))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1021,6 +1021,7 @@ func TestPriorityLevelConfigurationValidation(t *testing.T) {
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 5,
|
NominalConcurrencyShares: 5,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeReject,
|
Type: flowcontrol.LimitResponseTypeReject,
|
||||||
}}},
|
}}},
|
||||||
|
@ -30,10 +30,10 @@ import (
|
|||||||
flowcontrollisters "k8s.io/client-go/listers/flowcontrol/v1beta3"
|
flowcontrollisters "k8s.io/client-go/listers/flowcontrol/v1beta3"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
flowcontrolapisv1beta3 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3"
|
flowcontrolapisv1beta3 "k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEnsurePriorityLevel(t *testing.T) {
|
func TestEnsurePriorityLevel(t *testing.T) {
|
||||||
@ -257,6 +257,7 @@ func TestPriorityLevelSpecChanged(t *testing.T) {
|
|||||||
Type: flowcontrolv1beta3.PriorityLevelEnablementLimited,
|
Type: flowcontrolv1beta3.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrolv1beta3.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrolv1beta3.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: flowcontrolapisv1beta3.PriorityLevelConfigurationDefaultNominalConcurrencyShares,
|
NominalConcurrencyShares: flowcontrolapisv1beta3.PriorityLevelConfigurationDefaultNominalConcurrencyShares,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrolv1beta3.LimitResponse{
|
LimitResponse: flowcontrolv1beta3.LimitResponse{
|
||||||
Type: flowcontrolv1beta3.LimitResponseTypeReject,
|
Type: flowcontrolv1beta3.LimitResponseTypeReject,
|
||||||
},
|
},
|
||||||
@ -291,7 +292,10 @@ func TestPriorityLevelSpecChanged(t *testing.T) {
|
|||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
w := priorityLevelSpecChanged(testCase.expected, testCase.actual)
|
w := priorityLevelSpecChanged(testCase.expected, testCase.actual)
|
||||||
assert.Equal(t, testCase.specChanged, w)
|
if testCase.specChanged != w {
|
||||||
|
t.Errorf("Expected priorityLevelSpecChanged to return %t, but got: %t - diff: %s", testCase.specChanged, w,
|
||||||
|
cmp.Diff(testCase.expected, testCase.actual))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,6 +476,7 @@ func (b *plBuilder) WithLimited(nominalConcurrencyShares int32) *plBuilder {
|
|||||||
b.object.Spec.Type = flowcontrolv1beta3.PriorityLevelEnablementLimited
|
b.object.Spec.Type = flowcontrolv1beta3.PriorityLevelEnablementLimited
|
||||||
b.object.Spec.Limited = &flowcontrolv1beta3.LimitedPriorityLevelConfiguration{
|
b.object.Spec.Limited = &flowcontrolv1beta3.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: nominalConcurrencyShares,
|
NominalConcurrencyShares: nominalConcurrencyShares,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrolv1beta3.LimitResponse{
|
LimitResponse: flowcontrolv1beta3.LimitResponse{
|
||||||
Type: flowcontrolv1beta3.LimitResponseTypeReject,
|
Type: flowcontrolv1beta3.LimitResponseTypeReject,
|
||||||
},
|
},
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apiserver/pkg/authentication/serviceaccount"
|
"k8s.io/apiserver/pkg/authentication/serviceaccount"
|
||||||
"k8s.io/apiserver/pkg/authentication/user"
|
"k8s.io/apiserver/pkg/authentication/user"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The objects that define an apiserver's initial behavior. The
|
// The objects that define an apiserver's initial behavior. The
|
||||||
@ -96,6 +97,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 5,
|
NominalConcurrencyShares: 5,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeReject,
|
Type: flowcontrol.LimitResponseTypeReject,
|
||||||
},
|
},
|
||||||
@ -168,6 +170,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 30,
|
NominalConcurrencyShares: 30,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeQueue,
|
Type: flowcontrol.LimitResponseTypeQueue,
|
||||||
Queuing: &flowcontrol.QueuingConfiguration{
|
Queuing: &flowcontrol.QueuingConfiguration{
|
||||||
@ -184,6 +187,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 40,
|
NominalConcurrencyShares: 40,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeQueue,
|
Type: flowcontrol.LimitResponseTypeQueue,
|
||||||
Queuing: &flowcontrol.QueuingConfiguration{
|
Queuing: &flowcontrol.QueuingConfiguration{
|
||||||
@ -201,6 +205,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 10,
|
NominalConcurrencyShares: 10,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeQueue,
|
Type: flowcontrol.LimitResponseTypeQueue,
|
||||||
Queuing: &flowcontrol.QueuingConfiguration{
|
Queuing: &flowcontrol.QueuingConfiguration{
|
||||||
@ -218,6 +223,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 40,
|
NominalConcurrencyShares: 40,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeQueue,
|
Type: flowcontrol.LimitResponseTypeQueue,
|
||||||
Queuing: &flowcontrol.QueuingConfiguration{
|
Queuing: &flowcontrol.QueuingConfiguration{
|
||||||
@ -235,6 +241,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 100,
|
NominalConcurrencyShares: 100,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeQueue,
|
Type: flowcontrol.LimitResponseTypeQueue,
|
||||||
Queuing: &flowcontrol.QueuingConfiguration{
|
Queuing: &flowcontrol.QueuingConfiguration{
|
||||||
@ -252,6 +259,7 @@ var (
|
|||||||
Type: flowcontrol.PriorityLevelEnablementLimited,
|
Type: flowcontrol.PriorityLevelEnablementLimited,
|
||||||
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
Limited: &flowcontrol.LimitedPriorityLevelConfiguration{
|
||||||
NominalConcurrencyShares: 20,
|
NominalConcurrencyShares: 20,
|
||||||
|
LendablePercent: pointer.Int32(0),
|
||||||
LimitResponse: flowcontrol.LimitResponse{
|
LimitResponse: flowcontrol.LimitResponse{
|
||||||
Type: flowcontrol.LimitResponseTypeQueue,
|
Type: flowcontrol.LimitResponseTypeQueue,
|
||||||
Queuing: &flowcontrol.QueuingConfiguration{
|
Queuing: &flowcontrol.QueuingConfiguration{
|
||||||
|
Loading…
Reference in New Issue
Block a user