feat(helm): package to support linting a chart

pull/1121/head
joe2far 9 years ago
parent 274804707c
commit eee4874b23

@ -28,6 +28,8 @@ import (
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm" "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/provenance"
"k8s.io/helm/pkg/repo" "k8s.io/helm/pkg/repo"
) )
@ -46,6 +48,7 @@ Versioned chart archives are used by Helm package repositories.
type packageCmd struct { type packageCmd struct {
save bool save bool
sign bool sign bool
nolint bool
path string path string
key string key string
keyring 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.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.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.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 return cmd
} }
@ -97,6 +101,18 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error {
return err 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) ch, err := chartutil.LoadDir(path)
if err != nil { if err != nil {
return err return err

@ -63,6 +63,13 @@ func TestPackage(t *testing.T) {
expect: "", expect: "",
hasfile: "alpine-0.1.0.tgz", 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", name: "package --sign --key=KEY --keyring=KEYRING testdata/testcharts/alpine",
args: []string{"testdata/testcharts/alpine"}, args: []string{"testdata/testcharts/alpine"},

Loading…
Cancel
Save