Exemplo n.º 1
0
func lintChart(path string) (support.Linter, error) {
	var chartPath string
	linter := support.Linter{}

	if strings.HasSuffix(path, ".tgz") {
		tempDir, err := ioutil.TempDir("", "helm-lint")
		if err != nil {
			return linter, err
		}
		defer os.RemoveAll(tempDir)

		file, err := os.Open(path)
		if err != nil {
			return linter, err
		}
		defer file.Close()

		if err = chartutil.Expand(tempDir, file); err != nil {
			return linter, err
		}

		base := strings.Split(filepath.Base(path), "-")[0]
		chartPath = filepath.Join(tempDir, base)
	} else {
		chartPath = path
	}

	// Guard: Error out of this is not a chart.
	if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil {
		return linter, errLintNoChart
	}

	return lint.All(chartPath), nil
}
Exemplo n.º 2
0
Arquivo: lint.go Projeto: gabrtv/helm
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
	}

	linter := lint.All(path)

	if len(linter.Messages) == 0 {
		fmt.Println("Lint OK")
		return nil
	}

	for _, i := range linter.Messages {
		fmt.Printf("%s\n", i)
	}

	if linter.HighestSeverity == support.ErrorSev {
		return errLintFailed
	}

	return nil
}