Skip to content

Commit 57558bf

Browse files
Update route creation for vLLM gateway
1 parent 1562528 commit 57558bf

7 files changed

+69
-26
lines changed

controllers/gorch/guardrailsorchestrator_controller.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,24 @@ func (r *GuardrailsOrchestratorReconciler) Reconcile(ctx context.Context, req ct
201201
}
202202

203203
existingRoute := &routev1.Route{}
204-
err = r.Get(ctx, types.NamespacedName{Name: orchestrator.Name + "-route", Namespace: orchestrator.Namespace}, existingRoute)
204+
err = r.Get(ctx, types.NamespacedName{Name: orchestrator.Name + "-health", Namespace: orchestrator.Namespace}, existingRoute)
205205
if err != nil && errors.IsNotFound(err) {
206-
// Define a new route
207-
route := r.createRoute(ctx, orchestrator)
206+
// Define a new route for the health endpoint
207+
route := r.createRoute(ctx, orchestrator.Name+"-health", "health", orchestrator)
208+
log.Info("Creating a new Route", "Route.Namespace", route.Namespace, "Route.Name", route.Name)
209+
err = r.Create(ctx, route)
210+
if err != nil {
211+
log.Error(err, "Failed to create new Route", "Route.Namespace", route.Namespace, "Route.Name", route.Name)
212+
}
213+
} else if err != nil {
214+
log.Error(err, "Failed to get Route")
215+
return ctrl.Result{}, err
216+
}
217+
218+
err = r.Get(ctx, types.NamespacedName{Name: orchestrator.Name + "-http", Namespace: orchestrator.Namespace}, existingRoute)
219+
if err != nil && errors.IsNotFound(err) {
220+
// Define a new route for the http endpoint
221+
route := r.createRoute(ctx, orchestrator.Name+"-http", "http", orchestrator)
208222
log.Info("Creating a new Route", "Route.Namespace", route.Namespace, "Route.Name", route.Name)
209223
err = r.Create(ctx, route)
210224
if err != nil {
@@ -286,8 +300,8 @@ func (r *GuardrailsOrchestratorReconciler) deleteService(ctx context.Context, or
286300
return nil
287301
}
288302

289-
func (r *GuardrailsOrchestratorReconciler) deleteRoute(ctx context.Context, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) (err error) {
290-
obj := client.ObjectKey{Name: orchestrator.Name + "-route", Namespace: orchestrator.Namespace}
303+
func (r *GuardrailsOrchestratorReconciler) deleteRoute(ctx context.Context, routeName string, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) (err error) {
304+
obj := client.ObjectKey{Name: routeName, Namespace: orchestrator.Namespace}
291305
orig := &routev1.Route{}
292306
log := log.FromContext(ctx).WithValues("GuardrailsOrchestratorReconciler.deleteRoute", obj)
293307
err = r.Get(ctx, obj, orig)
@@ -317,7 +331,10 @@ func (r *GuardrailsOrchestratorReconciler) doFinalizerOperationsForOrchestrator(
317331
if err = r.deleteService(ctx, orchestrator); err != nil {
318332
return err
319333
}
320-
if err = r.deleteRoute(ctx, orchestrator); err != nil {
334+
if err = r.deleteRoute(ctx, orchestrator.Name+"-health", orchestrator); err != nil {
335+
return err
336+
}
337+
if err = r.deleteRoute(ctx, orchestrator.Name+"-http", orchestrator); err != nil {
321338
return err
322339
}
323340
return

controllers/gorch/guardrailsorchestrator_controller_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,20 @@ func testCreateDeleteGuardrailsOrchestrator(namespaceName string) {
201201
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-service", Namespace: namespaceName}, service); err != nil {
202202
return err
203203
}
204-
Expect(service.Namespace).Should(Equal(namespaceName))
205-
204+
port := getServicePort(service, "http")
205+
Expect(*port).Should(Equal(int32(8033)))
206206
route := &routev1.Route{}
207207
if err := routev1.AddToScheme(scheme.Scheme); err != nil {
208208
return err
209209
}
210-
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-route", Namespace: namespaceName}, route); err != nil {
210+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-health", Namespace: namespaceName}, route); err != nil {
211+
return err
212+
}
213+
Expect(route.Spec.Port.TargetPort.String()).Should(Equal("health"))
214+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-http", Namespace: namespaceName}, route); err != nil {
211215
return err
212216
}
217+
Expect(route.Spec.Port.TargetPort.String()).Should(Equal("http"))
213218
return nil
214219
}, time.Second*10, time.Millisecond*10).Should(Succeed())
215220

@@ -339,14 +344,21 @@ func testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName string) {
339344
return err
340345
}
341346
Expect(service.Namespace).Should(Equal(namespaceName))
347+
port := getServicePort(service, "http")
348+
Expect(*port).Should(Equal(int32(8032)))
342349

343350
route := &routev1.Route{}
344351
if err := routev1.AddToScheme(scheme.Scheme); err != nil {
345352
return err
346353
}
347-
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-route", Namespace: namespaceName}, route); err != nil {
354+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-health", Namespace: namespaceName}, route); err != nil {
348355
return err
349356
}
357+
Expect(route.Spec.Port.TargetPort.String()).Should(Equal("health"))
358+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-http", Namespace: namespaceName}, route); err != nil {
359+
return err
360+
}
361+
Expect(route.Spec.Port.TargetPort.String()).Should(Equal("http"))
350362
return nil
351363
}, time.Second*10, time.Millisecond*10).Should(Succeed())
352364

