ref(helm): consolidate vars() function

pull/2592/head
Patrick Mahoney 8 years ago
parent a3d44f4f02
commit 9e62777a56

@ -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)
}

@ -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, &currentMap); 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)
}

Loading…
Cancel
Save