Skip to content

Commit

Permalink
Remove deprecated APIs for the Envoy gRPC API
Browse files Browse the repository at this point in the history
Envoy v1.12.0+ supports the new APIs
  • Loading branch information
mihaitodor authored and relistan committed Aug 4, 2020
1 parent db5e775 commit 17251cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
11 changes: 4 additions & 7 deletions envoy/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
hcm "github.com/envoyproxy/go-control-plane/envoy/config/filter/network/http_connection_manager/v2"
tcpp "github.com/envoyproxy/go-control-plane/envoy/config/filter/network/tcp_proxy/v2"
"github.com/envoyproxy/go-control-plane/pkg/cache"
"github.com/envoyproxy/go-control-plane/pkg/conversion"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/duration"
"github.com/golang/protobuf/ptypes/wrappers"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -213,9 +213,7 @@ func envoyListenerFromService(svc *service.Service, envoyServiceName string,
return nil, fmt.Errorf("unrecognised proxy mode: %s", svc.ProxyMode)
}

// TODO: Switch to ptypes.MarshalAny when updating the Envoy API
// See the original implementation from 080e510
serialisedConnectionManager, err := conversion.MessageToStruct(connectionManager)
serialisedConnectionManager, err := ptypes.MarshalAny(connectionManager)
if err != nil {
return nil, fmt.Errorf("failed to create the connection manager: %s", err)
}
Expand All @@ -235,9 +233,8 @@ func envoyListenerFromService(svc *service.Service, envoyServiceName string,
FilterChains: []*listener.FilterChain{{
Filters: []*listener.Filter{{
Name: connectionManagerName,
// TODO: Switch to Filter_TypedConfig when updating the Envoy API
ConfigType: &listener.Filter_Config{
Config: serialisedConnectionManager,
ConfigType: &listener.Filter_TypedConfig{
TypedConfig: serialisedConnectionManager,
},
}},
}},
Expand Down
31 changes: 18 additions & 13 deletions envoy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
"github.com/Nitro/sidecar/service"
api "github.com/envoyproxy/go-control-plane/envoy/api/v2"
core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
hcm "github.com/envoyproxy/go-control-plane/envoy/config/filter/network/http_connection_manager/v2"
tcpp "github.com/envoyproxy/go-control-plane/envoy/config/filter/network/tcp_proxy/v2"
envoy_discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
"github.com/envoyproxy/go-control-plane/pkg/cache"
"github.com/envoyproxy/go-control-plane/pkg/conversion"
xds "github.com/envoyproxy/go-control-plane/pkg/server"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"github.com/golang/protobuf/ptypes"
Expand Down Expand Up @@ -53,22 +54,26 @@ func validateListener(serialisedListener *any.Any, svc service.Service) {

if svc.ProxyMode == "http" {
So(filters[0].GetName(), ShouldEqual, wellknown.HTTPConnectionManager)
// TODO: Switch to ptypes.MarshalAny when updating the Envoy API
// See the original implementation from 080e510
//nolint:staticcheck // ignore SA1019 for deprecated code
connectionManager, err := conversion.MessageToStruct(filters[0].GetConfig())
connectionManager := &hcm.HttpConnectionManager{}
err = ptypes.UnmarshalAny(filters[0].GetTypedConfig(), connectionManager)
So(err, ShouldBeNil)
So(connectionManager, ShouldNotBeZeroValue)
So(connectionManager.GetFields()["stat_prefix"].GetStringValue(), ShouldEqual, "ingress_http")
So(connectionManager.GetStatPrefix(), ShouldEqual, "ingress_http")
So(connectionManager.GetRouteConfig(), ShouldNotBeNil)
So(connectionManager.GetRouteConfig().GetVirtualHosts(), ShouldHaveLength, 1)
virtualHost := connectionManager.GetRouteConfig().GetVirtualHosts()[0]
So(virtualHost.GetName(), ShouldEqual, svc.Name)
So(virtualHost.GetRoutes(), ShouldHaveLength, 1)
route := virtualHost.GetRoutes()[0].GetRoute()
So(route, ShouldNotBeNil)
So(route.GetCluster(), ShouldEqual, adapter.SvcName(svc.Name, svc.Ports[0].ServicePort))
So(route.GetTimeout(), ShouldNotBeNil)
} else { // tcp
So(filters[0].GetName(), ShouldEqual, wellknown.TCPProxy)
// TODO: Switch to ptypes.MarshalAny when updating the Envoy API
// See the original implementation from 080e510
//nolint:staticcheck // ignore SA1019 for deprecated code
connectionManager, err := conversion.MessageToStruct(filters[0].GetConfig())
connectionManager := &tcpp.TcpProxy{}
err = ptypes.UnmarshalAny(filters[0].GetTypedConfig(), connectionManager)
So(err, ShouldBeNil)
So(connectionManager.GetFields()["stat_prefix"].GetStringValue(), ShouldEqual, "ingress_tcp")
So(connectionManager.GetFields()["cluster"].GetStringValue(), ShouldEqual, adapter.SvcName(svc.Name, svc.Ports[0].ServicePort))
So(connectionManager.GetStatPrefix(), ShouldEqual, "ingress_tcp")
So(connectionManager.GetCluster(), ShouldEqual, adapter.SvcName(svc.Name, svc.Ports[0].ServicePort))
}
}

Expand Down

0 comments on commit 17251cc

Please sign in to comment.