Skip to content

Commit

Permalink
Update agent tags on config reload (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvanoers authored Jun 14, 2021
1 parent 5008f7a commit 6c18bc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit 6c18bc5

Please sign in to comment.