-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Vendor updates for gRPC and xDS server * xDS server implementation for serving Envoy as a Connect proxy * Address initial review comments * consistent envoy package aliases; typos fixed; override TLS and authz for custom listeners * Moar Typos * Moar typos
- Loading branch information
Showing
214 changed files
with
137,803 additions
and
5,546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package xds | ||
|
||
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/hashicorp/consul/agent/proxycfg" | ||
) | ||
|
||
// 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") | ||
} | ||
// Include the "app" cluster for the public listener | ||
clusters := make([]proto.Message, len(cfgSnap.Proxy.Upstreams)+1) | ||
|
||
clusters[0] = makeAppCluster(cfgSnap) | ||
|
||
for idx, upstream := range cfgSnap.Proxy.Upstreams { | ||
clusters[idx+1] = makeUpstreamCluster(upstream.Identifier(), cfgSnap) | ||
} | ||
|
||
return clusters, nil | ||
} | ||
|
||
func makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot) *envoy.Cluster { | ||
addr := cfgSnap.Proxy.LocalServiceAddress | ||
if addr == "" { | ||
addr = "127.0.0.1" | ||
} | ||
return &envoy.Cluster{ | ||
Name: LocalAppClusterName, | ||
// TODO(banks): make this configurable from the proxy config | ||
ConnectTimeout: 5 * time.Second, | ||
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: []*envoycore.Address{makeAddressPtr(addr, cfgSnap.Proxy.LocalServicePort)}, | ||
// LoadAssignment: &envoy.ClusterLoadAssignment{ | ||
// ClusterName: LocalAppClusterName, | ||
// Endpoints: []endpoint.LocalityLbEndpoints{ | ||
// { | ||
// LbEndpoints: []endpoint.LbEndpoint{ | ||
// makeEndpoint(LocalAppClusterName, | ||
// addr, | ||
// cfgSnap.Proxy.LocalServicePort), | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
} | ||
} | ||
|
||
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: 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: &envoyauth.UpstreamTlsContext{ | ||
CommonTlsContext: makeCommonTLSContext(cfgSnap), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package xds | ||
|
||
import ( | ||
"errors" | ||
|
||
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 representation of the "endpoints" | ||
// (upstream instances) in the snapshot. | ||
func endpointsFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]proto.Message, error) { | ||
if cfgSnap == nil { | ||
return nil, errors.New("nil config given") | ||
} | ||
resources := make([]proto.Message, 0, len(cfgSnap.UpstreamEndpoints)) | ||
for id, endpoints := range cfgSnap.UpstreamEndpoints { | ||
if len(endpoints) < 1 { | ||
continue | ||
} | ||
la := makeLoadAssignment(id, endpoints) | ||
resources = append(resources, la) | ||
} | ||
return resources, nil | ||
} | ||
|
||
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) *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, envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr(addr, ep.Service.Port), | ||
}, | ||
}) | ||
} | ||
return &envoy.ClusterLoadAssignment{ | ||
ClusterName: clusterName, | ||
Endpoints: []envoyendpoint.LocalityLbEndpoints{{ | ||
LbEndpoints: es, | ||
}}, | ||
} | ||
} |
Oops, something went wrong.