Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
  • Loading branch information
mathetake committed Dec 9, 2024
1 parent a416c97 commit b545f4a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 168 deletions.
15 changes: 1 addition & 14 deletions api/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -48,12 +46,6 @@ type LLMRouteSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule="self.schema == 'OpenAI'"
APISchema LLMAPISchema `json:"inputSchema"`
// TargetRefs are the names of the Gateway resources this policy is being attached to.
// The namespace is "local", i.e. the same namespace as the LLMRoute.
//
// +optional
// +kubebuilder:validation:MaxItems=128
TargetRefs []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"`
// HTTPRouteRef is the name of the HTTPRoute resource that the Gateway will use to route the traffic.
// The namespace is "local", i.e. the same namespace as the LLMRoute.
//
Expand All @@ -63,7 +55,7 @@ type LLMRouteSpec struct {
// Currently, only the exact header matching is supported, otherwise the configuration will be rejected.
//
// +kubebuilder:validation:Required
HTTPRouteRef HTTPRouteRef `json:"httpRoutRef,omitempty"`
HTTPRouteRef HTTPRouteRef `json:"httpRouteRef,omitempty"`
}

// HTTPRouteRef is a reference to a HTTPRoute resource in the "local" namespace.
Expand Down Expand Up @@ -101,11 +93,6 @@ type LLMBackendSpec struct {
//
// This is required to be set.
APISchema LLMAPISchema `json:"outputSchema"`
// BackendRef is the reference to the Backend resource that this LLMBackend corresponds to.
//
// The backend can be of either k8s Service or [egv1a1.Backend] kind plus the resource must be in the same namespace as the LLMRoute.
// For the sake of simplicity, currently the same backend cannot be referenced by multiple LLMBackend(s).
BackendRef gwapiv1.BackendObjectReference `json:"backendRef"`
}

// LLMAPISchema defines the API schema of either LLMRoute (the input) or LLMBackend (the output).
Expand Down
13 changes: 2 additions & 11 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -41,80 +41,6 @@ spec:
spec:
description: Spec defines the details of the LLM policy.
properties:
backendRef:
description: |-
BackendRef is the reference to the Backend resource that this LLMBackend corresponds to.
The backend can be of either k8s Service or [egv1a1.Backend] kind plus the resource must be in the same namespace as the LLMRoute.
For the sake of simplicity, currently the same backend cannot be referenced by multiple LLMBackend(s).
properties:
group:
default: ""
description: |-
Group is the group of the referent. For example, "gateway.networking.k8s.io".
When unspecified or empty string, core API group is inferred.
maxLength: 253
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
kind:
default: Service
description: |-
Kind is the Kubernetes resource kind of the referent. For example
"Service".
Defaults to "Service" when not specified.
ExternalName services can refer to CNAME DNS records that may live
outside of the cluster and as such are difficult to reason about in
terms of conformance. They also may not be safe to forward to (see
CVE-2021-25740 for more information). Implementations SHOULD NOT
support ExternalName Services.
Support: Core (Services with a type other than ExternalName)
Support: Implementation-specific (Services with type ExternalName)
maxLength: 63
minLength: 1
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
type: string
name:
description: Name is the name of the referent.
maxLength: 253
minLength: 1
type: string
namespace:
description: |-
Namespace is the namespace of the backend. When unspecified, the local
namespace is inferred.
Note that when a namespace different than the local namespace is specified,
a ReferenceGrant object is required in the referent namespace to allow that
namespace's owner to accept the reference. See the ReferenceGrant
documentation for details.
Support: Core
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
port:
description: |-
Port specifies the destination port number to use for this resource.
Port is required when the referent is a Kubernetes Service. In this
case, the port number is the service port number, not the target port.
For other resources, destination port might be derived from the referent
resource or this field.
format: int32
maximum: 65535
minimum: 1
type: integer
required:
- name
type: object
x-kubernetes-validations:
- message: Must have port for Service reference
rule: '(size(self.group) == 0 && self.kind == ''Service'') ? has(self.port)
: true'
outputSchema:
description: |-
APISchema specifies the API schema of the output format of requests from
Expand All @@ -137,7 +63,6 @@ spec:
- schema
type: object
required:
- backendRef
- outputSchema
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spec:
spec:
description: Spec defines the details of the LLM policy.
properties:
httpRoutRef:
httpRouteRef:
description: |-
HTTPRouteRef is the name of the HTTPRoute resource that the Gateway will use to route the traffic.
The namespace is "local", i.e. the same namespace as the LLMRoute.
Expand Down Expand Up @@ -91,63 +91,8 @@ spec:
type: object
x-kubernetes-validations:
- rule: self.schema == 'OpenAI'
targetRefs:
description: |-
TargetRefs are the names of the Gateway resources this policy is being attached to.
The namespace is "local", i.e. the same namespace as the LLMRoute.
items:
description: |-
LocalPolicyTargetReferenceWithSectionName identifies an API object to apply a
direct policy to. This should be used as part of Policy resources that can
target single resources. For more information on how this policy attachment
mode works, and a sample Policy resource, refer to the policy attachment
documentation for Gateway API.
Note: This should only be used for direct policy attachment when references
to SectionName are actually needed. In all other cases,
LocalPolicyTargetReference should be used.
properties:
group:
description: Group is the group of the target resource.
maxLength: 253
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
kind:
description: Kind is kind of the target resource.
maxLength: 63
minLength: 1
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
type: string
name:
description: Name is the name of the target resource.
maxLength: 253
minLength: 1
type: string
sectionName:
description: |-
SectionName is the name of a section within the target resource. When
unspecified, this targetRef targets the entire resource. In the following
resources, SectionName is interpreted as the following:
* Gateway: Listener name
* HTTPRoute: HTTPRouteRule name
* Service: Port name
If a SectionName is specified, but does not exist on the targeted object,
the Policy must fail to attach, and the policy implementation should record
a `ResolvedRefs` or similar Condition in the Policy's status.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
required:
- group
- kind
- name
type: object
maxItems: 128
type: array
required:
- httpRouteRef
- inputSchema
type: object
type: object
Expand Down
9 changes: 2 additions & 7 deletions tests/cel-validation/testdata/llmroutes/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@ metadata:
spec:
inputSchema:
schema: OpenAI
targetRefs:
- name: my-gateway
kind: Gateway
group: gateway.networking.k8s.io
backendRefs:
- name: dog-route
- name: cat-route
httpRouteRef:
name: dog-route
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
inputSchema:
# Input must be OpenAI schema at the moment, so this is invalid.
schema: AWSBedrock
targetRefs:
backendRefs:
httpRouteRef:
name: dog-route
4 changes: 2 additions & 2 deletions tests/cel-validation/testdata/llmroutes/unknown_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
inputSchema:
# Schema must be OpenAI schema at the moment, so this is invalid.
schema: SomeRandomVendor
targetRefs:
backendRefs:
httpRouteRef:
name: dog-route

0 comments on commit b545f4a

Please sign in to comment.