Unverified Commit 0a9bf4f9 authored by Matt Farina's avatar Matt Farina Committed by GitHub

Merge pull request #6754 from karuppiah7890/fix-lint-for-no-package-found-v2

fix silent lint ignore for non existing packaged charts
parents 1f692330 23926365
...@@ -17,7 +17,6 @@ limitations under the License. ...@@ -17,7 +17,6 @@ limitations under the License.
package main package main
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -81,8 +80,6 @@ func newLintCmd(out io.Writer) *cobra.Command { ...@@ -81,8 +80,6 @@ func newLintCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
var errLintNoChart = errors.New("No chart found for linting (missing Chart.yaml)")
func (l *lintCmd) run() error { func (l *lintCmd) run() error {
var lowestTolerance int var lowestTolerance int
if l.strict { if l.strict {
...@@ -100,15 +97,16 @@ func (l *lintCmd) run() error { ...@@ -100,15 +97,16 @@ func (l *lintCmd) run() error {
var total int var total int
var failures int var failures int
for _, path := range l.paths { for _, path := range l.paths {
if linter, err := lintChart(path, rvals, l.namespace, l.strict); err != nil { linter, err := lintChart(path, rvals, l.namespace, l.strict)
if err != nil {
failures = failures + 1
fmt.Println("==> Skipping", path) fmt.Println("==> Skipping", path)
fmt.Println(err) fmt.Println(err)
if err == errLintNoChart { fmt.Println("")
failures = failures + 1 continue
} }
} else {
fmt.Println("==> Linting", path)
fmt.Println("==> Linting", path)
if len(linter.Messages) == 0 { if len(linter.Messages) == 0 {
fmt.Println("Lint OK") fmt.Println("Lint OK")
} }
...@@ -121,7 +119,6 @@ func (l *lintCmd) run() error { ...@@ -121,7 +119,6 @@ func (l *lintCmd) run() error {
if linter.HighestSeverity >= lowestTolerance { if linter.HighestSeverity >= lowestTolerance {
failures = failures + 1 failures = failures + 1
} }
}
fmt.Println("") fmt.Println("")
} }
...@@ -148,12 +145,12 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support ...@@ -148,12 +145,12 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
return linter, err return linter, fmt.Errorf("unable to open tar ball %s: %s", path, err.Error())
} }
defer file.Close() defer file.Close()
if err = chartutil.Expand(tempDir, file); err != nil { if err = chartutil.Expand(tempDir, file); err != nil {
return linter, err return linter, fmt.Errorf("unable to extract tar ball: %s", err.Error())
} }
files, err := ioutil.ReadDir(tempDir) files, err := ioutil.ReadDir(tempDir)
...@@ -171,7 +168,7 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support ...@@ -171,7 +168,7 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support
// Guard: Error out if this is not a chart. // Guard: Error out if this is not a chart.
if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil { if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil {
return linter, errLintNoChart return linter, fmt.Errorf("unable to check Chart.yaml file in chart: %s", err.Error())
} }
return lint.All(chartPath, vals, namespace, strict), nil return lint.All(chartPath, vals, namespace, strict), nil
......
...@@ -17,6 +17,8 @@ limitations under the License. ...@@ -17,6 +17,8 @@ limitations under the License.
package main package main
import ( import (
"bytes"
"fmt"
"testing" "testing"
) )
...@@ -70,3 +72,38 @@ func TestLintChart(t *testing.T) { ...@@ -70,3 +72,38 @@ func TestLintChart(t *testing.T) {
}) })
} }
} }
func TestLinRunForNonExistentChart(t *testing.T) {
t.Run("should error out for non existent tgz chart", func(t *testing.T) {
testCharts := []string{"non-existent-chart.tgz"}
testLint := &lintCmd{
paths: testCharts,
out: bytes.NewBufferString(""),
}
expectedErr := fmt.Errorf("0 chart(s) linted, 1 chart(s) failed")
err := testLint.run()
if err == nil {
t.Errorf("expected error but got no error")
}
if err != nil && (err.Error() != expectedErr.Error()) {
t.Errorf("expected: \"%v\" , but got: \"%v\"", expectedErr, err)
}
})
t.Run("should error out for corrupted tgz chart", func(t *testing.T) {
var corruptedTgzChart = "testdata/testcharts/corrupted-compressed-chart.tgz"
testCharts := []string{corruptedTgzChart}
testLint := &lintCmd{
paths: testCharts,
out: bytes.NewBufferString(""),
}
expectedErr := fmt.Errorf("0 chart(s) linted, 1 chart(s) failed")
err := testLint.run()
if err == nil {
t.Errorf("expected error but got no error")
}
if err != nil && (err.Error() != expectedErr.Error()) {
t.Errorf("expected: \"%v\" , but got: \"%v\"", expectedErr, err)
}
})
}
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