From eee4874b2376813b9dfd9b7d7e76ad36b864998d Mon Sep 17 00:00:00 2001 From: joe2far Date: Tue, 6 Sep 2016 17:58:53 +0100 Subject: [PATCH] feat(helm): package to support linting a chart --- cmd/helm/package.go | 16 ++++++++++++++++ cmd/helm/package_test.go | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/cmd/helm/package.go b/cmd/helm/package.go index fac2a2fef..f198c3f47 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -28,6 +28,8 @@ import ( "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/helm" + "k8s.io/helm/pkg/lint" + "k8s.io/helm/pkg/lint/support" "k8s.io/helm/pkg/provenance" "k8s.io/helm/pkg/repo" ) @@ -46,6 +48,7 @@ Versioned chart archives are used by Helm package repositories. type packageCmd struct { save bool sign bool + nolint bool path string key string keyring string @@ -87,6 +90,7 @@ func newPackageCmd(client helm.Interface, out io.Writer) *cobra.Command { f.BoolVar(&pkg.sign, "sign", false, "use a PGP private key to sign this package") f.StringVar(&pkg.key, "key", "", "the name of the key to use when signing. Used if --sign is true.") f.StringVar(&pkg.keyring, "keyring", defaultKeyring(), "the location of a public keyring") + f.BoolVar(&pkg.nolint, "no-lint", false, "not lint a chart before packaging it") return cmd } @@ -97,6 +101,18 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error { return err } + if p.nolint != true { + linter := lint.All(path) + if linter.HighestSeverity == support.ErrorSev { + for _, msg := range linter.Messages { + if msg.Severity == support.ErrorSev { + cmd.Println(msg) + } + } + return fmt.Errorf("chart lint failed") + } + } + ch, err := chartutil.LoadDir(path) if err != nil { return err diff --git a/cmd/helm/package_test.go b/cmd/helm/package_test.go index b724ba2ea..249a49634 100644 --- a/cmd/helm/package_test.go +++ b/cmd/helm/package_test.go @@ -63,6 +63,13 @@ func TestPackage(t *testing.T) { expect: "", hasfile: "alpine-0.1.0.tgz", }, + { + name: "package testdata/testcharts/alpine --no-lint", + args: []string{"testdata/testcharts/alpine"}, + flags: map[string]string{"nolint": "1"}, + expect: "", + hasfile: "alpine-0.1.0.tgz", + }, { name: "package --sign --key=KEY --keyring=KEYRING testdata/testcharts/alpine", args: []string{"testdata/testcharts/alpine"},