Commit 893c3b61 authored by Axel Köhler's avatar Axel Köhler Committed by Matthew Fisher

Add chart name check to lint (#3773)

Signed-off-by: 's avatarAxel Köhler <koehler.ax3l@gmail.com>
parent 8015fc35
......@@ -11,3 +11,4 @@ rootfs/rudder
vendor/
*.exe
.idea/
*.iml
\ No newline at end of file
......@@ -46,7 +46,8 @@ func Chartfile(linter *support.Linter) {
return
}
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartName(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartNamePresence(chartFile))
linter.RunLinterRule(support.WarningSev, chartFileName, validateChartNameFormat(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartNameDirMatch(linter.ChartDir, chartFile))
// Chart metadata
......@@ -74,13 +75,20 @@ func validateChartYamlFormat(chartFileError error) error {
return nil
}
func validateChartName(cf *chart.Metadata) error {
func validateChartNamePresence(cf *chart.Metadata) error {
if cf.Name == "" {
return errors.New("name is required")
}
return nil
}
func validateChartNameFormat(cf *chart.Metadata) error {
if strings.Contains(cf.Name, ".") {
return errors.New("name should be lower case letters and numbers. Words may be separated with dashes")
}
return nil
}
func validateChartNameDirMatch(chartDir string, cf *chart.Metadata) error {
if cf.Name != filepath.Base(chartDir) {
return fmt.Errorf("directory name (%s) and chart name (%s) must be the same", filepath.Base(chartDir), cf.Name)
......
......@@ -29,17 +29,20 @@ import (
)
const (
badChartDir = "testdata/badchartfile"
goodChartDir = "testdata/goodone"
badChartDir = "testdata/badchartfile"
badNameChartDir = "testdata/badnamechart"
goodChartDir = "testdata/goodone"
)
var (
badChartFilePath = filepath.Join(badChartDir, "Chart.yaml")
badNameChartFilePath = filepath.Join(badNameChartDir, "Chart.yaml")
goodChartFilePath = filepath.Join(goodChartDir, "Chart.yaml")
nonExistingChartFilePath = filepath.Join(os.TempDir(), "Chart.yaml")
)
var badChart, chatLoadRrr = chartutil.LoadChartfile(badChartFilePath)
var badNameChart, _ = chartutil.LoadChartfile(badNameChartFilePath)
var goodChart, _ = chartutil.LoadChartfile(goodChartFilePath)
// Validation functions Test
......@@ -66,12 +69,19 @@ func TestValidateChartYamlFormat(t *testing.T) {
}
func TestValidateChartName(t *testing.T) {
err := validateChartName(badChart)
err := validateChartNamePresence(badChart)
if err == nil {
t.Errorf("validateChartName to return a linter error, got no error")
}
}
func TestValidateChartNameFormat(t *testing.T) {
err := validateChartNameFormat(badNameChart)
if err == nil {
t.Errorf("validateChartNameFormat to return a linter error, got no error")
}
}
func TestValidateChartNameDirMatch(t *testing.T) {
err := validateChartNameDirMatch(goodChartDir, goodChart)
if err != nil {
......
name: bad.chart.name
description: A Helm chart for Kubernetes
version: 0.1.0
icon: http://riverrun.io
# Default values for badchartname.
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