From f736af95eb94950acc5871a8451fa4a4bdc37697 Mon Sep 17 00:00:00 2001 From: Christophe VILA Date: Fri, 16 Oct 2020 22:23:18 +0200 Subject: [PATCH 1/2] do not check YAML if nothing was parsed Signed-off-by: Christophe VILA --- pkg/lint/rules/template.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 5de0819c4..3e4e0ebd1 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -122,6 +122,9 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace // key will be raised as well err := yaml.Unmarshal([]byte(renderedContent), &yamlStruct) + if (K8sYamlStruct{}) == yamlStruct { + continue + } // If YAML linting fails, we sill progress. So we don't capture the returned state // on this linter run. linter.RunLinterRule(support.ErrorSev, fpath, validateYamlContent(err)) From 8a4c0bc7b1d7f17dededd6167ad4d500073f8842 Mon Sep 17 00:00:00 2001 From: Christophe VILA Date: Tue, 27 Oct 2020 23:06:01 +0100 Subject: [PATCH 2/2] added test for https://github.com/helm/helm/pull/8913 related to https://github.com/helm/helm/issues/8621 Signed-off-by: Christophe VILA --- pkg/lint/rules/template_test.go | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pkg/lint/rules/template_test.go b/pkg/lint/rules/template_test.go index b4397851b..50cd562aa 100644 --- a/pkg/lint/rules/template_test.go +++ b/pkg/lint/rules/template_test.go @@ -332,3 +332,37 @@ func TestValidateTopIndentLevel(t *testing.T) { } } + +// TestEmptyWithCommentsManifests checks the lint is not failing against empty manifests that contains only comments +// See https://github.com/helm/helm/issues/8621 +func TestEmptyWithCommentsManifests(t *testing.T) { + mychart := chart.Chart{ + Metadata: &chart.Metadata{ + APIVersion: "v2", + Name: "emptymanifests", + Version: "0.1.0", + Icon: "satisfy-the-linting-gods.gif", + }, + Templates: []*chart.File{ + { + Name: "templates/empty-with-comments.yaml", + Data: []byte("#@formatter:off\n"), + }, + }, + } + tmpdir := ensure.TempDir(t) + defer os.RemoveAll(tmpdir) + + if err := chartutil.SaveDir(&mychart, tmpdir); err != nil { + t.Fatal(err) + } + + linter := support.Linter{ChartDir: filepath.Join(tmpdir, mychart.Name())} + Templates(&linter, values, namespace, strict) + if l := len(linter.Messages); l > 0 { + for i, msg := range linter.Messages { + t.Logf("Message %d: %s", i, msg) + } + t.Fatalf("Expected 0 lint errors, got %d", l) + } +}