Commit f0af7d60 authored by Matt Butcher's avatar Matt Butcher Committed by GitHub

Merge pull request #2592 from raisemarketplace/compare

ref(helm): consolidate vars() function
parents 6931a238 9e62777a
...@@ -204,7 +204,7 @@ func (i *installCmd) run() error { ...@@ -204,7 +204,7 @@ func (i *installCmd) run() error {
i.namespace = defaultNamespace() i.namespace = defaultNamespace()
} }
rawVals, err := i.vals() rawVals, err := vals(i.valueFiles, i.values)
if err != nil { if err != nil {
return err return err
} }
...@@ -302,11 +302,13 @@ func mergeValues(dest map[string]interface{}, src map[string]interface{}) map[st ...@@ -302,11 +302,13 @@ func mergeValues(dest map[string]interface{}, src map[string]interface{}) map[st
return dest 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{}{} base := map[string]interface{}{}
// User specified a values files via -f/--values // User specified a values files via -f/--values
for _, filePath := range i.valueFiles { for _, filePath := range valueFiles {
currentMap := map[string]interface{}{} currentMap := map[string]interface{}{}
bytes, err := ioutil.ReadFile(filePath) bytes, err := ioutil.ReadFile(filePath)
if err != nil { if err != nil {
...@@ -321,7 +323,7 @@ func (i *installCmd) vals() ([]byte, error) { ...@@ -321,7 +323,7 @@ func (i *installCmd) vals() ([]byte, error) {
} }
// User specified a value via --set // User specified a value via --set
for _, value := range i.values { for _, value := range values {
if err := strvals.ParseInto(value, base); err != nil { if err := strvals.ParseInto(value, base); err != nil {
return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) return []byte{}, fmt.Errorf("failed parsing --set data: %s", err)
} }
......
...@@ -19,16 +19,13 @@ package main ...@@ -19,16 +19,13 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"strings" "strings"
"github.com/ghodss/yaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/storage/driver" "k8s.io/helm/pkg/storage/driver"
"k8s.io/helm/pkg/strvals"
) )
const upgradeDesc = ` const upgradeDesc = `
...@@ -176,7 +173,7 @@ func (u *upgradeCmd) run() error { ...@@ -176,7 +173,7 @@ func (u *upgradeCmd) run() error {
} }
} }
rawVals, err := u.vals() rawVals, err := vals(u.valueFiles, u.values)
if err != nil { if err != nil {
return err return err
} }
...@@ -225,31 +222,3 @@ func (u *upgradeCmd) run() error { ...@@ -225,31 +222,3 @@ func (u *upgradeCmd) run() error {
return nil 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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment