Skip to content

Commit

Permalink
Use config defaults with a custom config
Browse files Browse the repository at this point in the history
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 vmware-tanzu#390

Signed-off-by: Chuck Ha <chuck@heptio.com>
  • Loading branch information
Chuck Ha committed Mar 24, 2018
1 parent b999222 commit 826ea6e
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pkg/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
Expand Down

0 comments on commit 826ea6e

Please sign in to comment.