Skip to content

Commit 0980c4a

Browse files
committed
Integrate GRPCRoute into NIMService
Signed-off-by: Sheng Lin <[email protected]>
1 parent 00b70ed commit 0980c4a

37 files changed

+244
-5
lines changed

api/apps/v1alpha1/common_types.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ type Gateway struct {
8585
// +kubebuilder:default:=true
8686
// HTTPRoutesEnabled is a flag to enable HTTPRoutes for the created gateway.
8787
HTTPRoutesEnabled bool `json:"httpRoutesEnabled,omitempty"`
88+
89+
// +kubebuilder:default:=false
90+
// GRPCRoutesEnabled is a flag to enable GRPCRoutes for the created gateway.
91+
GRPCRoutesEnabled bool `json:"grpcRoutesEnabled,omitempty"`
8892
}
8993

9094
// DEPRECATED ExposeV1 defines attributes to expose the service.
@@ -270,6 +274,38 @@ func (r *Router) GenerateGatewayHTTPRouteSpec(namespace, name string, port int32
270274
}
271275
}
272276

277+
func (r *Router) GenerateGatewayGRPCRouteSpec(namespace, name string, port int32) gatewayv1.GRPCRouteSpec {
278+
if r.Gateway == nil || !r.Gateway.GRPCRoutesEnabled {
279+
return gatewayv1.GRPCRouteSpec{}
280+
}
281+
282+
return gatewayv1.GRPCRouteSpec{
283+
CommonRouteSpec: gatewayv1.CommonRouteSpec{
284+
ParentRefs: []gatewayv1.ParentReference{
285+
{
286+
Name: gatewayv1.ObjectName(r.Gateway.Name),
287+
Namespace: ptr.To(gatewayv1.Namespace(r.Gateway.Namespace)),
288+
},
289+
},
290+
},
291+
Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(r.getHostname(namespace, name))},
292+
Rules: []gatewayv1.GRPCRouteRule{
293+
{
294+
BackendRefs: []gatewayv1.GRPCBackendRef{
295+
{
296+
BackendRef: gatewayv1.BackendRef{
297+
BackendObjectReference: gatewayv1.BackendObjectReference{
298+
Name: gatewayv1.ObjectName(name),
299+
Port: ptr.To(gatewayv1.PortNumber(port)),
300+
},
301+
},
302+
},
303+
},
304+
},
305+
},
306+
}
307+
}
308+
273309
func (r *Router) getHostname(namespace, name string) string {
274310
return fmt.Sprintf("%s.%s.%s", name, namespace, r.HostDomainName)
275311
}

api/apps/v1alpha1/nimservice_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,14 @@ func (n *NIMService) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
963963
return n.Spec.Router.GenerateGatewayHTTPRouteSpec(n.GetNamespace(), n.GetName(), n.GetServicePort())
964964
}
965965

966+
func (n *NIMService) IsGRPCRouteEnabled() bool {
967+
return n.Spec.Router.Gateway != nil && n.Spec.Router.Gateway.GRPCRoutesEnabled
968+
}
969+
970+
func (n *NIMService) GetGRPCRouteSpec() gatewayv1.GRPCRouteSpec {
971+
return n.Spec.Router.GenerateGatewayGRPCRouteSpec(n.GetNamespace(), n.GetName(), n.GetServicePort())
972+
}
973+
966974
// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NIMService deployment.
967975
func (n *NIMService) IsServiceMonitorEnabled() bool {
968976
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
@@ -1350,6 +1358,16 @@ func (n *NIMService) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
13501358
return params
13511359
}
13521360

