Skip to content

Commit 5bf9ab9

Browse files
authored
(backport)feat(gateway-api): support GRPCRoute (#2570) (#274)
1 parent d88a0d2 commit 5bf9ab9

File tree

28 files changed

+1858
-152
lines changed

28 files changed

+1858
-152
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ GATEAY_API_VERSION ?= v1.3.0
6262
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080"
6363
CONFORMANCE_TEST_REPORT_OUTPUT ?= $(DIR)/apisix-ingress-controller-conformance-report.yaml
6464
## https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/conformance/utils/suite/profiles.go
65-
CONFORMANCE_PROFILES ?= GATEWAY-HTTP
65+
CONFORMANCE_PROFILES ?= GATEWAY-HTTP,GATEWAY-GRPC
6666

6767
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6868
ifeq (,$(shell go env GOBIN))

api/adc/types.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,6 @@ const (
343343

344344
type Scheme string
345345

346-
const (
347-
SchemeHTTP = "http"
348-
)
349-
350346
type UpstreamType string
351347

352348
const (
@@ -518,11 +514,13 @@ func ComposeServiceNameWithRule(namespace, name string, rule string) string {
518514
return buf.String()
519515
}
520516

521-
func ComposeServiceNameWithStream(namespace, name string, rule string) string {
522-
// FIXME Use sync.Pool to reuse this buffer if the upstream
523-
// name composing code path is hot.
517+
func ComposeGRPCServiceNameWithRule(namespace, name string, rule string) string {
518+
return ComposeServicesNameWithScheme(namespace, name, rule, "grpc")
519+
}
520+
521+
func ComposeServicesNameWithScheme(namespace, name string, rule string, scheme string) string {
524522
var p []byte
525-
plen := len(namespace) + len(name) + 6
523+
plen := len(namespace) + len(name) + len(rule) + len(scheme) + 3
526524

527525
p = make([]byte, 0, plen)
528526
buf := bytes.NewBuffer(p)
@@ -531,11 +529,16 @@ func ComposeServiceNameWithStream(namespace, name string, rule string) string {
531529
buf.WriteString(name)
532530
buf.WriteByte('_')
533531
buf.WriteString(rule)
534-
buf.WriteString("_stream")
532+
buf.WriteByte('_')
533+
buf.WriteString(scheme)
535534

536535
return buf.String()
537536
}
538537

538+
func ComposeServiceNameWithStream(namespace, name string, rule string) string {
539+
return ComposeServicesNameWithScheme(namespace, name, rule, "stream")
540+
}
541+
539542
func ComposeConsumerName(namespace, name string) string {
540543
// FIXME Use sync.Pool to reuse this buffer if the upstream
541544
// name composing code path is hot.
@@ -568,9 +571,8 @@ func NewDefaultUpstream() *Upstream {
568571
"managed-by": "apisix-ingress-controller",
569572
},
570573
},
571-
Nodes: make(UpstreamNodes, 0),
572-
Scheme: SchemeHTTP,
573-
Type: Roundrobin,
574+
Nodes: make(UpstreamNodes, 0),
575+
Type: Roundrobin,
574576
}
575577
}
576578

config/rbac/role.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ rules:
8080
- gateway.networking.k8s.io
8181
resources:
8282
- gatewayclasses
83-
- gateways
8483
verbs:
8584
- get
8685
- list
@@ -91,6 +90,7 @@ rules:
9190
resources:
9291
- gatewayclasses/status
9392
- gateways/status
93+
- grpcroutes/status
9494
- httproutes/status
9595
- referencegrants/status
9696
verbs:
@@ -99,35 +99,22 @@ rules:
9999
- apiGroups:
100100
- gateway.networking.k8s.io
101101
resources:
102+
- gateways
103+
- grpcroutes
102104
- httproutes
103-
verbs:
104-
- get
105-
- list
106-
- watch
107-
- apiGroups:
108-
- gateway.networking.k8s.io
109-
resources:
110105
- referencegrants
111106
verbs:
112-
- list
113-
- update
114-
- watch
115-
- apiGroups:
116-
- networking.k8s.io
117-
resources:
118-
- ingressclasses
119-
verbs:
120107
- get
121108
- list
122109
- watch
123110
- apiGroups:
124111
- networking.k8s.io
125112
resources:
113+
- ingressclasses
126114
- ingresses
127115
verbs:
128116
- get
129117
- list
130-
- update
131118
- watch
132119
- apiGroups:
133120
- networking.k8s.io

docs/en/latest/concepts/gateway-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ By supporting Gateway API, the APISIX Ingress controller can realize richer func
4848
| GatewayClass | Supported | N/A | Not supported | v1 |
4949
| Gateway | Partially supported | Partially supported | Not supported | v1 |
5050
| HTTPRoute | Supported | Partially supported | Not supported | v1 |
51-
| GRPCRoute | Not supported | Not supported | Not supported | v1 |
51+
| GRPCRoute | Supported | Supported | Not supported | v1 |
5252
| ReferenceGrant | Supported | Not supported | Not supported | v1beta1 |
5353
| TLSRoute | Not supported | Not supported | Not supported | v1alpha2 |
5454
| TCPRoute | Not supported | Not supported | Not supported | v1alpha2 |

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
github.com/stretchr/testify v1.10.0
2727
go.uber.org/zap v1.27.0
2828
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
29+
google.golang.org/grpc v1.71.1
2930
gopkg.in/yaml.v3 v3.0.1
3031
helm.sh/helm/v3 v3.15.4
3132
k8s.io/api v0.32.3
@@ -237,7 +238,6 @@ require (
237238
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
238239
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
239240
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
240-
google.golang.org/grpc v1.71.1 // indirect
241241
google.golang.org/protobuf v1.36.6 // indirect
242242
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
243243
gopkg.in/fsnotify.v1 v1.4.7 // indirect

internal/adc/translator/apisixroute.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ func (t *Translator) buildUpstream(tctx *provider.TranslateContext, service *adc
240240
upstreamName := adc.ComposeUpstreamName(ar.Namespace, ar.Name, fmt.Sprintf("%d", ruleIndex), fmt.Sprintf("%d", backendIndex))
241241
upstream.Name = upstreamName
242242
upstream.ID = id.GenID(upstreamName)
243+
upstream.Scheme = cmp.Or(upstream.Scheme, apiv2.SchemeHTTP)
243244
upstreams = append(upstreams, upstream)
244245
}
245246

@@ -265,6 +266,7 @@ func (t *Translator) buildUpstream(tctx *provider.TranslateContext, service *adc
265266
upstreamName := adc.ComposeExternalUpstreamName(upsNN.Namespace, upsNN.Name)
266267
upstream.Name = upstreamName
267268
upstream.ID = id.GenID(upstreamName)
269+
upstream.Scheme = cmp.Or(upstream.Scheme, apiv2.SchemeHTTP)
268270
upstreams = append(upstreams, upstream)
269271
}
270272

0 commit comments

Comments
 (0)