Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring RESTAPI to GRPC via HTTPFilterPolicy #616

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: {}
48 changes: 48 additions & 0 deletions controller/plugins/grpc_json_transcoder/config.go
Original file line number Diff line number Diff line change
@@ -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(),
},
}
}
1 change: 1 addition & 0 deletions controller/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions types/plugins/grpc_json_transcoder/config.go
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 37 in types/plugins/grpc_json_transcoder/config.go

View check run for this annotation

Codecov / codecov/patch

types/plugins/grpc_json_transcoder/config.go#L36-L37

Added lines #L36 - L37 were not covered by tests
}

func (p *Plugin) Order() plugins.PluginOrder {
return plugins.PluginOrder{
Position: plugins.OrderPositionInner,
}
}

func (p *Plugin) Config() api.PluginConfig {
return &grpc_json_transcoder.GrpcJsonTranscoder{}
}
Loading