From fe8316803a9cbfd91f609497870735a474d2cc00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E8=B4=A4=E6=B6=9B?= <601803023@qq.com> Date: Sat, 29 Jun 2024 16:57:18 +0800 Subject: [PATCH 1/2] add grpcJsonTranscoder plugin --- .../plugins/grpc_json_transcoder.in.yml | 21 +++++++ .../plugins/grpc_json_transcoder.out.yml | 51 +++++++++++++++ .../plugins/grpc_json_transcoder/config.go | 48 ++++++++++++++ controller/plugins/plugins.go | 1 + e2e/base/grpc.yml | 63 +++++++++++++++++++ e2e/tests/grpc_json_transcoder.go | 18 ++++++ e2e/tests/grpc_json_transcoder.yml | 20 ++++++ types/plugins/grpc_json_transcoder/config.go | 33 ++++++++++ 8 files changed, 255 insertions(+) create mode 100644 controller/internal/translation/testdata/plugins/grpc_json_transcoder.in.yml create mode 100644 controller/internal/translation/testdata/plugins/grpc_json_transcoder.out.yml create mode 100644 controller/plugins/grpc_json_transcoder/config.go create mode 100644 e2e/base/grpc.yml create mode 100644 e2e/tests/grpc_json_transcoder.go create mode 100644 e2e/tests/grpc_json_transcoder.yml create mode 100644 types/plugins/grpc_json_transcoder/config.go diff --git a/controller/internal/translation/testdata/plugins/grpc_json_transcoder.in.yml b/controller/internal/translation/testdata/plugins/grpc_json_transcoder.in.yml new file mode 100644 index 00000000..ee03f003 --- /dev/null +++ b/controller/internal/translation/testdata/plugins/grpc_json_transcoder.in.yml @@ -0,0 +1,21 @@ +apiVersion: htnn.mosn.io/v1 +kind: HTTPFilterPolicy +metadata: + name: policy + namespace: default +spec: + targetRef: + group: networking.istio.io + kind: VirtualService + name: default + filters: + grpcJsonTranscoder: + config: + protoDescriptor: protos/helloworld.pb + services: + - helloworld.Greeter + printOptions: + addWhitespace: true + alwaysPrintPrimitiveFields: true + alwaysPrintEnumsAsInts: false + preserveProtoFieldNames: false \ No newline at end of file diff --git a/controller/internal/translation/testdata/plugins/grpc_json_transcoder.out.yml b/controller/internal/translation/testdata/plugins/grpc_json_transcoder.out.yml new file mode 100644 index 00000000..c4251351 --- /dev/null +++ b/controller/internal/translation/testdata/plugins/grpc_json_transcoder.out.yml @@ -0,0 +1,51 @@ +- metadata: + creationTimestamp: null + name: htnn-h-default.local + namespace: default + spec: + configPatches: + - applyTo: HTTP_ROUTE + match: + routeConfiguration: + vhost: + name: default.local:80 + route: + name: default/default + patch: + operation: MERGE + value: + typed_per_filter_config: + htnn.filters.http.grpcJsonTranscoder: + '@type': type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder + printOptions: + addWhitespace: true + alwaysPrintEnumsAsInts: false + alwaysPrintPrimitiveFields: true + preserveProtoFieldNames: false + protoDescriptor: protos/helloworld.pb + services: + - helloworld.Greeter + status: {} +- metadata: + creationTimestamp: null + name: htnn-http-filter + namespace: istio-system + spec: + configPatches: + - applyTo: HTTP_FILTER + match: + listener: + filterChain: + filter: + name: envoy.filters.network.http_connection_manager + subFilter: + name: envoy.filters.http.router + patch: + operation: INSERT_BEFORE + value: + disabled: true + name: htnn.filters.http.grpcJsonTranscoder + typed_config: + '@type': type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder + priority: -10 + status: {} diff --git a/controller/plugins/grpc_json_transcoder/config.go b/controller/plugins/grpc_json_transcoder/config.go new file mode 100644 index 00000000..274a3b60 --- /dev/null +++ b/controller/plugins/grpc_json_transcoder/config.go @@ -0,0 +1,48 @@ +// Copyright The HTNN Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package grpc_json_transcoder + +import ( + "mosn.io/htnn/api/pkg/plugins" + "mosn.io/htnn/types/plugins/grpc_json_transcoder" +) + +const ( + Name = "grpcJsonTranscoder" +) + +func init() { + plugins.RegisterHttpPlugin(Name, &plugin{}) +} + +type plugin struct { + grpc_json_transcoder.Plugin +} + +// Each Native plugin need to implement the methods below + +// RouteConfigTypeURL returns the type url of per-route config +func (p *plugin) RouteConfigTypeURL() string { + return "type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder" +} + +// HTTPFilterConfigPlaceholder returns the placeholder config for http filter +func (p *plugin) HTTPFilterConfigPlaceholder() map[string]interface{} { + return map[string]interface{}{ + "typed_config": map[string]interface{}{ + "@type": p.RouteConfigTypeURL(), + }, + } +} diff --git a/controller/plugins/plugins.go b/controller/plugins/plugins.go index 9be29d47..79a06757 100644 --- a/controller/plugins/plugins.go +++ b/controller/plugins/plugins.go @@ -20,6 +20,7 @@ import ( _ "mosn.io/htnn/controller/plugins/cors" _ "mosn.io/htnn/controller/plugins/ext_proc" _ "mosn.io/htnn/controller/plugins/fault" + _ "mosn.io/htnn/controller/plugins/grpc_json_transcoder" _ "mosn.io/htnn/controller/plugins/local_ratelimit" _ "mosn.io/htnn/controller/plugins/lua" _ "mosn.io/htnn/types/plugins" diff --git a/e2e/base/grpc.yml b/e2e/base/grpc.yml new file mode 100644 index 00000000..194b032d --- /dev/null +++ b/e2e/base/grpc.yml @@ -0,0 +1,63 @@ +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: default +spec: + parentRefs: + - name: default + namespace: e2e + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: grpc-backend + port: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: grpc-backend +spec: + selector: + app: grpc-backend + ports: + - protocol: TCP + port: 8080 + targetPort: 3000 + appProtocol: kubernetes.io/h2c +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: grpc-backend + labels: + app: grpc-backend +spec: + replicas: 1 + selector: + matchLabels: + app: grpc-backend + template: + metadata: + labels: + app: grpc-backend + spec: + containers: + - name: grpc-backend + image: gcr.io/k8s-staging-gateway-api/echo-basic:v20240412-v1.0.0-394-g40c666fd + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: GRPC_ECHO_SERVER + value: "1" + resources: + requests: + cpu: 10m diff --git a/e2e/tests/grpc_json_transcoder.go b/e2e/tests/grpc_json_transcoder.go new file mode 100644 index 00000000..3524ea91 --- /dev/null +++ b/e2e/tests/grpc_json_transcoder.go @@ -0,0 +1,18 @@ +package tests + +import ( + "github.com/stretchr/testify/require" + "mosn.io/htnn/e2e/pkg/suite" + "testing" +) + +func init() { + suite.Register(suite.Test{ + Manifests: []string{"base/grpc.yml"}, + Run: func(t *testing.T, suite *suite.Suite) { + rsp, err := suite.Get("/echo", nil) + require.NoError(t, err) + require.Equal(t, 200, rsp.StatusCode) + }, + }) +} diff --git a/e2e/tests/grpc_json_transcoder.yml b/e2e/tests/grpc_json_transcoder.yml new file mode 100644 index 00000000..18668658 --- /dev/null +++ b/e2e/tests/grpc_json_transcoder.yml @@ -0,0 +1,20 @@ +apiVersion: htnn.mosn.io/v1 +kind: HTTPFilterPolicy +metadata: + name: policy +spec: + targetRef: + group: gateway.networking.k8s.io + kind: HTTPRoute + name: default + filters: + grpcJsonTranscoder: + config: + protoDescriptorBin: CuElCg5ncnBjZWNoby5wcm90bxIrZ2F0ZXdheV9hcGlfY29uZm9ybWFuY2UuZWNob19iYXNpYy5ncnBjZWNobyIwCgZIZWFkZXISEAoDa2V5GAEgASgJUgNrZXkSFAoFdmFsdWUYAiABKAlSBXZhbHVlInYKB0NvbnRleHQSHAoJbmFtZXNwYWNlGAEgASgJUgluYW1lc3BhY2USGAoHaW5ncmVzcxgCIAEoCVIHaW5ncmVzcxIhCgxzZXJ2aWNlX25hbWUYAyABKAlSC3NlcnZpY2VOYW1lEhAKA3BvZBgEIAEoCVIDcG9kIssBCg1UTFNBc3NlcnRpb25zE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TIGNvbm5lY3Rpb24gYmV0d2VlbiB0aGUgY2xpZW50IGFuZCB0aGUgc2VydmVyLgoKDAoFBAMCBAYSA0wCDwoMCgUEAwIEARIDTBAeCgwKBQQDAgQDEgNMISIKCQoCBAQSA08AFgoKCgMEBAESA08IEwoKCgIEBRIEUQBUAQoKCgMEBQESA1EIFAoLCgQEBQIAEgNSAhwKDAoFBAUCAAYSA1ICDAoMCgUEBQIAARIDUg0XCgwKBQQFAgADEgNSGhsKCwoEBAUCARIDUwIaCgwKBQQFAgEGEgNTAg0KDAoFBAUCAQESA1MOFQoMCgUEBQIBAxIDUxgZCgoKAgYAEgRWAF8BCgoKAwYAARIDVggQCgsKBAYAAgASA1cCMQoMCgUGAAIAARIDVwYKCgwKBQYAAgACEgNXCxYKDAoFBgACAAMSA1chLQqAAQoEBgACARIDWwI0GnMgQmVoYXZlcyBpZGVudGljYWxseSB0byBFY2hvLCBidXQgbGl2ZXMgYXQgYSBkaWZmZXJlbnQgbWV0aG9kIHRvCiBlbXVsYXRlIHRoZSBzZXJ2aWNlIGhhdmluZyBtb3JlIHRoYW4gb25lIG1ldGhvZC4KCgwKBQYAAgEBEgNbBg0KDAoFBgACAQISA1sOGQoMCgUGAAIBAxIDWyQwCjUKBAYAAgISA14CNhooIEFuIGludGVudGlvbmFsbHkgdW5pbXBsZW1lbnRlZCBtZXRob2QuCgoMCgUGAAICARIDXgYPCgwKBQYAAgICEgNeEBsKDAoFBgACAgMSA14mMmIGcHJvdG8z + services: + - helloworld.Greeter + printOptions: + addWhitespace: true + alwaysPrintPrimitiveFields: true + alwaysPrintEnumsAsInts: false + preserveProtoFieldNames: false \ No newline at end of file diff --git a/types/plugins/grpc_json_transcoder/config.go b/types/plugins/grpc_json_transcoder/config.go new file mode 100644 index 00000000..d621ca3d --- /dev/null +++ b/types/plugins/grpc_json_transcoder/config.go @@ -0,0 +1,33 @@ +package grpc_json_transcoder + +import ( + grpc_json_transcoder "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_json_transcoder/v3" + "mosn.io/htnn/api/pkg/filtermanager/api" + "mosn.io/htnn/api/pkg/plugins" +) + +const ( + Name = "grpcJsonTranscoder" +) + +func init() { + plugins.RegisterHttpPluginType(Name, &Plugin{}) +} + +type Plugin struct { + plugins.PluginMethodDefaultImpl +} + +func (p *Plugin) Type() plugins.PluginType { + return plugins.TypeTraffic +} + +func (p *Plugin) Order() plugins.PluginOrder { + return plugins.PluginOrder{ + Position: plugins.OrderPositionInner, + } +} + +func (p *Plugin) Config() api.PluginConfig { + return &grpc_json_transcoder.GrpcJsonTranscoder{} +} From 31b190f054934bd608834be65fc7a694596e205e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E8=B4=A4=E6=B6=9B?= <601803023@qq.com> Date: Sat, 29 Jun 2024 17:37:46 +0800 Subject: [PATCH 2/2] format go --- e2e/base/grpc.yml | 63 -------------------- e2e/tests/grpc_json_transcoder.go | 18 ------ e2e/tests/grpc_json_transcoder.yml | 20 ------- types/plugins/grpc_json_transcoder/config.go | 15 +++++ 4 files changed, 15 insertions(+), 101 deletions(-) delete mode 100644 e2e/base/grpc.yml delete mode 100644 e2e/tests/grpc_json_transcoder.go delete mode 100644 e2e/tests/grpc_json_transcoder.yml diff --git a/e2e/base/grpc.yml b/e2e/base/grpc.yml deleted file mode 100644 index 194b032d..00000000 --- a/e2e/base/grpc.yml +++ /dev/null @@ -1,63 +0,0 @@ -apiVersion: gateway.networking.k8s.io/v1 -kind: HTTPRoute -metadata: - name: default -spec: - parentRefs: - - name: default - namespace: e2e - rules: - - matches: - - path: - type: PathPrefix - value: / - backendRefs: - - name: grpc-backend - port: 8080 ---- -apiVersion: v1 -kind: Service -metadata: - name: grpc-backend -spec: - selector: - app: grpc-backend - ports: - - protocol: TCP - port: 8080 - targetPort: 3000 - appProtocol: kubernetes.io/h2c ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: grpc-backend - labels: - app: grpc-backend -spec: - replicas: 1 - selector: - matchLabels: - app: grpc-backend - template: - metadata: - labels: - app: grpc-backend - spec: - containers: - - name: grpc-backend - image: gcr.io/k8s-staging-gateway-api/echo-basic:v20240412-v1.0.0-394-g40c666fd - env: - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: GRPC_ECHO_SERVER - value: "1" - resources: - requests: - cpu: 10m diff --git a/e2e/tests/grpc_json_transcoder.go b/e2e/tests/grpc_json_transcoder.go deleted file mode 100644 index 3524ea91..00000000 --- a/e2e/tests/grpc_json_transcoder.go +++ /dev/null @@ -1,18 +0,0 @@ -package tests - -import ( - "github.com/stretchr/testify/require" - "mosn.io/htnn/e2e/pkg/suite" - "testing" -) - -func init() { - suite.Register(suite.Test{ - Manifests: []string{"base/grpc.yml"}, - Run: func(t *testing.T, suite *suite.Suite) { - rsp, err := suite.Get("/echo", nil) - require.NoError(t, err) - require.Equal(t, 200, rsp.StatusCode) - }, - }) -} diff --git a/e2e/tests/grpc_json_transcoder.yml b/e2e/tests/grpc_json_transcoder.yml deleted file mode 100644 index 18668658..00000000 --- a/e2e/tests/grpc_json_transcoder.yml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: htnn.mosn.io/v1 -kind: HTTPFilterPolicy -metadata: - name: policy -spec: - targetRef: - group: gateway.networking.k8s.io - kind: HTTPRoute - name: default - filters: - grpcJsonTranscoder: - config: - protoDescriptorBin: CuElCg5ncnBjZWNoby5wcm90bxIrZ2F0ZXdheV9hcGlfY29uZm9ybWFuY2UuZWNob19iYXNpYy5ncnBjZWNobyIwCgZIZWFkZXISEAoDa2V5GAEgASgJUgNrZXkSFAoFdmFsdWUYAiABKAlSBXZhbHVlInYKB0NvbnRleHQSHAoJbmFtZXNwYWNlGAEgASgJUgluYW1lc3BhY2USGAoHaW5ncmVzcxgCIAEoCVIHaW5ncmVzcxIhCgxzZXJ2aWNlX25hbWUYAyABKAlSC3NlcnZpY2VOYW1lEh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DTAIjGk4gSW5mb3JtYXRpb24gcmVsYXRlZCB0byB0aGUgVExTIGNvbm5lY3Rpb24gYmV0d2VlbiB0aGUgY2xpZW50IGFuZCB0aGUgc2VydmVyLgoKDAoFBAMCBAYSA0wCDwoMCgUEAwIEARIDTBAeCgwKBQQDAgQDEgNMISIKCQoCBAQSA08AFgoKCgMEBAESA08IEwoKCgIEBRIEUQBUAQoKCgMEBQESA1EIFAoLCgQEBQIAEgNSAhwKDAoFBAUCAAYSA1ICDAoMCgUEBQIAARIDUg0XCgwKBQQFAgADEgNSGhsKCwoEBAUCARIDUwIaCgwKBQQFAgEGEgNTAg0KDAoFBAUCAQESA1MOFQoMCgUEBQIBAxIDUxgZCgoKAgYAEgRWAF8BCgoKAwYAARIDVggQCgsKBAYAAgASA1cCMQoMCgUGAAIAARIDVwYKCgwKBQYAAgACEgNXCxYKDAoFBgACAAMSA1chLQqAAQoEBgACARIDWwI0GnMgQmVoYXZlcyBpZGVudGljYWxseSB0byBFY2hvLCBidXQgbGl2ZXMgYXQgYSBkaWZmZXJlbnQgbWV0aG9kIHRvCiBlbXVsYXRlIHRoZSBzZXJ2aWNlIGhhdmluZyBtb3JlIHRoYW4gb25lIG1ldGhvZC4KCgwKBQYAAgEBEgNbBg0KDAoFBgACAQISA1sOGQoMCgUGAAIBAxIDWyQwCjUKBAYAAgISA14CNhooIEFuIGludGVudGlvbmFsbHkgdW5pbXBsZW1lbnRlZCBtZXRob2QuCgoMCgUGAAICARIDXgYPCgwKBQYAAgICEgNeEBsKDAoFBgACAgMSA14mMmIGcHJvdG8z - services: - - helloworld.Greeter - printOptions: - addWhitespace: true - alwaysPrintPrimitiveFields: true - alwaysPrintEnumsAsInts: false - preserveProtoFieldNames: false \ No newline at end of file diff --git a/types/plugins/grpc_json_transcoder/config.go b/types/plugins/grpc_json_transcoder/config.go index d621ca3d..56180609 100644 --- a/types/plugins/grpc_json_transcoder/config.go +++ b/types/plugins/grpc_json_transcoder/config.go @@ -1,7 +1,22 @@ +// Copyright The HTNN Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package grpc_json_transcoder import ( grpc_json_transcoder "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_json_transcoder/v3" + "mosn.io/htnn/api/pkg/filtermanager/api" "mosn.io/htnn/api/pkg/plugins" )