@@ -23,6 +23,7 @@ import (
2323 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424 "k8s.io/apimachinery/pkg/types"
2525 "sigs.k8s.io/controller-runtime/pkg/client"
26+ gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
2627)
2728
2829// gateway related utils: currently only support envoy ai gateway
@@ -54,24 +55,23 @@ func IsAIGatewayRouteExist(ctx context.Context, client client.Client) (bool, err
5455// name: qwen2-0--5b-lb # model name
5556// kind: Service
5657// port: 8080
57- func CreateAIServiceBackend (ctx context.Context , client client.Client , backendRefName , namespace string , port int , schemaName string ) error {
58- if schemaName == "" {
59- schemaName = "OpenAI"
60- }
58+ func CreateAIServiceBackend (ctx context.Context , client client.Client , backendRefName , namespace string , port int ) error {
59+ kind := gwapiv1 .Kind ("Service" )
60+ portName := gwapiv1 .PortNumber (port )
6161 // create the AIServiceBackend
6262 backend := & aigv1a1.AIServiceBackend {
6363 ObjectMeta : metav1.ObjectMeta {
6464 Name : backendRefName ,
6565 Namespace : namespace ,
6666 },
6767 Spec : aigv1a1.AIServiceBackendSpec {
68- Schema : aigv1a1.AIServiceBackendSchema {
69- Name : schemaName ,
68+ APISchema : aigv1a1.VersionedAPISchema {
69+ Name : aigv1a1 . APISchemaOpenAI ,
7070 },
71- BackendRef : aigv1a1. AIServiceBackendRef {
72- Name : backendRefName ,
73- Kind : "Service" ,
74- Port : port ,
71+ BackendRef : gwapiv1. BackendObjectReference {
72+ Name : gwapiv1 . ObjectName ( backendRefName ) ,
73+ Kind : & kind ,
74+ Port : & portName ,
7575 },
7676 },
7777 }
@@ -108,20 +108,21 @@ func UpdateAIGatewayRoute(ctx context.Context, client client.Client, backendRefN
108108 return nil
109109 }
110110 }
111+ exact := gwapiv1 .HeaderMatchExact
111112 // if the rule does not exist, append it to the spec.rules list
112113 rule := aigv1a1.AIGatewayRouteRule {
113- Matches : []aigv1a1.AIGatewayRouteMatch {
114+ Matches : []aigv1a1.AIGatewayRouteRuleMatch {
114115 {
115- Headers : []aigv1a1. AIGatewayRouteHeaderMatch {
116+ Headers : []gwapiv1. HTTPHeaderMatch {
116117 {
117- Type : aigv1a1 . HeaderMatchTypeExact ,
118+ Type : & exact ,
118119 Name : "x-ai-eg-model" ,
119120 Value : modelName ,
120121 },
121122 },
122123 },
123124 },
124- BackendRefs : []aigv1a1.AIGatewayRouteBackendRef {
125+ BackendRefs : []aigv1a1.AIGatewayRouteRuleBackendRef {
125126 {
126127 Name : backendRefName ,
127128 },
0 commit comments