@@ -469,7 +481,10 @@ func testCreateDeleteGuardrailsOrchestratorOtelExporter(namespaceName string) {
469481
if err := routev1.AddToScheme(scheme.Scheme); err != nil {
470482
return err
471483
}
472-
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-route", Namespace: namespaceName}, route); err != nil {
484+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-health", Namespace: namespaceName}, route); err != nil {
485+
return err
486+
}
487+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-http", Namespace: namespaceName}, route); err != nil {
473488
return err
474489
}
475490
return nil

controllers/gorch/route.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ const routeTemplatePath = "route.tmpl.yaml"
2121

2222
type RouteConfig struct {
2323
Orchestrator *gorchv1alpha1.GuardrailsOrchestrator
24+
RouteName string
2425
PortName string
2526
}
2627

27-
func (r *GuardrailsOrchestratorReconciler) createRoute(ctx context.Context, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) *routev1.Route {
28-
routeHttpConfig := RouteConfig{
28+
func (r *GuardrailsOrchestratorReconciler) createRoute(ctx context.Context, routeName string, portName string, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) *routev1.Route {
29+
routeConfig := RouteConfig{
2930
Orchestrator: orchestrator,
30-
PortName: "http",
31+
RouteName: routeName,
32+
PortName: portName,
3133
}
3234
var route *routev1.Route
33-
route, err := templateParser.ParseResource[routev1.Route](routeTemplatePath, routeHttpConfig, reflect.TypeOf(&routev1.Route{}))
35+
route, err := templateParser.ParseResource[routev1.Route](routeTemplatePath, routeConfig, reflect.TypeOf(&routev1.Route{}))
3436

3537
if err != nil {
3638
log.FromContext(ctx).Error(err, "Failed to parse route template")
@@ -39,7 +41,7 @@ func (r *GuardrailsOrchestratorReconciler) createRoute(ctx context.Context, orch
3941
return route
4042
}
4143

42-
func (r *GuardrailsOrchestratorReconciler) checkRouteReady(ctx context.Context, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) (bool, error) {
44+
func (r *GuardrailsOrchestratorReconciler) checkRouteReady(ctx context.Context, routeName string, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) (bool, error) {
4345
// Retry logic for getting the route and checking its readiness
4446
var existingRoute *routev1.Route
4547
err := retry.OnError(
@@ -52,7 +54,7 @@ func (r *GuardrailsOrchestratorReconciler) checkRouteReady(ctx context.Context,
5254
},
5355
func() error {
5456
// Fetch the Route resource
55-
typedNamespaceName := types.NamespacedName{Name: orchestrator.Name + "-route", Namespace: orchestrator.Namespace}
57+
typedNamespaceName := types.NamespacedName{Name: routeName, Namespace: orchestrator.Namespace}
5658
existingRoute = &routev1.Route{}
5759
err := r.Get(ctx, typedNamespaceName, existingRoute)
5860
if err != nil {
@@ -67,7 +69,7 @@ func (r *GuardrailsOrchestratorReconciler) checkRouteReady(ctx context.Context,
6769
}
6870
}
6971
// Route is not admitted yet, return an error to retry
70-
return fmt.Errorf("route %s is not admitted", orchestrator.Name)
72+
return fmt.Errorf("route %s is not admitted", routeName)
7173
},
7274
)
7375
if err != nil {

controllers/gorch/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ func (r *GuardrailsOrchestratorReconciler) updateStatus(ctx context.Context, ori
128128
func (r *GuardrailsOrchestratorReconciler) reconcileStatuses(ctx context.Context, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) (ctrl.Result, error) {
129129
generatorReady, _ = r.checkGeneratorPresent(ctx, orchestrator.Namespace)
130130
deploymentReady, _ = r.checkDeploymentReady(ctx, orchestrator)
131-
routeReady, _ = r.checkRouteReady(ctx, orchestrator)
131+
routeReadyHealth, _ := r.checkRouteReady(ctx, orchestrator.Name+"-health", orchestrator)
132+
routeReadyName, _ := r.checkRouteReady(ctx, orchestrator.Name+"-http", orchestrator)
133+
routeReady = routeReadyHealth && routeReadyName
132134

133135
if generatorReady && deploymentReady && routeReady {
134136
_, updateErr := r.updateStatus(ctx, orchestrator, func(saved *gorchv1alpha1.GuardrailsOrchestrator) {

controllers/gorch/suite_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ func getEnvVar(envVarName string, envVars []corev1.EnvVar) *corev1.EnvVar {
6666
return nil
6767
}
6868

69+
func getServicePort(service *corev1.Service, portName string) *int32 {
70+
for _, port := range service.Spec.Ports {
71+
if port.Name == portName {
72+
return &port.Port
73+
}
74+
}
75+
return nil
76+
}
6977
func TestControllers(t *testing.T) {
7078
RegisterFailHandler(Fail)
7179

controllers/gorch/templates/route.tmpl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
kind: Route
22
apiVersion: route.openshift.io/v1
33
metadata:
4-
name: {{.Orchestrator.Name}}-route
4+
name: {{.RouteName}}
55
namespace: {{.Orchestrator.Namespace}}
66
labels:
77
app: {{.Orchestrator.Name}}

controllers/gorch/templates/service.tmpl.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ metadata:
66
labels:
77
app: {{.Orchestrator.Name}}
88
component: {{.Orchestrator.Name}}
9-
app.kubernetes.io/instance: {{.Orchestrator.Name}}
10-
app.kubernetes.io/name: {{.Orchestrator.Name}}
11-
app.kubernetes.io/part-of: trustyai
129
spec:
1310
ipFamilies:
1411
- IPv4
1512
ports:
1613
- name: http
1714
protocol: TCP
15+
{{if .Orchestrator.Spec.VLLMGatewayConfig}}
16+
port: 8032
17+
targetPort: 8032
18+
{{else}}
1819
port: 8033
1920
targetPort: 8033
21+
{{end}}
2022
- name: health
2123
protocol: TCP
2224
port: 8034
@@ -28,6 +30,3 @@ spec:
2830
selector:
2931
app: {{.Orchestrator.Name}}
3032
component: {{.Orchestrator.Name}}
31-
app.kubernetes.io/instance: {{.Orchestrator.Name}}
32-
app.kubernetes.io/name: {{.Orchestrator.Name}}
33-
app.kubernetes.io/part-of: trustyai

0 commit comments

Comments
 (0)