Add chartutil.StrictLoadChartfile for strict (WARNING-level) lint

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

@ -28,6 +28,17 @@ import (
// LoadChartfile loads a Chart.yaml file into a *chart.Metadata.
func LoadChartfile(filename string) (*chart.Metadata, error) {
b, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
y := new(chart.Metadata)
err = yaml.Unmarshal(b, y)
return y, err
}
// StrictLoadChartFile loads a Chart.yaml into a *chart.Metadata using a strict unmarshaling
func StrictLoadChartfile(filename string) (*chart.Metadata, error) {
b, err := os.ReadFile(filename)
if err != nil {
return nil, err

@ -96,7 +96,7 @@ func TestInvalidChartYaml(t *testing.T) {
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") {
if !strings.Contains(m[0].Err.Error(), "failed to strictly parse chartfile") {
t.Errorf("All didn't have the error for duplicate YAML keys")
}
}

@ -46,6 +46,9 @@ func Chartfile(linter *support.Linter) {
return
}
_, err = chartutil.StrictLoadChartfile(chartPath)
linter.RunLinterRule(support.WarningSev, chartFileName, validateChartYamlStrictFormat(err))
// type check for Chart.yaml . ignoring error as any parse
// errors would already be caught in the above load function
chartFileForTypeCheck, _ := loadChartFileForTypeCheck(chartPath)
@ -102,6 +105,13 @@ func validateChartYamlFormat(chartFileError error) error {
return nil
}
func validateChartYamlStrictFormat(chartFileError error) error {
if chartFileError != nil {
return errors.Errorf("failed to strictly parse chartfile\n\t%s", chartFileError.Error())
}
return nil
}
func validateChartName(cf *chart.Metadata) error {
if cf.Name == "" {
return errors.New("name is required")

@ -3,3 +3,4 @@ apiVersion: v2
apiVersion: v1
description: A Helm chart for Kubernetes
version: 1.3.0
icon: http://example.com

Loading…
Cancel
Save