From 0e32e6417b57ef72fd3bda0001b17db6f27040a8 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Wed, 15 Apr 2020 11:48:07 -0600 Subject: [PATCH] fix: lint with strict passes for helm create (#7926) Signed-off-by: Matt Butcher --- pkg/chartutil/create.go | 2 +- pkg/lint/lint_test.go | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index 8bab79429..d8480f54f 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -74,7 +74,7 @@ serviceAccount: create: true # The name of the service account to use. # If not set and create is true, a name is generated using the fullname template - name: + name: "" podSecurityContext: {} # fsGroup: 2000 diff --git a/pkg/lint/lint_test.go b/pkg/lint/lint_test.go index 0514f7f6d..acd67adac 100644 --- a/pkg/lint/lint_test.go +++ b/pkg/lint/lint_test.go @@ -17,11 +17,14 @@ limitations under the License. package lint import ( + "io/ioutil" + "os" "strings" + "testing" + "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/lint/support" - - "testing" + "k8s.io/helm/pkg/proto/hapi/chart" ) var values = []byte{} @@ -101,3 +104,36 @@ func TestGoodChart(t *testing.T) { t.Errorf("All failed but shouldn't have: %#v", m) } } + +// TestHelmCreateChart tests that a `helm create` always passes a `helm lint` test. +// +// See https://github.com/helm/helm/issues/7923 +func TestHelmCreateChart(t *testing.T) { + dir, err := ioutil.TempDir("", "-helm-test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + cfile := &chart.Metadata{ + Name: "testhelmcreatepasseslint", + Description: "See lint_test.go", + Version: "0.1.0", + AppVersion: "1.0", + ApiVersion: chartutil.ApiVersionV1, + } + + createdChart, err := chartutil.Create(cfile, dir) + if err != nil { + t.Error(err) + // Fatal is bad because of the defer. + return + } + + m := All(createdChart, values, namespace, true).Messages + if ll := len(m); ll != 1 { + t.Errorf("All should have had exactly 1 error. Got %d", ll) + } else if msg := m[0].Err.Error(); !strings.Contains(msg, "icon is recommended") { + t.Errorf("Unexpected lint error: %s", msg) + } +}