diff --git a/cmd/helm/install.go b/cmd/helm/install.go index b9eb3b28a..3598e7234 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -204,7 +204,7 @@ func (i *installCmd) run() error { i.namespace = defaultNamespace() } - rawVals, err := i.vals() + rawVals, err := vals(i.valueFiles, i.values) if err != nil { return err } @@ -300,11 +300,13 @@ func mergeValues(dest map[string]interface{}, src map[string]interface{}) map[st return dest } -func (i *installCmd) vals() ([]byte, error) { +// vals merges values from files specified via -f/--values and +// directly via --set, marshaling them to YAML +func vals(valueFiles valueFiles, values []string) ([]byte, error) { base := map[string]interface{}{} // User specified a values files via -f/--values - for _, filePath := range i.valueFiles { + for _, filePath := range valueFiles { currentMap := map[string]interface{}{} bytes, err := ioutil.ReadFile(filePath) if err != nil { @@ -319,7 +321,7 @@ func (i *installCmd) vals() ([]byte, error) { } // User specified a value via --set - for _, value := range i.values { + for _, value := range values { if err := strvals.ParseInto(value, base); err != nil { return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) } diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index c27581c57..90210ca7f 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -19,16 +19,13 @@ package main import ( "fmt" "io" - "io/ioutil" "strings" - "github.com/ghodss/yaml" "github.com/spf13/cobra" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/storage/driver" - "k8s.io/helm/pkg/strvals" ) const upgradeDesc = ` @@ -174,7 +171,7 @@ func (u *upgradeCmd) run() error { } } - rawVals, err := u.vals() + rawVals, err := vals(u.valueFiles, u.values) if err != nil { return err } @@ -218,31 +215,3 @@ func (u *upgradeCmd) run() error { return nil } - -func (u *upgradeCmd) vals() ([]byte, error) { - base := map[string]interface{}{} - - // User specified a values files via -f/--values - for _, filePath := range u.valueFiles { - currentMap := map[string]interface{}{} - bytes, err := ioutil.ReadFile(filePath) - if err != nil { - return []byte{}, err - } - - if err := yaml.Unmarshal(bytes, ¤tMap); err != nil { - return []byte{}, fmt.Errorf("failed to parse %s: %s", filePath, err) - } - // Merge with the previous map - base = mergeValues(base, currentMap) - } - - // User specified a value via --set - for _, value := range u.values { - if err := strvals.ParseInto(value, base); err != nil { - return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) - } - } - - return yaml.Marshal(base) -}