diff --git a/cmd/agent.go b/cmd/agent.go index d2e2792de..df9f6331a 100644 --- a/cmd/agent.go +++ b/cmd/agent.go @@ -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 diff --git a/dkron/agent.go b/dkron/agent.go index bba1b33b0..771a23b82 100644 --- a/dkron/agent.go +++ b/dkron/agent.go @@ -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 {