Skip to content

Commit

Permalink
support grpc
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain committed Jul 4, 2024
1 parent 9d57fa8 commit 7603592
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
12 changes: 8 additions & 4 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,10 +1307,14 @@ func (t *Translator) processServiceDestinationSetting(
}
}

// support HTTPRouteBackendProtocolH2C
if servicePort.AppProtocol != nil &&
*servicePort.AppProtocol == "kubernetes.io/h2c" {
protocol = ir.HTTP2
// support HTTPRouteBackendProtocolH2C/GRPC
if servicePort.AppProtocol != nil {
switch *servicePort.AppProtocol {
case "kubernetes.io/h2c":
protocol = ir.HTTP2

Check warning on line 1314 in internal/gatewayapi/route.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/route.go#L1313-L1314

Added lines #L1313 - L1314 were not covered by tests
case "grpc":
protocol = ir.GRPC
}
}

// Route to endpoints by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ services:
ports:
- name: grpc
port: 9000
appProtocol: grpc
protocol: TCP
targetPort: 9000
endpointSlices:
Expand All @@ -123,6 +124,7 @@ endpointSlices:
addressType: IPv4
ports:
- name: grpc
appProtocol: grpc
protocol: TCP
port: 9090
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ xdsIR:
endpoints:
- host: 10.240.0.10
port: 9090
protocol: TCP
protocol: GRPC
http:
requestHeaders:
- x-client-ip-address
Expand All @@ -178,7 +178,7 @@ xdsIR:
endpoints:
- host: 10.240.0.10
port: 9090
protocol: TCP
protocol: GRPC
name: envoy-gateway-system/test
type: TCP
http:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ xdsIR:
endpoints:
- host: 8.7.6.5
port: 4317
protocol: TCP
protocol: GRPC
resources:
k8s.cluster.name: cluster-1
text: |
Expand Down
2 changes: 2 additions & 0 deletions internal/gatewayapi/testdata/envoyproxy-accesslog.in.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ services:
ports:
- name: grpc
port: 9000
appProtocol: grpc
protocol: TCP
targetPort: 9000
endpointSlices:
Expand All @@ -132,6 +133,7 @@ endpointSlices:
ports:
- name: grpc
protocol: TCP
appProtocol: grpc
port: 9090
endpoints:
- addresses:
Expand Down
4 changes: 2 additions & 2 deletions internal/gatewayapi/testdata/envoyproxy-accesslog.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ xdsIR:
endpoints:
- host: 10.240.0.10
port: 9090
protocol: TCP
protocol: GRPC
http:
requestHeaders:
- x-client-ip-address
Expand All @@ -182,7 +182,7 @@ xdsIR:
endpoints:
- host: 10.240.0.10
port: 9090
protocol: TCP
protocol: GRPC
name: envoy-gateway-system/test
text: |
[%START_TIME%] "%REQ(:METHOD)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%"\n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ xdsIR:
endpoints:
- host: 8.7.6.5
port: 4317
protocol: TCP
protocol: GRPC
provider:
backendRefs:
- name: otel-collector
Expand Down
18 changes: 15 additions & 3 deletions internal/gatewayapi/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,16 @@ func TestTranslate(t *testing.T) {
ClusterIP: "3.3.3.3",
Ports: []corev1.ServicePort{
{
Name: "grpc",
Port: 4317,
TargetPort: intstr.IntOrString{IntVal: 4317},
Name: "grpc",
Port: 4317,
TargetPort: intstr.IntOrString{IntVal: 4317},
Protocol: corev1.ProtocolTCP,
AppProtocol: ptr.To("grpc"),
},
{
Name: "zipkin",
Port: 9411,
TargetPort: intstr.IntOrString{IntVal: 9411},
Protocol: corev1.ProtocolTCP,
},
},
Expand All @@ -264,6 +271,11 @@ func TestTranslate(t *testing.T) {
Port: ptr.To[int32](4317),
Protocol: ptr.To(corev1.ProtocolTCP),
},
{
Name: ptr.To("zipkin"),
Port: ptr.To[int32](9411),
Protocol: ptr.To(corev1.ProtocolTCP),
},
},
Endpoints: []discoveryv1.Endpoint{
{
Expand Down

0 comments on commit 7603592

Please sign in to comment.