Skip to content

Commit

Permalink
config: use URL method to get Nomad address for plugins (#966)
Browse files Browse the repository at this point in the history
For #944 we fixed the Nomad API package so that it no longer mutated the private
`url` field if previously set, which allowed reusing an `api.Config` object
between clients when a unix domain socket was in use.

However, the autoscaler plugins for Nomad strategy and target don't use the
`api.Config` object we parse directly and instead get a map of string->string
derived from that config so it can be passed over the go-plugin interface. This
mapping did not account for the `Address` field being mutated when unix domain
sockets are in use, so the bug was not actually fixed.

Update the mapping to use the safe `URL()` method on the config, rather than
reading the `Address` field.

Fixes: #955
Ref: hashicorp/nomad#23785
  • Loading branch information
tgross authored Sep 11, 2024
1 parent b7ded59 commit 180f107
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## UNRELEASED

BUG FIXES:
* config: Fixed a bug where the Nomad strategy and target plugins would fail to connect to Nomad's Task API socket [[GH-966](https://github.com/hashicorp/nomad-autoscaler/pull/966)]

## 0.4.5 (August 13, 2024)

IMPROVEMENTS:
Expand Down
6 changes: 5 additions & 1 deletion sdk/helper/nomad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ func MergeMapWithAgentConfig(m map[string]string, cfg *api.Config) {
}

if cfg.Address != "" && m[configKeyNomadAddress] == "" {
m[configKeyNomadAddress] = cfg.Address
if cfg.URL() != nil {
m[configKeyNomadAddress] = cfg.URL().String()
} else {
m[configKeyNomadAddress] = cfg.Address
}
}
if cfg.Region != "" && m[configKeyNomadRegion] == "" {
m[configKeyNomadRegion] = cfg.Region
Expand Down

0 comments on commit 180f107

Please sign in to comment.