Skip to content

Commit edfe2d2

Browse files
committed
add: crd validation
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
1 parent dd0cb7a commit edfe2d2

7 files changed

Lines changed: 99 additions & 0 deletions

File tree

api/v1alpha1/bandwidthlimit_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type BandwidthLimitResponseTrailers struct {
6969
// "bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
7070
// "bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
7171
//
72+
// +kubebuilder:validation:Pattern=`^[^\r\n\x00]*$`
7273
// +optional
7374
Prefix *string `json:"prefix,omitempty"`
7475
}

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ spec:
135135
including response body transfer time and the time added by the filter.
136136
"bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
137137
"bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
138+
pattern: ^[^\r\n\x00]*$
138139
type: string
139140
type: object
140141
required:

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ spec:
134134
including response body transfer time and the time added by the filter.
135135
"bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
136136
"bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
137+
pattern: ^[^\r\n\x00]*$
137138
type: string
138139
type: object
139140
required:

test/cel-validation/backendtrafficpolicy_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,6 +3264,99 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
32643264
},
32653265
wantErrors: []string{},
32663266
},
3267+
{
3268+
desc: "invalid bandwidthLimit prefix with carriage return",
3269+
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
3270+
btp.Spec = egv1a1.BackendTrafficPolicySpec{
3271+
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
3272+
TargetRef: &gwapiv1.LocalPolicyTargetReferenceWithSectionName{
3273+
LocalPolicyTargetReference: gwapiv1.LocalPolicyTargetReference{
3274+
Group: "gateway.networking.k8s.io",
3275+
Kind: "Gateway",
3276+
Name: "eg",
3277+
},
3278+
},
3279+
},
3280+
BandwidthLimit: &egv1a1.BandwidthLimitSpec{
3281+
Response: &egv1a1.BandwidthLimitResponseConfig{
3282+
Limit: egv1a1.BandwidthLimitValue{
3283+
Value: resource.MustParse("10M"),
3284+
Unit: egv1a1.BandwidthLimitUnitSecond,
3285+
},
3286+
ResponseTrailers: &egv1a1.BandwidthLimitResponseTrailers{
3287+
Prefix: new("x-eg\r"),
3288+
},
3289+
},
3290+
},
3291+
}
3292+
},
3293+
wantErrors: []string{
3294+
"spec.bandwidthLimit.response.responseTrailers.prefix",
3295+
"in body should match",
3296+
},
3297+
},
3298+
{
3299+
desc: "invalid bandwidthLimit prefix with newline",
3300+
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
3301+
btp.Spec = egv1a1.BackendTrafficPolicySpec{
3302+
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
3303+
TargetRef: &gwapiv1.LocalPolicyTargetReferenceWithSectionName{
3304+
LocalPolicyTargetReference: gwapiv1.LocalPolicyTargetReference{
3305+
Group: "gateway.networking.k8s.io",
3306+
Kind: "Gateway",
3307+
Name: "eg",
3308+
},
3309+
},
3310+
},
3311+
BandwidthLimit: &egv1a1.BandwidthLimitSpec{
3312+
Response: &egv1a1.BandwidthLimitResponseConfig{
3313+
Limit: egv1a1.BandwidthLimitValue{
3314+
Value: resource.MustParse("10M"),
3315+
Unit: egv1a1.BandwidthLimitUnitSecond,
3316+
},
3317+
ResponseTrailers: &egv1a1.BandwidthLimitResponseTrailers{
3318+
Prefix: new("x-eg\n"),
3319+
},
3320+
},
3321+
},
3322+
}
3323+
},
3324+
wantErrors: []string{
3325+
"spec.bandwidthLimit.response.responseTrailers.prefix",
3326+
"in body should match",
3327+
},
3328+
},
3329+
{
3330+
desc: "invalid bandwidthLimit prefix with null byte",
3331+
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
3332+
btp.Spec = egv1a1.BackendTrafficPolicySpec{
3333+
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
3334+
TargetRef: &gwapiv1.LocalPolicyTargetReferenceWithSectionName{
3335+
LocalPolicyTargetReference: gwapiv1.LocalPolicyTargetReference{
3336+
Group: "gateway.networking.k8s.io",
3337+
Kind: "Gateway",
3338+
Name: "eg",
3339+
},
3340+
},
3341+
},
3342+
BandwidthLimit: &egv1a1.BandwidthLimitSpec{
3343+
Response: &egv1a1.BandwidthLimitResponseConfig{
3344+
Limit: egv1a1.BandwidthLimitValue{
3345+
Value: resource.MustParse("10M"),
3346+
Unit: egv1a1.BandwidthLimitUnitSecond,
3347+
},
3348+
ResponseTrailers: &egv1a1.BandwidthLimitResponseTrailers{
3349+
Prefix: new("x-eg\x00"),
3350+
},
3351+
},
3352+
},
3353+
}
3354+
},
3355+
wantErrors: []string{
3356+
"spec.bandwidthLimit.response.responseTrailers.prefix",
3357+
"in body should match",
3358+
},
3359+
},
32673360
{
32683361
desc: "invalid bandwidthLimit with neither request nor response",
32693362
mutate: func(btp *egv1a1.BackendTrafficPolicy) {

test/helm/gateway-crds-helm/all.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22662,6 +22662,7 @@ spec:
2266222662
including response body transfer time and the time added by the filter.
2266322663
"bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
2266422664
"bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
22665+
pattern: ^[^\r\n\x00]*$
2266522666
type: string
2266622667
type: object
2266722668
required:

test/helm/gateway-crds-helm/e2e.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ spec:
635635
including response body transfer time and the time added by the filter.
636636
"bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
637637
"bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
638+
pattern: ^[^\r\n\x00]*$
638639
type: string
639640
type: object
640641
required:

test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ spec:
635635
including response body transfer time and the time added by the filter.
636636
"bandwidth-request-filter-delay-ms" is delay time in milliseconds in request stream transfer added by the filter.
637637
"bandwidth-response-filter-delay-ms" is delay time in milliseconds that added by the filter.
638+
pattern: ^[^\r\n\x00]*$
638639
type: string
639640
type: object
640641
required:

0 commit comments

Comments
 (0)