fix(pkg/lint): unmarshals Chart.yaml strictly

When "helm lint" is run, it now errors on invalid chartfiles,
e.g. those with duplicate keys

Closes #12381

Signed-off-by: Edward Miller <edmiller287@gmail.com>
pull/12382/head
Edward Miller 2 years ago committed by edbmiller
parent 7571f77163
commit 00f8561ad4

@ -33,7 +33,7 @@ func LoadChartfile(filename string) (*chart.Metadata, error) {
return nil, err return nil, err
} }
y := new(chart.Metadata) y := new(chart.Metadata)
err = yaml.Unmarshal(b, y) err = yaml.UnmarshalStrict(b, y)
return y, err return y, err
} }

@ -35,6 +35,7 @@ const badYamlFileDir = "rules/testdata/albatross"
const goodChartDir = "rules/testdata/goodone" const goodChartDir = "rules/testdata/goodone"
const subChartValuesDir = "rules/testdata/withsubchart" const subChartValuesDir = "rules/testdata/withsubchart"
const malformedTemplate = "rules/testdata/malformed-template" const malformedTemplate = "rules/testdata/malformed-template"
const invalidChartFileDir = "rules/testdata/invalidchartfile"
func TestBadChart(t *testing.T) { func TestBadChart(t *testing.T) {
m := RunAll(badChartDir, values, namespace).Messages m := RunAll(badChartDir, values, namespace).Messages
@ -90,6 +91,16 @@ func TestInvalidYaml(t *testing.T) {
} }
} }
func TestInvalidChartYaml(t *testing.T) {
m := All(invalidChartFileDir, values, namespace, strict).Messages
if len(m) != 1 {
t.Fatalf("All didn't fail with expected errors, got %#v", m)
}
if !strings.Contains(m[0].Err.Error(), "unable to parse YAML") {
t.Errorf("All didn't have the error for duplicate YAML keys")
}
}
func TestBadValues(t *testing.T) { func TestBadValues(t *testing.T) {
m := RunAll(badValuesFileDir, values, namespace).Messages m := RunAll(badValuesFileDir, values, namespace).Messages
if len(m) < 1 { if len(m) < 1 {

@ -0,0 +1,5 @@
name: some-chart
apiVersion: v2
apiVersion: v1
description: A Helm chart for Kubernetes
version: 1.3.0
Loading…
Cancel
Save