From 826ea6e522c9e3ceca76729c45ef69f1e784a61a Mon Sep 17 00:00:00 2001 From: Chuck Ha Date: Fri, 23 Mar 2018 15:16:22 -0700 Subject: [PATCH] Use config defaults with a custom config Start with sensible defaults instead of zero values. If a config is passed in it will merge into the default config instead of a zero-value config. Fixes #390 Signed-off-by: Chuck Ha --- pkg/client/gen.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/client/gen.go b/pkg/client/gen.go index 572d9fc7c..490ed2d0e 100644 --- a/pkg/client/gen.go +++ b/pkg/client/gen.go @@ -21,9 +21,12 @@ import ( "encoding/json" "strings" + "github.com/imdario/mergo" + "github.com/pkg/errors" "github.com/heptio/sonobuoy/pkg/buildinfo" + "github.com/heptio/sonobuoy/pkg/config" "github.com/heptio/sonobuoy/pkg/templates" ) @@ -43,18 +46,8 @@ type templateValues struct { // GenerateManifest fills in a template with a Sonobuoy config func (c *SonobuoyClient) GenerateManifest(cfg *GenConfig) ([]byte, error) { - if cfg.Image != "" { - cfg.Config.WorkerImage = cfg.Image - } - - if cfg.ImagePullPolicy != "" { - cfg.Config.ImagePullPolicy = cfg.ImagePullPolicy - } - - if cfg.Namespace != "" { - cfg.Config.Namespace = cfg.Namespace - } - + // Set defaults for the config.Config and overwrite fields with the passed in config. + mergo.MergeWithOverwrite(cfg.Config, config.New()) marshalledConfig, err := json.Marshal(cfg.Config) if err != nil { return nil, errors.Wrap(err, "couldn't marshall selector")