Commit a64303d0 authored by Michelle Noorali's avatar Michelle Noorali

feat(lint): lint an archived chart

* part of #836
parent bb875b56
...@@ -19,11 +19,14 @@ package main ...@@ -19,11 +19,14 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/lint" "k8s.io/helm/pkg/lint"
) )
...@@ -55,6 +58,35 @@ func lintCmd(cmd *cobra.Command, args []string) error { ...@@ -55,6 +58,35 @@ func lintCmd(cmd *cobra.Command, args []string) error {
path = args[0] 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. // Guard: Error out of this is not a chart.
if _, err := os.Stat(filepath.Join(path, "Chart.yaml")); err != nil { if _, err := os.Stat(filepath.Join(path, "Chart.yaml")); err != nil {
return errLintNoChart return errLintNoChart
...@@ -69,5 +101,6 @@ func lintCmd(cmd *cobra.Command, args []string) error { ...@@ -69,5 +101,6 @@ func lintCmd(cmd *cobra.Command, args []string) error {
for _, i := range issues { for _, i := range issues {
fmt.Printf("%s\n", i) fmt.Printf("%s\n", i)
} }
return nil return nil
} }
/*
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)
}
}
...@@ -22,8 +22,8 @@ import ( ...@@ -22,8 +22,8 @@ import (
"k8s.io/helm/pkg/repo" "k8s.io/helm/pkg/repo"
) )
const testDir = "testdata/" const testDir = "testdata/testcache"
const testFile = "testdata/local-index.yaml" const testFile = "testdata/testcache/local-index.yaml"
type searchTestCase struct { type searchTestCase struct {
in string in string
......
# 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
description: A Helm chart for Kubernetes
name: decompressedchart
version: 0.1.0
# Default values for decompressedchart.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
name: my-decompressed-chart
...@@ -17,17 +17,17 @@ limitations under the License. ...@@ -17,17 +17,17 @@ limitations under the License.
package lint package lint
import ( import (
"path/filepath"
"k8s.io/helm/pkg/lint/rules" "k8s.io/helm/pkg/lint/rules"
"k8s.io/helm/pkg/lint/support" "k8s.io/helm/pkg/lint/support"
"os"
"path/filepath"
) )
// All runs all of the available linters on the given base directory. // All runs all of the available linters on the given base directory.
func All(basedir string) []support.Message { func All(basedir string) []support.Message {
// Using abs path to get directory context // Using abs path to get directory context
current, _ := os.Getwd() chartDir, _ := filepath.Abs(basedir)
chartDir := filepath.Join(current, basedir)
linter := support.Linter{ChartDir: chartDir} linter := support.Linter{ChartDir: chartDir}
rules.Chartfile(&linter) rules.Chartfile(&linter)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment