Skip to content

Commit 141909f

Browse files
committed
tighten ceiling for matching-precedence to 10000
1 parent c33bbbc commit 141909f

File tree

7 files changed

+57
-9
lines changed

7 files changed

+57
-9
lines changed

api/openapi-spec/swagger.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/flowcontrol/types.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const (
4343
PriorityLevelConfigurationConditionConcurrencyShared = "ConcurrencyShared"
4444
)
4545

46+
// Constants used by api validation.
47+
const (
48+
FlowSchemaMaxMatchingPrecedence int32 = 10000
49+
)
50+
4651
// +genclient
4752
// +genclient:nonNamespaced
4853
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -88,8 +93,8 @@ type FlowSchemaSpec struct {
8893
PriorityLevelConfiguration PriorityLevelConfigurationReference
8994
// `matchingPrecedence` is used to choose among the FlowSchemas that match a given request. The chosen
9095
// FlowSchema is among those with the numerically lowest (which we take to be logically highest)
91-
// MatchingPrecedence. Each MatchingPrecedence value must be non-negative.
92-
// Note that if the precedence is not specified or zero, it will be set to 1000 as default.
96+
// MatchingPrecedence. Each MatchingPrecedence value must be ranged in [1,10000].
97+
// Note that if the precedence is not specified, it will be set to 1000 as default.
9398
// +optional
9499
MatchingPrecedence int32
95100
// `distinguisherMethod` defines how to compute the flow distinguisher for requests that match this schema.

pkg/apis/flowcontrol/validation/validation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ func ValidateFlowSchemaUpdate(old, fs *flowcontrol.FlowSchema) field.ErrorList {
8787
func ValidateFlowSchemaSpec(spec *flowcontrol.FlowSchemaSpec, fldPath *field.Path) field.ErrorList {
8888
var allErrs field.ErrorList
8989
if spec.MatchingPrecedence <= 0 {
90-
allErrs = append(allErrs, field.Invalid(fldPath.Child("matchingPrecedence"), spec.MatchingPrecedence, "must be positive value"))
90+
allErrs = append(allErrs, field.Invalid(fldPath.Child("matchingPrecedence"), spec.MatchingPrecedence, "must be a positive value"))
91+
}
92+
if spec.MatchingPrecedence > flowcontrol.FlowSchemaMaxMatchingPrecedence {
93+
allErrs = append(allErrs, field.Invalid(fldPath.Child("matchingPrecedence"), spec.MatchingPrecedence, fmt.Sprintf("must not be greater than %v", flowcontrol.FlowSchemaMaxMatchingPrecedence)))
9194
}
9295
if spec.DistinguisherMethod != nil {
9396
if !supportedDistinguisherMethods.Has(string(spec.DistinguisherMethod.Type)) {

pkg/apis/flowcontrol/validation/validation_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,41 @@ func TestFlowSchemaValidation(t *testing.T) {
547547
field.Invalid(field.NewPath("spec").Child("rules").Index(0).Child("resourceRules").Index(0).Child("namespaces").Index(0), "-foo", nsErrIntro+`a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')`),
548548
},
549549
},
550+
{
551+
name: "MatchingPrecedence must not be greater than 10000",
552+
flowSchema: &flowcontrol.FlowSchema{
553+
ObjectMeta: metav1.ObjectMeta{
554+
Name: "system-foo",
555+
},
556+
Spec: flowcontrol.FlowSchemaSpec{
557+
MatchingPrecedence: 50000,
558+
PriorityLevelConfiguration: flowcontrol.PriorityLevelConfigurationReference{
559+
Name: "system-bar",
560+
},
561+
Rules: []flowcontrol.PolicyRulesWithSubjects{
562+
{
563+
Subjects: []flowcontrol.Subject{
564+
{
565+
Kind: flowcontrol.SubjectKindUser,
566+
User: &flowcontrol.UserSubject{Name: "noxu"},
567+
},
568+
},
569+
ResourceRules: []flowcontrol.ResourcePolicyRule{
570+
{
571+
Verbs: []string{flowcontrol.VerbAll},
572+
APIGroups: []string{flowcontrol.APIGroupAll},
573+
Resources: []string{flowcontrol.ResourceAll},
574+
Namespaces: []string{flowcontrol.NamespaceEvery},
575+
},
576+
},
577+
},
578+
},
579+
},
580+
},
581+
expectedErrors: field.ErrorList{
582+
field.Invalid(field.NewPath("spec").Child("matchingPrecedence"), int32(50000), "must not be greater than 10000"),
583+
},
584+
},
550585
}
551586
for _, testCase := range testCases {
552587
t.Run(testCase.name, func(t *testing.T) {

staging/src/k8s.io/api/flowcontrol/v1alpha1/generated.proto

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/api/flowcontrol/v1alpha1/types.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const (
4343
PriorityLevelConfigurationConditionConcurrencyShared = "ConcurrencyShared"
4444
)
4545

46+
// Constants used by api validation.
47+
const (
48+
FlowSchemaMaxMatchingPrecedence int32 = 10000
49+
)
50+
4651
// +genclient
4752
// +genclient:nonNamespaced
4853
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -88,8 +93,8 @@ type FlowSchemaSpec struct {
8893
PriorityLevelConfiguration PriorityLevelConfigurationReference `json:"priorityLevelConfiguration" protobuf:"bytes,1,opt,name=priorityLevelConfiguration"`
8994
// `matchingPrecedence` is used to choose among the FlowSchemas that match a given request. The chosen
9095
// FlowSchema is among those with the numerically lowest (which we take to be logically highest)
91-
// MatchingPrecedence. Each MatchingPrecedence value must be non-negative.
92-
// Note that if the precedence is not specified or zero, it will be set to 1000 as default.
96+
// MatchingPrecedence. Each MatchingPrecedence value must be ranged in [1,10000].
97+
// Note that if the precedence is not specified, it will be set to 1000 as default.
9398
// +optional
9499
MatchingPrecedence int32 `json:"matchingPrecedence" protobuf:"varint,2,opt,name=matchingPrecedence"`
95100
// `distinguisherMethod` defines how to compute the flow distinguisher for requests that match this schema.

staging/src/k8s.io/api/flowcontrol/v1alpha1/types_swagger_doc_generated.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)