Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 48 additions & 7 deletions agent/xds/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/hashicorp/consul/logging"
"time"

envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
Expand Down Expand Up @@ -582,6 +583,7 @@ type gatewayClusterOpts struct {
hostnameEndpoints structs.CheckServiceNodes
}

// makeGatewayCluster creates an Envoy cluster for a mesh or terminating gateway
func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayClusterOpts) *envoy.Cluster {
cfg, err := ParseGatewayConfig(snap.Proxy.Config)
if err != nil {
Expand Down Expand Up @@ -631,11 +633,53 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC
}
cluster.ClusterDiscoveryType = &discoveryType

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

var (
hostname string
idx int
)
for i, e := range opts.hostnameEndpoints {
addr, port := e.BestAddress(opts.isRemote)
if !uniqueHostnames[addr] {
uniqueHostnames[addr] = true
}
Comment thread
freddygv marked this conversation as resolved.
Outdated

health, weight := calculateEndpointHealthAndWeight(e, opts.onlyPassing)
if health == envoycore.HealthStatus_UNHEALTHY {
continue
}

if len(endpoints) == 0 {
endpoints = append(endpoints, makeLbEndpoint(addr, port, health, weight))

hostname = addr
idx = i
Comment thread
crhino marked this conversation as resolved.
}
}

for _, e := range opts.hostnameEndpoints {
endpoints = append(endpoints, makeLbEndpoint(e, opts.isRemote, opts.onlyPassing))
dc := opts.hostnameEndpoints[idx].Node.Datacenter
service := opts.hostnameEndpoints[idx].Service.CompoundServiceName()

loggerName := logging.TerminatingGateway
if snap.Kind == structs.ServiceKindMeshGateway {
loggerName = logging.MeshGateway
}

if len(endpoints) == 0 {
s.Logger.Named(loggerName).
Warn("service does not contain any healthy instances, skipping Envoy cluster creation",
"dc", dc, "service", service.String())

return nil
}
if len(uniqueHostnames) > 0 {
Comment thread
freddygv marked this conversation as resolved.
Outdated
s.Logger.Named(loggerName).
Warn(fmt.Sprintf("service contains instances with more than one unique hostname; only %q be resolved by Envoy.", hostname),
Comment thread
freddygv marked this conversation as resolved.
Outdated
"dc", dc, "service", service.String())
}

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

func makeLbEndpoint(csn structs.CheckServiceNode, isRemote, onlyPassing bool) envoyendpoint.LbEndpoint {
health, weight := calculateEndpointHealthAndWeight(csn, onlyPassing)
addr, port := csn.BestAddress(isRemote)

func makeLbEndpoint(addr string, port int, health envoycore.HealthStatus, weight int) envoyendpoint.LbEndpoint {
return envoyendpoint.LbEndpoint{
HostIdentifier: &envoyendpoint.LbEndpoint_Endpoint{
Endpoint: &envoyendpoint.Endpoint{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
"socketAddress": {
"address": "456.us-west-2.elb.notaws.com",
"portValue": 443
}
}
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
}
]
}
Expand Down
12 changes: 0 additions & 12 deletions agent/xds/testdata/clusters/mesh-gateway-service-subsets.golden
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
"socketAddress": {
"address": "456.us-west-2.elb.notaws.com",
"portValue": 443
}
}
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
}
]
}
Expand Down
12 changes: 0 additions & 12 deletions agent/xds/testdata/clusters/mesh-gateway-service-timeouts.golden
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
"socketAddress": {
"address": "456.us-west-2.elb.notaws.com",
"portValue": 443
}
}
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
"socketAddress": {
"address": "456.us-west-2.elb.notaws.com",
"portValue": 443
}
}
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
}
]
}
Expand Down
12 changes: 0 additions & 12 deletions agent/xds/testdata/clusters/mesh-gateway.golden
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
"socketAddress": {
"address": "456.us-west-2.elb.notaws.com",
"portValue": 443
}
}
},
"healthStatus": "HEALTHY",
"loadBalancingWeight": 1
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@
"endpoints": [
{
"lbEndpoints": [
{
Comment thread
crhino marked this conversation as resolved.
"endpoint": {
"address": {
"socketAddress": {
"address": "api.mydomain",
"portValue": 8081
}
}
},
"healthStatus": "UNHEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
"endpoints": [
{
"lbEndpoints": [
{
"endpoint": {
"address": {
"socketAddress": {
"address": "api.mydomain",
"portValue": 8081
}
}
},
"healthStatus": "UNHEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
"endpoints": [
{
"lbEndpoints": [
{
"endpoint": {
"address": {
"socketAddress": {
"address": "api.mydomain",
"portValue": 8081
}
}
},
"healthStatus": "UNHEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
Expand Down
12 changes: 0 additions & 12 deletions agent/xds/testdata/clusters/terminating-gateway.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
"endpoints": [
{
"lbEndpoints": [
{
"endpoint": {
"address": {
"socketAddress": {
"address": "api.mydomain",
"portValue": 8081
}
}
},
"healthStatus": "UNHEALTHY",
"loadBalancingWeight": 1
},
{
"endpoint": {
"address": {
Expand Down