diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 7a52ea597..1c652e182 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -19,11 +19,14 @@ package main import ( "errors" "fmt" + "io/ioutil" "os" "path/filepath" + "strings" "github.com/spf13/cobra" + "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/lint" ) @@ -55,6 +58,35 @@ func lintCmd(cmd *cobra.Command, args []string) error { path = args[0] } + if err := lintChart(path); err != nil { + return err + } + + return nil +} + +func lintChart(path string) error { + if strings.HasSuffix(path, ".tgz") { + tempDir, err := ioutil.TempDir("", "helm-lint") + if err != nil { + return err + } + defer os.RemoveAll(tempDir) + + file, err := os.Open(path) + if err != nil { + return err + } + defer file.Close() + + if err = chartutil.Expand(tempDir, file); err != nil { + return err + } + + base := strings.Split(filepath.Base(path), "-")[0] + path = filepath.Join(tempDir, base) + } + // Guard: Error out of this is not a chart. if _, err := os.Stat(filepath.Join(path, "Chart.yaml")); err != nil { return errLintNoChart @@ -69,5 +101,6 @@ func lintCmd(cmd *cobra.Command, args []string) error { for _, i := range issues { fmt.Printf("%s\n", i) } + return nil } diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go new file mode 100644 index 000000000..b7e3db6c6 --- /dev/null +++ b/cmd/helm/lint_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "testing" +) + +var ( + archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz" + chartDirPath = "testdata/testcharts/decompressedchart/" +) + +func TestLintChart(t *testing.T) { + if err := lintChart(chartDirPath); err != nil { + t.Errorf("%s", err) + } + + if err := lintChart(archivedChartPath); err != nil { + t.Errorf("%s", err) + } + +} diff --git a/cmd/helm/search_test.go b/cmd/helm/search_test.go index d53dfa3fd..0869551aa 100644 --- a/cmd/helm/search_test.go +++ b/cmd/helm/search_test.go @@ -22,8 +22,8 @@ import ( "k8s.io/helm/pkg/repo" ) -const testDir = "testdata/" -const testFile = "testdata/local-index.yaml" +const testDir = "testdata/testcache" +const testFile = "testdata/testcache/local-index.yaml" type searchTestCase struct { in string diff --git a/cmd/helm/testdata/foobar-index.yaml b/cmd/helm/testdata/testcache/foobar-index.yaml similarity index 100% rename from cmd/helm/testdata/foobar-index.yaml rename to cmd/helm/testdata/testcache/foobar-index.yaml diff --git a/cmd/helm/testdata/local-index.yaml b/cmd/helm/testdata/testcache/local-index.yaml similarity index 100% rename from cmd/helm/testdata/local-index.yaml rename to cmd/helm/testdata/testcache/local-index.yaml diff --git a/cmd/helm/testdata/testcharts/compressedchart-0.1.0.tgz b/cmd/helm/testdata/testcharts/compressedchart-0.1.0.tgz new file mode 100644 index 000000000..575b27128 Binary files /dev/null and b/cmd/helm/testdata/testcharts/compressedchart-0.1.0.tgz differ diff --git a/cmd/helm/testdata/testcharts/decompressedchart/.helmignore b/cmd/helm/testdata/testcharts/decompressedchart/.helmignore new file mode 100644 index 000000000..435b756d8 --- /dev/null +++ b/cmd/helm/testdata/testcharts/decompressedchart/.helmignore @@ -0,0 +1,5 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +.git diff --git a/cmd/helm/testdata/testcharts/decompressedchart/Chart.yaml b/cmd/helm/testdata/testcharts/decompressedchart/Chart.yaml new file mode 100755 index 000000000..3e65afdfa --- /dev/null +++ b/cmd/helm/testdata/testcharts/decompressedchart/Chart.yaml @@ -0,0 +1,3 @@ +description: A Helm chart for Kubernetes +name: decompressedchart +version: 0.1.0 diff --git a/cmd/helm/testdata/testcharts/decompressedchart/values.yaml b/cmd/helm/testdata/testcharts/decompressedchart/values.yaml new file mode 100644 index 000000000..a940d1fd9 --- /dev/null +++ b/cmd/helm/testdata/testcharts/decompressedchart/values.yaml @@ -0,0 +1,4 @@ +# Default values for decompressedchart. +# This is a YAML-formatted file. +# Declare name/value pairs to be passed into your templates. + name: my-decompressed-chart diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index dbe980606..6c47413e6 100644 --- a/pkg/lint/lint.go +++ b/pkg/lint/lint.go @@ -17,17 +17,17 @@ limitations under the License. package lint import ( + "path/filepath" + "k8s.io/helm/pkg/lint/rules" "k8s.io/helm/pkg/lint/support" - "os" - "path/filepath" ) // All runs all of the available linters on the given base directory. func All(basedir string) []support.Message { + // Using abs path to get directory context - current, _ := os.Getwd() - chartDir := filepath.Join(current, basedir) + chartDir, _ := filepath.Abs(basedir) linter := support.Linter{ChartDir: chartDir} rules.Chartfile(&linter)