@@ -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+
273309func (r * Router ) getHostname (namespace , name string ) string {
274310 return fmt .Sprintf ("%s.%s.%s" , name , namespace , r .HostDomainName )
275311}
0 commit comments