Skip to content

Commit 5107775

Browse files
authored
feat(gateway-api): support GRPCRoute (#2570)
1 parent 992bead commit 5107775

File tree

23 files changed

+1787
-143
lines changed

23 files changed

+1787
-143
lines changed

Makefile

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

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

api/adc/types.go

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

345345
type Scheme string
346346

347-
const (
348-
SchemeHTTP = "http"
349-
)
350-
351347
type UpstreamType string
352348

353349
const (
@@ -519,11 +515,13 @@ func ComposeServiceNameWithRule(namespace, name string, rule string) string {
519515
return buf.String()
520516
}
521517

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

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

537536
return buf.String()
538537
}
539538

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

config/rbac/role.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ rules:
7979
- gateway.networking.k8s.io
8080
resources:
8181
- gatewayclasses
82-
- gateways
8382
verbs:
8483
- get
8584
- list
@@ -90,6 +89,7 @@ rules:
9089
resources:
9190
- gatewayclasses/status
9291
- gateways/status
92+
- grpcroutes/status
9393
- httproutes/status
9494
- referencegrants/status
9595
verbs:
@@ -98,35 +98,22 @@ rules:
9898
- apiGroups:
9999
- gateway.networking.k8s.io
100100
resources:
101+
- gateways
102+
- grpcroutes
101103
- httproutes
102-
verbs:
103-
- get
104-
- list
105-
- watch
106-
- apiGroups:
107-
- gateway.networking.k8s.io
108-
resources:
109104
- referencegrants
110105
verbs:
111-
- list
112-
- update
113-
- watch
114-
- apiGroups:
115-
- networking.k8s.io
116-
resources:
117-
- ingressclasses
118-
verbs:
119106
- get
120107
- list
121108
- watch
122109
- apiGroups:
123110
- networking.k8s.io
124111
resources:
112+
- ingressclasses
125113
- ingresses
126114
verbs:
127115
- get
128116
- list
129-
- update
130117
- watch
131118
- apiGroups:
132119
- 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
k8s.io/api v0.32.3
3132
k8s.io/apiextensions-apiserver v0.32.3
@@ -195,7 +196,6 @@ require (
195196
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
196197
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
197198
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
198-
google.golang.org/grpc v1.71.1 // indirect
199199
google.golang.org/protobuf v1.36.6 // indirect
200200
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
201201
gopkg.in/fsnotify.v1 v1.4.7 // indirect

0 commit comments

Comments
 (0)