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 }