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

Update agent tags on config reload #983

Merged
merged 1 commit into from
Jun 14, 2021
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
1 change: 1 addition & 0 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func handleReload() {
fmt.Println("Reloading configuration...")
initConfig()
//Config reloading will also reload Notification settings
agent.UpdateTags(config.Tags)
}

// UnmarshalTags is a utility function which takes a slice of strings in
Expand Down
19 changes: 19 additions & 0 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,25 @@ func (a *Agent) Stop() error {
return nil
}

// UpdateTags updates the tag configuration for this agent
func (a *Agent) UpdateTags(tags map[string]string) {
// Preserve reserved tags
currentTags := a.serf.LocalMember().Tags
for _, tagName := range []string{"role", "version", "server", "bootstrap", "expect", "port", "rpc_addr"} {
if val, exists := currentTags[tagName]; exists {
tags[tagName] = val
}
}
tags["dc"] = a.config.Datacenter
tags["region"] = a.config.Region

// Set new collection of tags
err := a.serf.SetTags(tags)
if err != nil {
a.logger.Warnf("Setting tags unsuccessful: %s.", err.Error())
}
}

func (a *Agent) setupRaft() error {
if a.config.BootstrapExpect > 0 {
if a.config.BootstrapExpect == 1 {
Expand Down