From d6b5415c5f13032df364eec02d49b92ab95ee60a Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 4 Jul 2024 17:29:38 +0800 Subject: [PATCH] xds: should use TCP as default protocol (#3749) --- internal/gatewayapi/listener.go | 2 +- internal/gatewayapi/route.go | 12 ++++++++---- .../envoyproxy-accesslog-als-json.in.yaml | 2 ++ .../testdata/envoyproxy-accesslog.in.yaml | 2 ++ internal/gatewayapi/translator_test.go | 18 +++++++++++++++--- .../testdata/in/xds-ir/tracing-zipkin.yaml | 2 +- .../out/xds-ir/tracing-zipkin.clusters.yaml | 5 ----- test/e2e/base/manifests.yaml | 1 + 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/internal/gatewayapi/listener.go b/internal/gatewayapi/listener.go index 25afaacee7d..1bef8ca52a1 100644 --- a/internal/gatewayapi/listener.go +++ b/internal/gatewayapi/listener.go @@ -466,7 +466,7 @@ func (t *Translator) processBackendRefs(backendRefs []egv1a1.BackendRef, namespa return nil, err } - ds := t.processServiceDestinationSetting(ref.BackendObjectReference, ns, ir.GRPC, resources, envoyProxy) + ds := t.processServiceDestinationSetting(ref.BackendObjectReference, ns, ir.TCP, resources, envoyProxy) result = append(result, ds) } if len(result) == 0 { diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index 98e998c7f95..c6719015d1c 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -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 + case "grpc": + protocol = ir.GRPC + } } // Route to endpoints by default diff --git a/internal/gatewayapi/testdata/envoyproxy-accesslog-als-json.in.yaml b/internal/gatewayapi/testdata/envoyproxy-accesslog-als-json.in.yaml index 28850133563..4b5caa73f17 100644 --- a/internal/gatewayapi/testdata/envoyproxy-accesslog-als-json.in.yaml +++ b/internal/gatewayapi/testdata/envoyproxy-accesslog-als-json.in.yaml @@ -110,6 +110,7 @@ services: ports: - name: grpc port: 9000 + appProtocol: grpc protocol: TCP targetPort: 9000 endpointSlices: @@ -123,6 +124,7 @@ endpointSlices: addressType: IPv4 ports: - name: grpc + appProtocol: grpc protocol: TCP port: 9090 endpoints: diff --git a/internal/gatewayapi/testdata/envoyproxy-accesslog.in.yaml b/internal/gatewayapi/testdata/envoyproxy-accesslog.in.yaml index ea6b29424ca..0d634113f4f 100644 --- a/internal/gatewayapi/testdata/envoyproxy-accesslog.in.yaml +++ b/internal/gatewayapi/testdata/envoyproxy-accesslog.in.yaml @@ -118,6 +118,7 @@ services: ports: - name: grpc port: 9000 + appProtocol: grpc protocol: TCP targetPort: 9000 endpointSlices: @@ -132,6 +133,7 @@ endpointSlices: ports: - name: grpc protocol: TCP + appProtocol: grpc port: 9090 endpoints: - addresses: diff --git a/internal/gatewayapi/translator_test.go b/internal/gatewayapi/translator_test.go index 062808af580..357f6586bee 100644 --- a/internal/gatewayapi/translator_test.go +++ b/internal/gatewayapi/translator_test.go @@ -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, }, }, @@ -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{ { diff --git a/internal/xds/translator/testdata/in/xds-ir/tracing-zipkin.yaml b/internal/xds/translator/testdata/in/xds-ir/tracing-zipkin.yaml index a60183dd268..9b4e57fd74f 100644 --- a/internal/xds/translator/testdata/in/xds-ir/tracing-zipkin.yaml +++ b/internal/xds/translator/testdata/in/xds-ir/tracing-zipkin.yaml @@ -24,7 +24,7 @@ tracing: - endpoints: - host: "zipkin.default.svc.cluster.local" port: 9411 - protocol: "GRPC" + protocol: "TCP" provider: host: zipkin.default.svc.cluster.local port: 9411 diff --git a/internal/xds/translator/testdata/out/xds-ir/tracing-zipkin.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/tracing-zipkin.clusters.yaml index b8a1ac3df39..a9d0472bfac 100644 --- a/internal/xds/translator/testdata/out/xds-ir/tracing-zipkin.clusters.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/tracing-zipkin.clusters.yaml @@ -42,8 +42,3 @@ perConnectionBufferLimitBytes: 32768 respectDnsTtl: true type: STRICT_DNS - typedExtensionProtocolOptions: - envoy.extensions.upstreams.http.v3.HttpProtocolOptions: - '@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions - explicitHttpConfig: - http2ProtocolOptions: {} diff --git a/test/e2e/base/manifests.yaml b/test/e2e/base/manifests.yaml index ded6c648a0c..d3c78980afc 100644 --- a/test/e2e/base/manifests.yaml +++ b/test/e2e/base/manifests.yaml @@ -1092,6 +1092,7 @@ spec: ports: - name: grpc-als protocol: TCP + appProtocol: grpc port: 8080 targetPort: 8080 - name: http-monitoring