Skip to content

Commit

Permalink
client: fix Consul version finterprint (#17349)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lgfa29 committed May 30, 2023
1 parent 60e0404 commit 4068b68
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
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

0 comments on commit 4068b68

Please sign in to comment.