1361+
func (n *NIMService) GetGRPCRouteParams() *rendertypes.GRPCRouteParams {
1362+
params := &rendertypes.GRPCRouteParams{}
1363+
params.Enabled = n.IsGRPCRouteEnabled()
1364+
params.Name = n.GetName()
1365+
params.Namespace = n.GetNamespace()
1366+
params.Labels = n.GetServiceLabels()
1367+
params.Spec = n.GetGRPCRouteSpec()
1368+
return params
1369+
}
1370+
13531371
// GetRoleParams returns params to render Role from templates.
13541372
func (n *NIMService) GetRoleParams() *rendertypes.RoleParams {
13551373
params := &rendertypes.RoleParams{}

bundle/manifests/apps.nvidia.com_nemocustomizers.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,11 @@ spec:
12131213
gateway:
12141214
description: Gateway is the gateway to use for the created HTTPRoute.
12151215
properties:
1216+
grpcRoutesEnabled:
1217+
default: false
1218+
description: GRPCRoutesEnabled is a flag to enable GRPCRoutes
1219+
for the created gateway.
1220+
type: boolean
12161221
httpRoutesEnabled:
12171222
default: true
12181223
description: HTTPRoutesEnabled is a flag to enable HTTPRoutes

bundle/manifests/apps.nvidia.com_nemodatastores.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,11 @@ spec:
892892
gateway:
893893
description: Gateway is the gateway to use for the created HTTPRoute.
894894
properties:
895+
grpcRoutesEnabled:
896+
default: false
897+
description: GRPCRoutesEnabled is a flag to enable GRPCRoutes
898+
for the created gateway.
899+
type: boolean
895900
httpRoutesEnabled:
896901
default: true
897902
description: HTTPRoutesEnabled is a flag to enable HTTPRoutes

bundle/manifests/apps.nvidia.com_nemoentitystores.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,11 @@ spec:
822822
gateway:
823823
description: Gateway is the gateway to use for the created HTTPRoute.
824824
properties:
825+
grpcRoutesEnabled:
826+
default: false
827+
description: GRPCRoutesEnabled is a flag to enable GRPCRoutes
828+
for the created gateway.
829+
type: boolean
825830
httpRoutesEnabled:
826831
default: true
827832
description: HTTPRoutesEnabled is a flag to enable HTTPRoutes

bundle/manifests/apps.nvidia.com_nemoevaluators.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,11 @@ spec:
958958
gateway:
959959
description: Gateway is the gateway to use for the created HTTPRoute.
960960
properties:
961+
grpcRoutesEnabled:
962+
default: false
963+
description: GRPCRoutesEnabled is a flag to enable GRPCRoutes
964+
for the created gateway.
965+
type: boolean
961966
httpRoutesEnabled:
962967
default: true
963968
description: HTTPRoutesEnabled is a flag to enable HTTPRoutes

bundle/manifests/apps.nvidia.com_nemoguardrails.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ spec:
885885
gateway:
886886
description: Gateway is the gateway to use for the created HTTPRoute.
887887
properties:
888+
grpcRoutesEnabled:
889+
default: false
890+
description: GRPCRoutesEnabled is a flag to enable GRPCRoutes
891+
for the created gateway.
892+
type: boolean
888893
httpRoutesEnabled:
889894
default: true
890895
description: HTTPRoutesEnabled is a flag to enable HTTPRoutes

bundle/manifests/apps.nvidia.com_nimpipelines.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,11 @@ spec:
16781678
description: Gateway is the gateway to use for the created
16791679
HTTPRoute.
16801680
properties:
1681+
grpcRoutesEnabled:
1682+
default: false
1683+
description: GRPCRoutesEnabled is a flag to enable
1684+
GRPCRoutes for the created gateway.
1685+
type: boolean
16811686
httpRoutesEnabled:
16821687
default: true
16831688
description: HTTPRoutesEnabled is a flag to enable

bundle/manifests/apps.nvidia.com_nimservices.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,11 @@ spec:
16011601
gateway:
16021602
description: Gateway is the gateway to use for the created HTTPRoute.
16031603
properties:
1604+
grpcRoutesEnabled:
1605+
default: false
1606+
description: GRPCRoutesEnabled is a flag to enable GRPCRoutes
1607+
for the created gateway.
1608+
type: boolean
16041609
httpRoutesEnabled:
16051610
default: true
16061611
description: HTTPRoutesEnabled is a flag to enable HTTPRoutes

bundle/manifests/k8s-nim-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,7 @@ spec:
13491349
- gateway.networking.k8s.io
13501350
resources:
13511351
- httproutes
1352+
- grpcroutes
13521353
verbs:
13531354
- create
13541355
- delete

0 commit comments

Comments
 (0)