Browse Source

Update listener generation to account for consul VIP

pull/11738/head
freddygv 3 years ago
parent
commit
e7a7042c69
  1. 17
      agent/xds/listeners.go
  2. 3
      agent/xds/listeners_test.go
  3. 4
      agent/xds/testdata/listeners/transparent-proxy.envoy-1-20-x.golden

17
agent/xds/listeners.go

@ -168,13 +168,22 @@ func (s *ResourceGenerator) listenersFromSnapshotConnectProxy(cfgSnap *proxycfg.
// We do not match on all endpoints here since it would lead to load balancing across // We do not match on all endpoints here since it would lead to load balancing across
// all instances when any instance address is dialed. // all instances when any instance address is dialed.
for _, e := range endpoints { for _, e := range endpoints {
if vip := e.Service.TaggedAddresses[virtualIPTag]; vip.Address != "" { if vip := e.Service.TaggedAddresses[structs.TaggedAddressVirtualIP]; vip.Address != "" {
uniqueAddrs[vip.Address] = struct{}{} uniqueAddrs[vip.Address] = struct{}{}
} }
// The virtualIPTag is used by consul-k8s to store the ClusterIP for a service.
// We only match on this virtual IP if the upstream is in the proxy's partition.
// This is because the IP is not guaranteed to be unique across k8s clusters.
if structs.EqualPartitions(e.Node.PartitionOrDefault(), cfgSnap.ProxyID.PartitionOrDefault()) {
if vip := e.Service.TaggedAddresses[virtualIPTag]; vip.Address != "" {
uniqueAddrs[vip.Address] = struct{}{}
}
}
} }
if len(uniqueAddrs) > 1 { if len(uniqueAddrs) > 2 {
s.Logger.Warn("detected multiple virtual IPs for an upstream, all will be used to match traffic", s.Logger.Debug("detected multiple virtual IPs for an upstream, all will be used to match traffic",
"upstream", id) "upstream", id, "ip_count", len(uniqueAddrs))
} }
// For every potential address we collected, create the appropriate address prefix to match on. // For every potential address we collected, create the appropriate address prefix to match on.

3
agent/xds/listeners_test.go

@ -863,7 +863,8 @@ func TestListenersFromSnapshot(t *testing.T) {
Address: "9.9.9.9", Address: "9.9.9.9",
Port: 9090, Port: 9090,
TaggedAddresses: map[string]structs.ServiceAddress{ TaggedAddresses: map[string]structs.ServiceAddress{
"virtual": {Address: "10.0.0.1"}, "virtual": {Address: "10.0.0.1"},
structs.TaggedAddressVirtualIP: {Address: "240.0.0.1"},
}, },
}, },
}, },

4
agent/xds/testdata/listeners/transparent-proxy.envoy-1-20-x.golden vendored

@ -42,6 +42,10 @@
{ {
"addressPrefix": "10.0.0.1", "addressPrefix": "10.0.0.1",
"prefixLen": 32 "prefixLen": 32
},
{
"addressPrefix": "240.0.0.1",
"prefixLen": 32
} }
] ]
}, },

Loading…
Cancel
Save