Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional API Testing for GEP-3171 #3300

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
e6beaef
Create index.md
jakebennert Jun 29, 2024
2506395
Create metadata.yaml
jakebennert Jun 29, 2024
377eb60
Update index.md
jakebennert Jun 30, 2024
6ad6511
Update metadata.yaml
jakebennert Jun 30, 2024
dd1f61b
Remove 'omitempty' from Fraction fields
jakebennert Jun 30, 2024
bf6644a
Merge branch 'kubernetes-sigs:main' into main
jakebennert Jul 22, 2024
494d1ac
Split MirrorPercent into two fields: MirrorPercent and MirrorFraction.
jakebennert Jul 22, 2024
d998621
Update index.md
jakebennert Jul 22, 2024
58b8d45
Add config examples.
jakebennert Jul 22, 2024
4768da7
Add Existing Support Table
jakebennert Jul 22, 2024
9c8f672
Update field names to avoid 'stuttering' in names.
jakebennert Jul 22, 2024
dbbe4de
Update geps/gep-3171/index.md
jakebennert Jul 29, 2024
b08b09a
Merge branch 'kubernetes-sigs:main' into main
jakebennert Aug 20, 2024
6f0b6f9
Add Fraction type
jakebennert Aug 20, 2024
219602f
Add percent and fraction to HTTPRequestMirrorFilter
jakebennert Aug 20, 2024
205726a
Update apis/v1/httproute_types.go
jakebennert Aug 21, 2024
dc6c3e4
Update apis/v1/shared_types.go
jakebennert Aug 21, 2024
1b8f84d
Add CEL validation to Fraction type
jakebennert Aug 21, 2024
b7d943c
Add CEL validation to HttpRequestMirrorFilter
jakebennert Aug 21, 2024
a38970f
Add CEL validation test for HTTPRequestMirrorFilter
jakebennert Aug 21, 2024
fece6d3
Ran /hack/update-codegen.sh
jakebennert Aug 21, 2024
a121d72
Update httproute_experimental_test.go
jakebennert Aug 22, 2024
8ac9286
Update httproute_experimental_test.go
jakebennert Aug 22, 2024
ce85d11
Update httproute_experimental_test.go
jakebennert Aug 22, 2024
1ae9c38
Update httproute_types.go
jakebennert Aug 22, 2024
2647fee
Reran /hack/update-codegen.sh
jakebennert Aug 22, 2024
4af86bc
Update httproute_experimental_test.go
jakebennert Aug 22, 2024
639dd42
Make Denominator field a pointer to distinguish between 0 and unset
jakebennert Aug 22, 2024
d1142d7
Change Percent to be a pointer to distinguish between 0 and unset
jakebennert Aug 23, 2024
2fc563b
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
b7b9e5d
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
5ef895e
Format httproute_types.go
jakebennert Aug 23, 2024
55bdd99
Make Fraction a pointer
jakebennert Aug 23, 2024
a7ec37b
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
785c868
Reran hack/update-codegen.sh
jakebennert Aug 23, 2024
9b9141a
Updating to test CEL validation
jakebennert Aug 23, 2024
0d950da
Updating to test CEL validation
jakebennert Aug 23, 2024
92c3a20
Update httproute_types.go
jakebennert Aug 23, 2024
316965a
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
ef85ee0
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
f9d6687
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
f64e4b7
Update httproute_types.go
jakebennert Aug 23, 2024
e92b89d
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
7beabbb
Update httproute_types.go
jakebennert Aug 23, 2024
c66e899
Update httproute_types.go
jakebennert Aug 23, 2024
faaac18
testing
jakebennert Aug 23, 2024
8758c99
Update httproute_types.go
jakebennert Aug 23, 2024
502f23b
Ran hack/update-codegen.sh
jakebennert Aug 23, 2024
6812812
format shared_types.go
jakebennert Aug 23, 2024
885055d
Update httproute_types.go
jakebennert Aug 23, 2024
3118321
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
03ad867
Update httproute_types.go
jakebennert Aug 23, 2024
cb721ba
Update httproute_types.go
jakebennert Aug 23, 2024
45190cf
reran hack/update-codegen.sh
jakebennert Aug 23, 2024
48fa58a
Update httproute_types.go
jakebennert Aug 23, 2024
0e10e93
Update httproute_experimental_test.go
jakebennert Aug 23, 2024
61ec05c
Reran hack/update-codegen.sh
jakebennert Aug 23, 2024
bd2f90e
Added RequestMirror validation to GRPCRoute
jakebennert Aug 26, 2024
11cec9b
Create grcproute_experimental_test.go
jakebennert Aug 26, 2024
9fe610b
Update grcproute_experimental_test.go
jakebennert Aug 26, 2024
a50077c
Update grpcroute_types.go
jakebennert Aug 26, 2024
ed12d84
Update grcproute_experimental_test.go
jakebennert Aug 26, 2024
4bc5e27
Ran hack/update-codegen.sh
jakebennert Aug 26, 2024
f12e175
Update grcproute_experimental_test.go
jakebennert Aug 26, 2024
ee4f5f5
Update grcproute_experimental_test.go
jakebennert Aug 26, 2024
ba8993d
Update Copyright Year
jakebennert Aug 26, 2024
ad9ecbb
Update pkg/test/cel/grcproute_experimental_test.go
jakebennert Aug 26, 2024
bb5a858
Update httproute_experimental_test.go
jakebennert Aug 26, 2024
ddeab1a
Update grcproute_experimental_test.go
jakebennert Aug 26, 2024
9483c44
Merge branch 'kubernetes-sigs:main' into main
jakebennert Aug 27, 2024
380f18d
Rename grcproute_experimental_test.go to grpcroute_experimental_test.go
jakebennert Aug 27, 2024
4dfa1a9
Add more tests for HTTPRequestMirrorFilter
jakebennert Aug 27, 2024
aac5f0a
Update grpcroute_experimental_test.go
jakebennert Aug 27, 2024
8bb3c8c
Add more tests for GRPCRequestMirrorFilter
jakebennert Aug 27, 2024
9b232e1
Update grpcroute_experimental_test.go
jakebennert Aug 27, 2024
55f0c68
Update httproute_experimental_test.go
jakebennert Aug 27, 2024
522590a
Update grpcroute_experimental_test.go
jakebennert Aug 27, 2024
c6a0e33
Update httproute_experimental_test.go
jakebennert Aug 27, 2024
149e213
Make HTTPRequestMirrorFilter's fraction a pointer
jakebennert Aug 27, 2024
1e295ff
Update httproute_experimental_test.go
jakebennert Aug 27, 2024
d1bf172
Update grpcroute_experimental_test.go
jakebennert Aug 27, 2024
4361500
Ran hack/update-codegen.sh
jakebennert Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apis/applyconfiguration/internal/internal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/v1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ type HTTPRequestMirrorFilter struct {
//
// +optional
// <gateway:experimental>
Fraction Fraction `json:"fraction,omitempty"`
Fraction *Fraction `json:"fraction,omitempty"`
}

// HTTPBackendRef defines how a HTTPRoute forwards a HTTP request.
Expand Down
6 changes: 5 additions & 1 deletion apis/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 0 additions & 90 deletions pkg/test/cel/grcproute_experimental_test.go

This file was deleted.

181 changes: 181 additions & 0 deletions pkg/test/cel/grpcroute_experimental_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
//go:build experimental
// +build experimental

/*
Copyright 2024 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 main

import (
"fmt"
"testing"
"time"

gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// How are tests named? Where to add new tests?
//
// Ensure that tests for newly added CEL validations are added in the correctly
// named test function. For example, if you added a test at the
// `GRPCRouteFilter` hierarchy (i.e. either at the struct level, or on one of
// the immediate descendent fields), then the test will go in the
// TestGRPCRouteFilter function. If the appropriate test function does not
// exist, please create one.
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
var percent int32 = 42
var denominator int32 = 1000
var bad_denominator int32 = 0
testService := gatewayv1.ObjectName("test-service")
tests := []struct {
name string
wantErrors []string
rules []gatewayv1.GRPCRouteRule
}{
{
name: "GRPCRoute - Invalid because both percent and fraction are specified",
wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Type: gatewayv1.GRPCRouteFilterRequestMirror,
RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Percent: &percent,
Fraction: &gatewayv1.Fraction{
Numerator: 83,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Invalid fraction - numerator greater than denominator",
wantErrors: []string{"numerator must be less than or equal to denominator"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Type: gatewayv1.GRPCRouteFilterRequestMirror,
RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 1001,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Invalid fraction - denominator is 0",
wantErrors: []string{"spec.rules[0].filters[0].requestMirror.fraction.denominator in body should be greater than or equal to 1"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Type: gatewayv1.GRPCRouteFilterRequestMirror,
RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 0,
Denominator: &bad_denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Invalid fraction - numerator is negative",
wantErrors: []string{"spec.rules[0].filters[0].requestMirror.fraction.numerator in body should be greater than or equal to 0"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Type: gatewayv1.GRPCRouteFilterRequestMirror,
RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: -1,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Valid with percent",
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Type: gatewayv1.GRPCRouteFilterRequestMirror,
RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Percent: &percent,
},
}},
}},
},
{
name: "GRPCRoute - Valid with fraction",
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Type: gatewayv1.GRPCRouteFilterRequestMirror,
RequestMirror: &gatewayv1.HTTPRequestMirrorFilter{
BackendRef: gatewayv1.BackendObjectReference{
Name: testService,
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 83,
Denominator: &denominator,
},
},
}},
}},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
route := &gatewayv1.GRPCRoute{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("foo-%v", time.Now().UnixNano()),
Namespace: metav1.NamespaceDefault,
},
Spec: gatewayv1.GRPCRouteSpec{Rules: tc.rules},
}
validateGRPCRoute(t, route, tc.wantErrors)
})
}
}
Loading