Skip to content

Commit

Permalink
persist managed_by label to cfg, update tests (#4179)
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kolberg <[email protected]>
  • Loading branch information
amdprophet authored Jan 20, 2021
1 parent 6fcded8 commit 5d37ea1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions agent/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func NewAgentConfig(cmd *cobra.Command) (*agent.Config, error) {

// Add the ManagedByLabel label value if the agent is managed by its entity
if viper.GetBool(flagAgentManagedEntity) {
if len(labels) == 0 {
labels = make(map[string]string)
if len(cfg.Labels) == 0 {
cfg.Labels = make(map[string]string)
}
labels[corev2.ManagedByLabel] = "sensu-agent"
cfg.Labels[corev2.ManagedByLabel] = "sensu-agent"
}

return cfg, nil
Expand Down
6 changes: 3 additions & 3 deletions agent/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func TestNewAgentConfig_AgentManagedEntityFlag(t *testing.T) {
}
_ = cmd.Flags().Set(flagAgentManagedEntity, "true")

_, err := NewAgentConfig(cmd)
cfg, err := NewAgentConfig(cmd)
if err != nil {
t.Fatal("unexpected error while calling handleConfig: ", err)
}

if !reflect.DeepEqual(labels, map[string]string{corev2.ManagedByLabel: "sensu-agent"}) {
t.Fatalf("TestNewAgentConfigFlags() labels = %v, want %v", labels, map[string]string{corev2.ManagedByLabel: "sensu-agent"})
if !reflect.DeepEqual(cfg.Labels, map[string]string{corev2.ManagedByLabel: "sensu-agent"}) {
t.Fatalf("TestNewAgentConfigFlags() labels = %v, want %v", cfg.Labels, map[string]string{corev2.ManagedByLabel: "sensu-agent"})
}
}

Expand Down

0 comments on commit 5d37ea1

Please sign in to comment.