Skip to content

Commit

Permalink
Bugfix for annotations & labels flags (#2881)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Plourde <simon@sensu.io>
  • Loading branch information
palourde committed Apr 17, 2019
1 parent fcd566c commit 0801c1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Versioning](http://semver.org/spec/v2.0.0.html).

## [5.6.0] - TBD

### Fixed
- Fixed the agent `--annotations` and `--labels` flags.

## [5.5.1] - 2019-04-15

### Changed
Expand Down
17 changes: 15 additions & 2 deletions agent/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (

var (
logger *logrus.Entry

annotations map[string]string
labels map[string]string
)

const (
Expand Down Expand Up @@ -164,6 +167,16 @@ func newStartCommand() *cobra.Command {
cfg.Redact = viper.GetStringSlice(flagRedact)
cfg.Subscriptions = viper.GetStringSlice(flagSubscriptions)

// Workaround for https://github.com/sensu/sensu-go/issues/2357. Detect if
// the flags for labels and annotations were changed. If so, use their
// values since flags take precedence over config
if flag := cmd.Flags().Lookup(flagLabels); flag != nil && flag.Changed {
cfg.Labels = labels
}
if flag := cmd.Flags().Lookup(flagAnnotations); flag != nil && flag.Changed {
cfg.Annotations = annotations
}

sensuAgent, err := agent.NewAgent(cfg)
if err != nil {
return err
Expand Down Expand Up @@ -279,8 +292,8 @@ func newStartCommand() *cobra.Command {
cmd.Flags().String(flagTrustedCAFile, viper.GetString(flagTrustedCAFile), "TLS CA certificate bundle in PEM format")
cmd.Flags().Bool(flagInsecureSkipTLSVerify, viper.GetBool(flagInsecureSkipTLSVerify), "skip TLS verification (not recommended!)")
cmd.Flags().String(flagLogLevel, viper.GetString(flagLogLevel), "logging level [panic, fatal, error, warn, info, debug]")
cmd.Flags().StringToString(flagLabels, viper.GetStringMapString(flagLabels), "entity labels map")
cmd.Flags().StringToString(flagAnnotations, viper.GetStringMapString(flagAnnotations), "entity annotations map")
cmd.Flags().StringToStringVar(&labels, flagLabels, nil, "entity labels map")
cmd.Flags().StringToStringVar(&annotations, flagAnnotations, nil, "entity annotations map")

cmd.Flags().SetNormalizeFunc(aliasNormalizeFunc)

Expand Down

0 comments on commit 0801c1d

Please sign in to comment.