Skip to content

Commit a3c7d2f

Browse files
authored
agent: reload Enterprise configuration (#849)
When the Nomad agent configuration is reloaded the Enterprise license checker must also be updated in case the Nomad token used to make API calls changes.
1 parent bca860e commit a3c7d2f

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ IMPROVEMENTS:
55

66
BUG FIXES:
77
* agent: Fixed a bug that caused a target in dry-run mode to scale when outside of its min/max range [[GH-845](https://github.com/hashicorp/nomad-autoscaler/pull/845)]
8+
* agent: Fixed a bug that caused the Enterprise license checker to not be reloaded on `SIGHUP` [[GH-849](https://github.com/hashicorp/nomad-autoscaler/pull/849)]
89

910
## 0.4.1 (January 18, 2024)
1011

GNUmakefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GIT_COMMIT := $(shell git rev-parse --short HEAD)
55
GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
66

77
GO_LDFLAGS := "$(GO_LDFLAGS) -X github.com/hashicorp/nomad-autoscaler/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"
8+
GO_TAGS := ""
89

910
# Attempt to use gotestsum for running tests, otherwise fallback to go test.
1011
GO_TEST_CMD = $(if $(shell command -v gotestsum 2>/dev/null),gotestsum --,go test)
@@ -67,8 +68,9 @@ pkg/%.zip: pkg/%/nomad-autoscaler ## Build and zip Nomad Autoscaler for GOOS_GOA
6768
.PHONY: dev
6869
dev: lint ## Build for the current development version
6970
@echo "==> Building autoscaler..."
70-
@CGO_ENABLED=0 go build \
71+
@CGO_ENABLED=0 GOPROXY=direct go build \
7172
-ldflags $(GO_LDFLAGS) \
73+
-tags "$(GO_TAGS)" \
7274
-o ./bin/nomad-autoscaler
7375
@rm -f $(BIN)/nomad-autoscaler && cp ./bin/nomad-autoscaler $(BIN)/
7476
@echo "==> Done"
@@ -82,7 +84,8 @@ proto: ## Generate the protocol buffers
8284
.PHONY: lint
8385
lint: lint-tools generate-tools hclfmt ## Lint the source code
8486
@echo "==> Linting source code..."
85-
@golangci-lint run -j 1
87+
@GOPROXY=direct \
88+
golangci-lint run -j 1 --build-tags "$(GO_TAGS)"
8689
@staticcheck ./...
8790
@hclogvet .
8891
@buf lint --config=./tools/buf/buf.yaml
@@ -129,7 +132,8 @@ check-protobuf: ## Checks the protobuf files are in-sync
129132
test: ## Test the source code
130133
@$(MAKE) -C plugins/test
131134
@echo "==> Testing source code..."
132-
@$(GO_TEST_CMD) -v -race -cover ./...
135+
@GOPROXY=direct \
136+
$(GO_TEST_CMD) -v -race -cover ./... -tags "$(GO_TAGS)"
133137
@echo "==> Done"
134138

135139
.PHONY: clean-plugins

agent/agent.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type Agent struct {
3939
// setting up all clients. It is the result of the Nomad api.DefaultConfig
4040
// merged with the user-specified Nomad config.Nomad.
4141
nomadCfg *api.Config
42+
43+
// entReload is used to notify the Enterprise license watcher to reload its
44+
// configuration.
45+
entReload chan any
4246
}
4347

4448
func NewAgent(c *config.Agent, configPaths []string, logger hclog.Logger) *Agent {
@@ -47,6 +51,7 @@ func NewAgent(c *config.Agent, configPaths []string, logger hclog.Logger) *Agent
4751
config: c,
4852
configPaths: configPaths,
4953
nomadCfg: nomadHelper.MergeDefaultWithAgentConfig(c.Nomad),
54+
entReload: make(chan any),
5055
}
5156
}
5257

@@ -83,7 +88,7 @@ func (a *Agent) Run(ctx context.Context) error {
8388
a.config.PolicyEval.DeliveryLimit)
8489
a.initWorkers(ctx)
8590

86-
a.initEnt(ctx)
91+
a.initEnt(ctx, a.entReload)
8792

8893
// Launch the eval handler.
8994
go a.runEvalHandler(ctx, policyEvalCh)
@@ -210,6 +215,8 @@ func (a *Agent) reload() {
210215
os.Exit(1)
211216
}
212217

218+
a.entReload <- struct{}{}
219+
213220
a.logger.Debug("reloading policy sources")
214221
// Set new Nomad client in the Nomad policy source.
215222
ps, ok := a.policySources[policy.SourceNameNomad]

agent/agent_oss.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ package agent
88

99
import "context"
1010

11-
func (a *Agent) initEnt(_ context.Context) {}
11+
func (a *Agent) initEnt(ctx context.Context, reload <-chan any) {
12+
go func() {
13+
for {
14+
select {
15+
case <-ctx.Done():
16+
return
17+
case <-reload:
18+
continue
19+
}
20+
}
21+
}()
22+
}

0 commit comments

Comments
 (0)