diff --git a/command/agent/consul/service_client.go b/command/agent/consul/service_client.go index 2934e24eeb0..3a22848f098 100644 --- a/command/agent/consul/service_client.go +++ b/command/agent/consul/service_client.go @@ -1704,7 +1704,7 @@ func maybeConnectSidecar(id string) bool { } var ( - sidecarProxyCheckRe = regexp.MustCompile(`service:_nomad-.+-sidecar-proxy(:[\d]+)?`) + sidecarProxyCheckRe = regexp.MustCompile(`^service:_nomad-.+-sidecar-proxy(:[\d]+)?$`) ) // maybeSidecarProxyCheck returns true if the ID likely matches a Nomad generated diff --git a/command/agent/consul/service_client_test.go b/command/agent/consul/service_client_test.go index 30ef7559291..9cacaa38ddc 100644 --- a/command/agent/consul/service_client_test.go +++ b/command/agent/consul/service_client_test.go @@ -636,5 +636,7 @@ func TestSyncLogic_maybeSidecarProxyCheck(t *testing.T) { try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy:2", true) try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001", false) try("_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy:1", false) + try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy:X", false) + try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy: ", false) try("service", false) }