Added autodetection of YAML/JSON values

pull/3227/head
Withnale 8 years ago
parent 16571305bb
commit d70c268840

@ -32,6 +32,8 @@ import (
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
api_yaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/downloader"
"k8s.io/helm/pkg/getter"
@ -330,19 +332,20 @@ func vals(valueFiles valueFiles, values []string) ([]byte, error) {
for _, filePath := range valueFiles {
currentMap := map[string]interface{}{}
var bytes []byte
var readBytes []byte
var err error
if strings.TrimSpace(filePath) == "-" {
bytes, err = ioutil.ReadAll(os.Stdin)
readBytes, err = ioutil.ReadAll(os.Stdin)
} else {
bytes, err = readFile(filePath)
readBytes, err = readFile(filePath)
}
if err != nil {
return []byte{}, err
}
if err := yaml.Unmarshal(bytes, &currentMap); err != nil {
d := api_yaml.NewYAMLOrJSONDecoder(bytes.NewReader(readBytes), 4096)
if err := d.Decode(&currentMap); err != nil {
return []byte{}, fmt.Errorf("failed to parse %s: %s", filePath, err)
}
// Merge with the previous map

@ -97,6 +97,13 @@ func TestTemplateCmd(t *testing.T) {
expectKey: "subchart1/templates/service.yaml",
expectValue: "name: apache",
},
{
name: "check_values_files_json",
desc: "verify --values files values exist",
args: []string{chartPath, "--values", chartPath + "/charts/subchartA/values.json"},
expectKey: "subchart1/templates/service.yaml",
expectValue: "name: apache",
},
{
name: "check_name_template",
desc: "verify --name-template result exists",

@ -0,0 +1,17 @@
{
"service": {
"name": "apache",
"type": "ClusterIP",
"externalPort": 80,
"internalPort": 80
},
"SCAdata": {
"SCAbool": false,
"SCAfloat": 3.1,
"SCAint": 55,
"SCAstring": "jabba",
"SCAnested1": {
"SCAnested2": true
}
}
}
Loading…
Cancel
Save