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

api: adds cel validation on requiring at least one targetRefs #114

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions api/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type AIGatewayRouteList struct {
type AIGatewayRouteSpec struct {
// TargetRefs are the names of the Gateway resources this AIGatewayRoute is being attached to.
//
// +optional
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=128
TargetRefs []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs,omitempty"`
TargetRefs []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"`
// APISchema specifies the API schema of the input that the target Gateway(s) will receive.
// Based on this schema, the ai-gateway will perform the necessary transformation to the
// output schema specified in the selected AIServiceBackend during the routing process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ spec:
- name
type: object
maxItems: 128
minItems: 1
type: array
required:
- inputSchema
- rules
- targetRefs
type: object
type: object
served: true
Expand Down
4 changes: 4 additions & 0 deletions tests/cel-validation/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestAIGatewayRoutes(t *testing.T) {
name: "unsupported_match.yaml",
expErr: "spec.rules[0].matches[0].headers: Invalid value: \"array\": currently only exact match is supported",
},
{
name: "no_target_refs.yaml",
expErr: `spec.targetRefs: Invalid value: 0: spec.targetRefs in body should have at least 1 items`,
},
} {
t.Run(tc.name, func(t *testing.T) {
data, err := testdata.ReadFile(path.Join("testdata/aigatewayroutes", tc.name))
Expand Down
4 changes: 4 additions & 0 deletions tests/cel-validation/testdata/aigatewayroutes/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ metadata:
name: apple
namespace: default
spec:
targetRefs:
- name: some-gateway
kind: Gateway
group: gateway.networking.k8s.io
inputSchema:
schema: OpenAI
rules:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: aigateway.envoyproxy.io/v1alpha1
kind: AIGatewayRoute
metadata:
name: apple
namespace: default
spec:
targetRefs: []
inputSchema:
schema: OpenAI
rules:
- matches:
- headers:
- type: Exact
name: x-envoy-ai-gateway-model
value: llama3-70b
backendRefs:
- name: kserve
weight: 20
- name: aws-bedrock
weight: 80
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ metadata:
name: apple
namespace: default
spec:
targetRefs:
- name: some-gateway
kind: Gateway
group: gateway.networking.k8s.io
inputSchema:
# Input must be OpenAI schema at the moment, so this is invalid.
schema: AWSBedrock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ metadata:
name: apple
namespace: default
spec:
targetRefs:
- name: some-gateway
kind: Gateway
group: gateway.networking.k8s.io
inputSchema:
# Schema must be OpenAI schema at the moment, so this is invalid.
schema: SomeRandomVendor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ metadata:
name: apple
namespace: default
spec:
targetRefs:
- name: some-gateway
kind: Gateway
group: gateway.networking.k8s.io
inputSchema:
schema: OpenAI
rules:
Expand Down
Loading