fix subcharts templates not linted if parent chart doesn't have templates directory

Signed-off-by: wawa0210 <xiaozhang0210@hotmail.com>
pull/8426/head
wawa0210 5 years ago
parent 579c01fad0
commit c5ea8fe00d
No known key found for this signature in database
GPG Key ID: 900C83A2C098B3B1

@ -1,6 +1,7 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts ==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended [INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory not found [WARNING] templates/: directory not found
[ERROR] templates/: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[ERROR] : unable to load chart [ERROR] : unable to load chart
error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
@ -10,6 +11,7 @@
[ERROR] Chart.yaml: version is required [ERROR] Chart.yaml: version is required
[INFO] Chart.yaml: icon is recommended [INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory not found [WARNING] templates/: directory not found
[ERROR] templates/: validation: chart.metadata.name is required
[ERROR] : unable to load chart [ERROR] : unable to load chart
validation: chart.metadata.name is required validation: chart.metadata.name is required

@ -1,6 +1,7 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts ==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended [INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory not found [WARNING] templates/: directory not found
[ERROR] templates/: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[ERROR] : unable to load chart [ERROR] : unable to load chart
error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required

@ -38,12 +38,12 @@ const goodChartDir = "rules/testdata/goodone"
func TestBadChart(t *testing.T) { func TestBadChart(t *testing.T) {
m := All(badChartDir, values, namespace, strict).Messages m := All(badChartDir, values, namespace, strict).Messages
if len(m) != 8 { if len(m) != 9 {
t.Errorf("Number of errors %v", len(m)) t.Errorf("Number of errors %v", len(m))
t.Errorf("All didn't fail with expected errors, got %#v", m) t.Errorf("All didn't fail with expected errors, got %#v", m)
} }
// There should be one INFO, 2 WARNINGs and 2 ERROR messages, check for them // There should be one INFO, 2 WARNINGs and 6 ERROR messages, check for them
var i, w, e, e2, e3, e4, e5, e6 bool var i, w, w2, e, e2, e3, e4, e5, e6 bool
for _, msg := range m { for _, msg := range m {
if msg.Severity == support.InfoSev { if msg.Severity == support.InfoSev {
if strings.Contains(msg.Err.Error(), "icon is recommended") { if strings.Contains(msg.Err.Error(), "icon is recommended") {
@ -54,6 +54,9 @@ func TestBadChart(t *testing.T) {
if strings.Contains(msg.Err.Error(), "directory not found") { if strings.Contains(msg.Err.Error(), "directory not found") {
w = true w = true
} }
if strings.Contains(msg.Err.Error(), "directory not found") {
w2 = true
}
} }
if msg.Severity == support.ErrorSev { if msg.Severity == support.ErrorSev {
if strings.Contains(msg.Err.Error(), "version '0.0.0.0' is not a valid SemVer") { if strings.Contains(msg.Err.Error(), "version '0.0.0.0' is not a valid SemVer") {
@ -80,7 +83,7 @@ func TestBadChart(t *testing.T) {
} }
} }
} }
if !e || !e2 || !e3 || !e4 || !e5 || !w || !i || !e6 { if !e || !e2 || !e3 || !e4 || !e5 || !w || !w2 || !i || !e6 {
t.Errorf("Didn't find all the expected errors, got %#v", m) t.Errorf("Didn't find all the expected errors, got %#v", m)
} }
} }

@ -50,12 +50,10 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
path := "templates/" path := "templates/"
templatesPath := filepath.Join(linter.ChartDir, path) templatesPath := filepath.Join(linter.ChartDir, path)
templatesDirExist := linter.RunLinterRule(support.WarningSev, path, validateTemplatesDir(templatesPath)) // Templates directory is optional
// if a warning level alarm occurs, just output the result,
// Templates directory is optional for now // and then continue to execute the subsequent logic
if !templatesDirExist { linter.RunLinterRule(support.WarningSev, path, validateTemplatesDir(templatesPath))
return
}
// Load chart and parse templates // Load chart and parse templates
chart, err := loader.Load(linter.ChartDir) chart, err := loader.Load(linter.ChartDir)

Loading…
Cancel
Save