From bb2395031b290b4bc6e0ca9f2e4c56c9a817dc98 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Tue, 30 May 2023 11:07:57 -0400 Subject: [PATCH] client: fix Consul version finterprint (#17349) Consul v1.13.8 was released with a breaking change in the /v1/agent/self endpoint version where a line break was being returned. This caused the Nomad finterprint to fail because `NewVersion` errors on parse. This commit removes any extra space from the Consul version returned by the API. --- .changelog/17349.txt | 3 +++ client/fingerprint/consul.go | 3 ++- client/fingerprint/consul_test.go | 17 +++++++++++++++++ command/agent/consul/self.go | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .changelog/17349.txt diff --git a/.changelog/17349.txt b/.changelog/17349.txt new file mode 100644 index 000000000..03d70b6a9 --- /dev/null +++ b/.changelog/17349.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: fixed a bug that prevented Nomad from fingerprinting Consul 1.13.8 correctly +``` diff --git a/client/fingerprint/consul.go b/client/fingerprint/consul.go index 45ea6f94e..b68285ec2 100644 --- a/client/fingerprint/consul.go +++ b/client/fingerprint/consul.go @@ -197,8 +197,9 @@ func (f *ConsulFingerprint) grpc(scheme string) func(info agentconsul.Self) (str return "", false } - consulVersion, err := version.NewVersion(v) + consulVersion, err := version.NewVersion(strings.TrimSpace(v)) if err != nil { + f.logger.Warn("invalid Consul version", "version", v) return "", false } diff --git a/client/fingerprint/consul_test.go b/client/fingerprint/consul_test.go index 2555c4a8b..c40840cf6 100644 --- a/client/fingerprint/consul_test.go +++ b/client/fingerprint/consul_test.go @@ -159,6 +159,14 @@ func TestConsulFingerprint_sku(t *testing.T) { require.Equal(t, "ent", s) }) + t.Run("extra spaces", func(t *testing.T) { + v, ok := fp.sku(agentconsul.Self{ + "Config": {"Version": " v1.9.5\n"}, + }) + require.True(t, ok) + require.Equal(t, "oss", v) + }) + t.Run("missing", func(t *testing.T) { _, ok := fp.sku(agentconsul.Self{ "Config": {}, @@ -371,6 +379,15 @@ func TestConsulFingerprint_grpc(t *testing.T) { require.Equal(t, "8503", s) }) + t.Run("version with extra spaces", func(t *testing.T) { + s, ok := fp.grpc("https")(agentconsul.Self{ + "Config": {"Version": " 1.14.0\n"}, + "DebugConfig": {"GRPCTLSPort": 8503.0}, // JSON numbers are floats + }) + require.True(t, ok) + require.Equal(t, "8503", s) + }) + t.Run("grpc missing http", func(t *testing.T) { _, ok := fp.grpc("http")(agentconsul.Self{ "DebugConfig": {}, diff --git a/command/agent/consul/self.go b/command/agent/consul/self.go index c7892b5dd..540b68636 100644 --- a/command/agent/consul/self.go +++ b/command/agent/consul/self.go @@ -20,7 +20,7 @@ func SKU(info Self) (string, bool) { return "", ok } - ver, vErr := version.NewVersion(v) + ver, vErr := version.NewVersion(strings.TrimSpace(v)) if vErr != nil { return "", false }