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

Bugfix for annotations & labels flags #2881

Merged
merged 2 commits into from
Apr 17, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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