Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: fix Consul version fingerprint #17349

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17349.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: fixed a bug that prevented Nomad from fingerprinting Consul 1.13.8 correctly
```
3 changes: 2 additions & 1 deletion client/fingerprint/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 17 additions & 0 deletions client/fingerprint/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -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": {},
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down