Skip to content

Commit

Permalink
consistent envoy package aliases; typos fixed; override TLS and authz…
Browse files Browse the repository at this point in the history
… for custom listeners
  • Loading branch information
banks committed Oct 3, 2018
1 parent 228a2ab commit 104603e
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 229 deletions.
36 changes: 18 additions & 18 deletions agent/xds/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"errors"
"time"

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

"github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/auth"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
"github.com/hashicorp/consul/agent/proxycfg"
)

// clustersFromSnapshot returns the xDS API reprepsentation of the "clusters"
// clustersFromSnapshot returns the xDS API representation of the "clusters"
// (upstreams) in the snapshot.
func clustersFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]proto.Message, error) {
if cfgSnap == nil {
return nil, errors.New("nil config given")
}
// Inlude the "app" cluster for the public listener
// Include the "app" cluster for the public listener
clusters := make([]proto.Message, len(cfgSnap.Proxy.Upstreams)+1)

clusters[0] = makeAppCluster(cfgSnap)
Expand All @@ -30,20 +30,20 @@ func clustersFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]pro
return clusters, nil
}

func makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot) *v2.Cluster {
func makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot) *envoy.Cluster {
addr := cfgSnap.Proxy.LocalServiceAddress
if addr == "" {
addr = "127.0.0.1"
}
return &v2.Cluster{
return &envoy.Cluster{
Name: LocalAppClusterName,
// TODO(banks): make this configurable from the proxy config
ConnectTimeout: 5 * time.Second,
Type: v2.Cluster_STATIC,
Type: envoy.Cluster_STATIC,
// API v2 docs say hosts is deprecated and should use LoadAssignment as
// below.. but it doesn't work for tcp_proxy target for some reason.
Hosts: []*core.Address{makeAddressPtr(addr, cfgSnap.Proxy.LocalServicePort)},
// LoadAssignment: &v2.ClusterLoadAssignment{
Hosts: []*envoycore.Address{makeAddressPtr(addr, cfgSnap.Proxy.LocalServicePort)},
// LoadAssignment: &envoy.ClusterLoadAssignment{
// ClusterName: LocalAppClusterName,
// Endpoints: []endpoint.LocalityLbEndpoints{
// {
Expand All @@ -58,21 +58,21 @@ func makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot) *v2.Cluster {
}
}

func makeUpstreamCluster(name string, cfgSnap *proxycfg.ConfigSnapshot) *v2.Cluster {
return &v2.Cluster{
func makeUpstreamCluster(name string, cfgSnap *proxycfg.ConfigSnapshot) *envoy.Cluster {
return &envoy.Cluster{
Name: name,
// TODO(banks): make this configurable from the upstream config
ConnectTimeout: 5 * time.Second,
Type: v2.Cluster_EDS,
EdsClusterConfig: &v2.Cluster_EdsClusterConfig{
EdsConfig: &core.ConfigSource{
ConfigSourceSpecifier: &core.ConfigSource_Ads{
Ads: &core.AggregatedConfigSource{},
Type: envoy.Cluster_EDS,
EdsClusterConfig: &envoy.Cluster_EdsClusterConfig{
EdsConfig: &envoycore.ConfigSource{
ConfigSourceSpecifier: &envoycore.ConfigSource_Ads{
Ads: &envoycore.AggregatedConfigSource{},
},
},
},
// Enable TLS upstream with the configured client certificate.
TlsContext: &auth.UpstreamTlsContext{
TlsContext: &envoyauth.UpstreamTlsContext{
CommonTlsContext: makeCommonTLSContext(cfgSnap),
},
}
Expand Down
24 changes: 12 additions & 12 deletions agent/xds/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package xds
import (
"errors"

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

"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
)

// endpointsFromSnapshot returns the xDS API reprepsentation of the "endpoints"
// endpointsFromSnapshot returns the xDS API representation of the "endpoints"
// (upstream instances) in the snapshot.
func endpointsFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]proto.Message, error) {
if cfgSnap == nil {
Expand All @@ -28,30 +28,30 @@ func endpointsFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]pr
return resources, nil
}

func makeEndpoint(clusterName, host string, port int) endpoint.LbEndpoint {
return endpoint.LbEndpoint{
Endpoint: &endpoint.Endpoint{
func makeEndpoint(clusterName, host string, port int) envoyendpoint.LbEndpoint {
return envoyendpoint.LbEndpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr(host, port),
},
}
}

func makeLoadAssignment(clusterName string, endpoints structs.CheckServiceNodes) *v2.ClusterLoadAssignment {
es := make([]endpoint.LbEndpoint, 0, len(endpoints))
func makeLoadAssignment(clusterName string, endpoints structs.CheckServiceNodes) *envoy.ClusterLoadAssignment {
es := make([]envoyendpoint.LbEndpoint, 0, len(endpoints))
for _, ep := range endpoints {
addr := ep.Service.Address
if addr == "" {
addr = ep.Node.Address
}
es = append(es, endpoint.LbEndpoint{
Endpoint: &endpoint.Endpoint{
es = append(es, envoyendpoint.LbEndpoint{
Endpoint: &envoyendpoint.Endpoint{
Address: makeAddressPtr(addr, ep.Service.Port),
},
})
}
return &v2.ClusterLoadAssignment{
return &envoy.ClusterLoadAssignment{
ClusterName: clusterName,
Endpoints: []endpoint.LocalityLbEndpoints{{
Endpoints: []envoyendpoint.LocalityLbEndpoints{{
LbEndpoints: es,
}},
}
Expand Down
Loading

0 comments on commit 104603e

Please sign in to comment.