From bfc501a0bf742abd2c772ce2a2771cd6368cee14 Mon Sep 17 00:00:00 2001 From: Michael Zalimeni Date: Wed, 9 Aug 2023 16:20:19 -0400 Subject: [PATCH] Apply K8s node locality to services and sidecars Locality-aware routing is based on proxy locality rather than the proxied service. Ensure we propagate locality to both when registering services. --- .changelog/2748.txt | 3 +++ .../controllers/endpoints/endpoints_controller.go | 2 ++ .../controllers/endpoints/endpoints_controller_test.go | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 .changelog/2748.txt diff --git a/.changelog/2748.txt b/.changelog/2748.txt new file mode 100644 index 0000000000..2a8c922d13 --- /dev/null +++ b/.changelog/2748.txt @@ -0,0 +1,3 @@ +```release-note:bug +control-plane: Set locality on sidecar proxies in addition to services when registering with connect-inject. +``` diff --git a/control-plane/connect-inject/controllers/endpoints/endpoints_controller.go b/control-plane/connect-inject/controllers/endpoints/endpoints_controller.go index cdf56b187f..3f139c2662 100644 --- a/control-plane/connect-inject/controllers/endpoints/endpoints_controller.go +++ b/control-plane/connect-inject/controllers/endpoints/endpoints_controller.go @@ -535,6 +535,8 @@ func (r *Controller) createServiceRegistrations(pod corev1.Pod, serviceEndpoints Namespace: consulNS, Proxy: proxyConfig, Tags: tags, + // Sidecar locality (not proxied service locality) is used for locality-aware routing. + Locality: locality, } // A user can enable/disable tproxy for an entire namespace. diff --git a/control-plane/connect-inject/controllers/endpoints/endpoints_controller_test.go b/control-plane/connect-inject/controllers/endpoints/endpoints_controller_test.go index 477be49e9f..2cec69dd0a 100644 --- a/control-plane/connect-inject/controllers/endpoints/endpoints_controller_test.go +++ b/control-plane/connect-inject/controllers/endpoints/endpoints_controller_test.go @@ -2021,6 +2021,10 @@ func TestReconcileCreateEndpoint(t *testing.T) { "envoy_telemetry_collector_bind_socket_dir": "/consul/connect-inject", }, }, + ServiceLocality: &api.Locality{ + Region: "us-west-1", + Zone: "us-west-1a", + }, ServiceMeta: map[string]string{ "name": "abc", "version": "2", @@ -2225,6 +2229,7 @@ func TestReconcileCreateEndpoint(t *testing.T) { require.Equal(t, tt.expectedProxySvcInstances[i].ServicePort, instance.ServicePort) require.Equal(t, tt.expectedProxySvcInstances[i].ServiceMeta, instance.ServiceMeta) require.Equal(t, tt.expectedProxySvcInstances[i].ServiceTags, instance.ServiceTags) + require.Equal(t, tt.expectedProxySvcInstances[i].ServiceLocality, instance.ServiceLocality) if tt.nodeMeta != nil { require.Equal(t, tt.expectedProxySvcInstances[i].NodeMeta, instance.NodeMeta) }