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/types/plugins/grpc_json_transcoder/config.go b/types/plugins/grpc_json_transcoder/config.go new file mode 100644 index 00000000..56180609 --- /dev/null +++ b/types/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 ( + 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{} +}