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

connect: upgrade github.com/envoyproxy/go-control-plane to v0.9.5 #8247

Merged
merged 1 commit into from
Jul 7, 2020
Merged
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
36 changes: 18 additions & 18 deletions agent/xds/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/hashicorp/consul/logging"
"time"

envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
Expand All @@ -13,13 +12,14 @@ import (
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoyendpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
envoytype "github.com/envoyproxy/go-control-plane/envoy/type"
"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/types"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/hashicorp/consul/agent/connect"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/logging"
)

// clustersFromSnapshot returns the xDS API representation of the "clusters" in the snapshot.
Expand Down Expand Up @@ -314,13 +314,13 @@ func (s *Server) makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot, name, pathProt
}
c = &envoy.Cluster{
Name: name,
ConnectTimeout: time.Duration(cfg.LocalConnectTimeoutMs) * time.Millisecond,
ConnectTimeout: ptypes.DurationProto(time.Duration(cfg.LocalConnectTimeoutMs) * time.Millisecond),
ClusterDiscoveryType: &envoy.Cluster_Type{Type: envoy.Cluster_STATIC},
LoadAssignment: &envoy.ClusterLoadAssignment{
ClusterName: name,
Endpoints: []envoyendpoint.LocalityLbEndpoints{
Endpoints: []*envoyendpoint.LocalityLbEndpoints{
{
LbEndpoints: []envoyendpoint.LbEndpoint{
LbEndpoints: []*envoyendpoint.LbEndpoint{
makeEndpoint(name,
addr,
port),
Expand Down Expand Up @@ -367,7 +367,7 @@ func (s *Server) makeUpstreamClusterForPreparedQuery(upstream structs.Upstream,
if c == nil {
c = &envoy.Cluster{
Name: sni,
ConnectTimeout: time.Duration(cfg.ConnectTimeoutMs) * time.Millisecond,
ConnectTimeout: ptypes.DurationProto(time.Duration(cfg.ConnectTimeoutMs) * time.Millisecond),
ClusterDiscoveryType: &envoy.Cluster_Type{Type: envoy.Cluster_EDS},
EdsClusterConfig: &envoy.Cluster_EdsClusterConfig{
EdsConfig: &envoycore.ConfigSource{
Expand Down Expand Up @@ -463,7 +463,7 @@ func (s *Server) makeUpstreamClustersForDiscoveryChain(
c := &envoy.Cluster{
Name: clusterName,
AltStatName: clusterName,
ConnectTimeout: node.Resolver.ConnectTimeout,
ConnectTimeout: ptypes.DurationProto(node.Resolver.ConnectTimeout),
ClusterDiscoveryType: &envoy.Cluster_Type{Type: envoy.Cluster_EDS},
CommonLbConfig: &envoy.Cluster_CommonLbConfig{
HealthyPanicThreshold: &envoytype.Percent{
Expand Down Expand Up @@ -548,7 +548,7 @@ func makeClusterFromUserConfig(configJSON string) (*envoy.Cluster, error) {

if _, ok := jsonFields["@type"]; ok {
// Type field is present so decode it as a types.Any
var any types.Any
var any any.Any
err := jsonpb.UnmarshalString(configJSON, &any)
if err != nil {
return nil, err
Expand Down Expand Up @@ -597,7 +597,7 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC

cluster := &envoy.Cluster{
Name: opts.name,
ConnectTimeout: opts.connectTimeout,
ConnectTimeout: ptypes.DurationProto(opts.connectTimeout),

// Having an empty config enables outlier detection with default config.
OutlierDetection: &envoycluster.OutlierDetection{},
Expand All @@ -624,7 +624,7 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC
// When a service instance is addressed by a hostname we have Envoy do the DNS resolution
// by setting a DNS cluster type and passing the hostname endpoints via CDS.
rate := 10 * time.Second
cluster.DnsRefreshRate = &rate
cluster.DnsRefreshRate = ptypes.DurationProto(rate)
cluster.DnsLookupFamily = envoy.Cluster_V4_ONLY

discoveryType := envoy.Cluster_Type{Type: envoy.Cluster_LOGICAL_DNS}
Expand All @@ -633,13 +633,13 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC
}
cluster.ClusterDiscoveryType = &discoveryType

endpoints := make([]envoyendpoint.LbEndpoint, 0, 1)
endpoints := make([]*envoyendpoint.LbEndpoint, 0, 1)
uniqueHostnames := make(map[string]bool)

var (
hostname string
idx int
fallback envoyendpoint.LbEndpoint
fallback *envoyendpoint.LbEndpoint
)
for i, e := range opts.hostnameEndpoints {
addr, port := e.BestAddress(opts.isRemote)
Expand Down Expand Up @@ -683,7 +683,7 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC

cluster.LoadAssignment = &envoy.ClusterLoadAssignment{
ClusterName: cluster.Name,
Endpoints: []envoyendpoint.LocalityLbEndpoints{
Endpoints: []*envoyendpoint.LocalityLbEndpoints{
{
LbEndpoints: endpoints,
},
Expand Down Expand Up @@ -728,8 +728,8 @@ func makeThresholdsIfNeeded(limits UpstreamLimits) []*envoycluster.CircuitBreake
return []*envoycluster.CircuitBreakers_Thresholds{threshold}
}

func makeLbEndpoint(addr string, port int, health envoycore.HealthStatus, weight int) envoyendpoint.LbEndpoint {
return envoyendpoint.LbEndpoint{
func makeLbEndpoint(addr string, port int, health envoycore.HealthStatus, weight int) *envoyendpoint.LbEndpoint {
return &envoyendpoint.LbEndpoint{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: &envoycore.Address{
Expand Down
7 changes: 4 additions & 3 deletions agent/xds/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"time"

envoycluster "github.com/envoyproxy/go-control-plane/envoy/api/v2/cluster"
"github.com/gogo/protobuf/types"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/lib/decode"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -211,10 +212,10 @@ type PassiveHealthCheck struct {
func (p PassiveHealthCheck) AsOutlierDetection() *envoycluster.OutlierDetection {
od := &envoycluster.OutlierDetection{}
if p.Interval != 0 {
od.Interval = types.DurationProto(p.Interval)
od.Interval = ptypes.DurationProto(p.Interval)
}
if p.MaxFailures != 0 {
od.Consecutive_5Xx = &types.UInt32Value{Value: p.MaxFailures}
od.Consecutive_5Xx = &wrappers.UInt32Value{Value: p.MaxFailures}
}
return od
}
Expand Down
33 changes: 16 additions & 17 deletions agent/xds/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package xds
import (
"errors"
"fmt"

envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoyendpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
"github.com/gogo/protobuf/proto"

"github.com/golang/protobuf/proto"
"github.com/hashicorp/consul/agent/connect"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"

bexpr "github.com/hashicorp/go-bexpr"
)

Expand Down Expand Up @@ -162,26 +161,26 @@ func (s *Server) endpointsFromSnapshotMeshGateway(cfgSnap *proxycfg.ConfigSnapsh

// generate endpoints for our servers if WAN federation is enabled
if cfgSnap.ServiceMeta[structs.MetaWANFederationKey] == "1" && cfgSnap.ServerSNIFn != nil {
var allServersLbEndpoints []envoyendpoint.LbEndpoint
var allServersLbEndpoints []*envoyendpoint.LbEndpoint

for _, srv := range cfgSnap.MeshGateway.ConsulServers {
clusterName := cfgSnap.ServerSNIFn(cfgSnap.Datacenter, srv.Node.Node)

addr, port := srv.BestAddress(false /*wan*/)

lbEndpoint := envoyendpoint.LbEndpoint{
lbEndpoint := &envoyendpoint.LbEndpoint{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr(addr, port),
Address: makeAddress(addr, port),
},
},
HealthStatus: envoycore.HealthStatus_UNKNOWN,
}

cla := &envoy.ClusterLoadAssignment{
ClusterName: clusterName,
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []envoyendpoint.LbEndpoint{lbEndpoint},
Endpoints: []*envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []*envoyendpoint.LbEndpoint{lbEndpoint},
}},
}
allServersLbEndpoints = append(allServersLbEndpoints, lbEndpoint)
Expand All @@ -193,7 +192,7 @@ func (s *Server) endpointsFromSnapshotMeshGateway(cfgSnap *proxycfg.ConfigSnapsh
// in this datacenter without knowing its name.
resources = append(resources, &envoy.ClusterLoadAssignment{
ClusterName: cfgSnap.ServerSNIFn(cfgSnap.Datacenter, ""),
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
Endpoints: []*envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: allServersLbEndpoints,
}},
})
Expand Down Expand Up @@ -289,11 +288,11 @@ func (s *Server) endpointsFromSnapshotIngressGateway(cfgSnap *proxycfg.ConfigSna
return resources, nil
}

func makeEndpoint(clusterName, host string, port int) envoyendpoint.LbEndpoint {
return envoyendpoint.LbEndpoint{
func makeEndpoint(clusterName, host string, port int) *envoyendpoint.LbEndpoint {
return &envoyendpoint.LbEndpoint{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr(host, port),
Address: makeAddress(host, port),
},
},
}
Expand Down Expand Up @@ -423,7 +422,7 @@ type loadAssignmentEndpointGroup struct {
func makeLoadAssignment(clusterName string, endpointGroups []loadAssignmentEndpointGroup, localDatacenter string) *envoy.ClusterLoadAssignment {
cla := &envoy.ClusterLoadAssignment{
ClusterName: clusterName,
Endpoints: make([]envoyendpoint.LocalityLbEndpoints, 0, len(endpointGroups)),
Endpoints: make([]*envoyendpoint.LocalityLbEndpoints, 0, len(endpointGroups)),
}

if len(endpointGroups) > 1 {
Expand All @@ -436,7 +435,7 @@ func makeLoadAssignment(clusterName string, endpointGroups []loadAssignmentEndpo

for priority, endpointGroup := range endpointGroups {
endpoints := endpointGroup.Endpoints
es := make([]envoyendpoint.LbEndpoint, 0, len(endpoints))
es := make([]*envoyendpoint.LbEndpoint, 0, len(endpoints))

for _, ep := range endpoints {
// TODO (mesh-gateway) - should we respect the translate_wan_addrs configuration here or just always use the wan for cross-dc?
Expand All @@ -447,18 +446,18 @@ func makeLoadAssignment(clusterName string, endpointGroups []loadAssignmentEndpo
healthStatus = endpointGroup.OverrideHealth
}

es = append(es, envoyendpoint.LbEndpoint{
es = append(es, &envoyendpoint.LbEndpoint{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr(addr, port),
Address: makeAddress(addr, port),
},
},
HealthStatus: healthStatus,
LoadBalancingWeight: makeUint32Value(weight),
})
}

cla.Endpoints = append(cla.Endpoints, envoyendpoint.LocalityLbEndpoints{
cla.Endpoints = append(cla.Endpoints, &envoyendpoint.LocalityLbEndpoints{
Priority: uint32(priority),
LbEndpoints: es,
})
Expand Down
54 changes: 27 additions & 27 deletions agent/xds/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"

envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoyendpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
Expand Down Expand Up @@ -108,8 +108,8 @@ func Test_makeLoadAssignment(t *testing.T) {
},
want: &envoy.ClusterLoadAssignment{
ClusterName: "service:test",
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []envoyendpoint.LbEndpoint{},
Endpoints: []*envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []*envoyendpoint.LbEndpoint{},
}},
},
},
Expand All @@ -121,22 +121,22 @@ func Test_makeLoadAssignment(t *testing.T) {
},
want: &envoy.ClusterLoadAssignment{
ClusterName: "service:test",
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []envoyendpoint.LbEndpoint{
envoyendpoint.LbEndpoint{
Endpoints: []*envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []*envoyendpoint.LbEndpoint{
{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr("10.10.10.10", 1234),
Address: makeAddress("10.10.10.10", 1234),
}},
HealthStatus: core.HealthStatus_HEALTHY,
HealthStatus: envoycore.HealthStatus_HEALTHY,
LoadBalancingWeight: makeUint32Value(1),
},
envoyendpoint.LbEndpoint{
{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr("10.10.10.20", 1234),
Address: makeAddress("10.10.10.20", 1234),
}},
HealthStatus: core.HealthStatus_HEALTHY,
HealthStatus: envoycore.HealthStatus_HEALTHY,
LoadBalancingWeight: makeUint32Value(1),
},
},
Expand All @@ -151,22 +151,22 @@ func Test_makeLoadAssignment(t *testing.T) {
},
want: &envoy.ClusterLoadAssignment{
ClusterName: "service:test",
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []envoyendpoint.LbEndpoint{
envoyendpoint.LbEndpoint{
Endpoints: []*envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []*envoyendpoint.LbEndpoint{
{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr("10.10.10.10", 1234),
Address: makeAddress("10.10.10.10", 1234),
}},
HealthStatus: core.HealthStatus_HEALTHY,
HealthStatus: envoycore.HealthStatus_HEALTHY,
LoadBalancingWeight: makeUint32Value(10),
},
envoyendpoint.LbEndpoint{
{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr("10.10.10.20", 1234),
Address: makeAddress("10.10.10.20", 1234),
}},
HealthStatus: core.HealthStatus_HEALTHY,
HealthStatus: envoycore.HealthStatus_HEALTHY,
LoadBalancingWeight: makeUint32Value(5),
},
},
Expand All @@ -181,22 +181,22 @@ func Test_makeLoadAssignment(t *testing.T) {
},
want: &envoy.ClusterLoadAssignment{
ClusterName: "service:test",
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []envoyendpoint.LbEndpoint{
envoyendpoint.LbEndpoint{
Endpoints: []*envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: []*envoyendpoint.LbEndpoint{
{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr("10.10.10.10", 1234),
Address: makeAddress("10.10.10.10", 1234),
}},
HealthStatus: core.HealthStatus_HEALTHY,
HealthStatus: envoycore.HealthStatus_HEALTHY,
LoadBalancingWeight: makeUint32Value(1),
},
envoyendpoint.LbEndpoint{
{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr("10.10.10.20", 1234),
Address: makeAddress("10.10.10.20", 1234),
}},
HealthStatus: core.HealthStatus_UNHEALTHY,
HealthStatus: envoycore.HealthStatus_UNHEALTHY,
LoadBalancingWeight: makeUint32Value(1),
},
},
Expand Down
3 changes: 1 addition & 2 deletions agent/xds/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"testing"

envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/gogo/protobuf/jsonpb"

"github.com/golang/protobuf/jsonpb"
"github.com/stretchr/testify/require"
)

Expand Down
Loading