Account for partitions in xds gen for mesh gw

This commit avoids skipping gateways in remote partitions of the local
DC when generating listeners/clusters/endpoints.
This commit is contained in:
freddygv 2021-10-24 09:51:55 -06:00
parent 935112a47a
commit a33b6923e0
4 changed files with 12 additions and 5 deletions

View File

@ -71,6 +71,10 @@ func (k GatewayKey) IsEmpty() bool {
return k.Partition == "" && k.Datacenter == ""
}
func (k GatewayKey) Matches(dc, partition string) bool {
return k.Partition == partition && k.Datacenter == dc
}
func gatewayKeyFromString(s string) GatewayKey {
split := strings.SplitN(s, ".", 2)

View File

@ -209,7 +209,7 @@ func (s *ResourceGenerator) clustersFromSnapshotMeshGateway(cfgSnap *proxycfg.Co
// generate the remote dc clusters
for _, key := range keys {
if key.Datacenter == cfgSnap.Datacenter {
if key.Matches(cfgSnap.Datacenter, cfgSnap.ProxyID.PartitionOrEmpty()) {
continue // skip local
}

View File

@ -114,9 +114,11 @@ func (s *ResourceGenerator) endpointsFromSnapshotMeshGateway(cfgSnap *proxycfg.C
// generate the endpoints for the gateways in the remote datacenters
for _, key := range keys {
// Skip creating endpoints for mesh gateways in local DC and gateways in remote DCs with a hostname as their address
// EDS cannot resolve hostnames so we provide them through CDS instead
if key.Datacenter == cfgSnap.Datacenter || len(cfgSnap.MeshGateway.HostnameDatacenters[key.String()]) > 0 {
// Skip creating endpoints for mesh gateways in local DC/partition and gateways.
// Also skip gateways with a hostname as their address.
// EDS cannot resolve hostnames, so we provide them through CDS instead.
if key.Matches(cfgSnap.Datacenter, cfgSnap.ProxyID.PartitionOrEmpty()) ||
len(cfgSnap.MeshGateway.HostnameDatacenters[key.String()]) > 0 {
continue
}

View File

@ -1139,9 +1139,10 @@ func (s *ResourceGenerator) makeMeshGatewayListener(name, addr string, port int,
// We need 1 Filter Chain per datacenter
keys := cfgSnap.MeshGateway.Keys()
for _, key := range keys {
if key.Datacenter == cfgSnap.Datacenter {
if key.Matches(cfgSnap.Datacenter, cfgSnap.ProxyID.PartitionOrEmpty()) {
continue // skip local
}
clusterName := connect.GatewaySNI(key.Datacenter, key.Partition, cfgSnap.Roots.TrustDomain)
filterName := fmt.Sprintf("%s.%s", name, key.String())
dcTCPProxy, err := makeTCPProxyFilter(filterName, clusterName, "mesh_gateway_remote.")