Merge pull request #908 from michelleN/feat/836-lint-archived-chart

feat(lint): lint an archived chart
pull/915/head
Michelle Noorali 8 years ago committed by GitHub
commit 849afc29bc

@ -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
}

@ -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)
}
}

@ -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

@ -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

@ -0,0 +1,3 @@
description: A Helm chart for Kubernetes
name: decompressedchart
version: 0.1.0

@ -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

@ -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)

Loading…
Cancel
Save