@ -19,6 +19,7 @@ package rules
import (
import (
"fmt"
"fmt"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strings"
"strings"
@ -47,10 +48,10 @@ var validName = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-
// Templates lints the templates in the Linter.
// Templates lints the templates in the Linter.
func Templates ( linter * support . Linter , values map [ string ] interface { } , namespace string , strict bool ) {
func Templates ( linter * support . Linter , values map [ string ] interface { } , namespace string , strict bool ) {
path := "templates/"
f path := "templates/"
templatesPath := filepath . Join ( linter . ChartDir , path)
templatesPath := filepath . Join ( linter . ChartDir , f path)
templatesDirExist := linter . RunLinterRule ( support . WarningSev , path, validateTemplatesDir ( templatesPath ) )
templatesDirExist := linter . RunLinterRule ( support . WarningSev , f path, validateTemplatesDir ( templatesPath ) )
// Templates directory is optional for now
// Templates directory is optional for now
if ! templatesDirExist {
if ! templatesDirExist {
@ -60,7 +61,7 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
// Load chart and parse templates
// Load chart and parse templates
chart , err := loader . Load ( linter . ChartDir )
chart , err := loader . Load ( linter . ChartDir )
chartLoaded := linter . RunLinterRule ( support . ErrorSev , path, err )
chartLoaded := linter . RunLinterRule ( support . ErrorSev , f path, err )
if ! chartLoaded {
if ! chartLoaded {
return
return
@ -77,14 +78,14 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
}
}
valuesToRender , err := chartutil . ToRenderValues ( chart , cvals , options , nil )
valuesToRender , err := chartutil . ToRenderValues ( chart , cvals , options , nil )
if err != nil {
if err != nil {
linter . RunLinterRule ( support . ErrorSev , path, err )
linter . RunLinterRule ( support . ErrorSev , f path, err )
return
return
}
}
var e engine . Engine
var e engine . Engine
e . LintMode = true
e . LintMode = true
renderedContentMap , err := e . Render ( chart , valuesToRender )
renderedContentMap , err := e . Render ( chart , valuesToRender )
renderOk := linter . RunLinterRule ( support . ErrorSev , path, err )
renderOk := linter . RunLinterRule ( support . ErrorSev , f path, err )
if ! renderOk {
if ! renderOk {
return
return
@ -99,13 +100,13 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
* /
* /
for _ , template := range chart . Templates {
for _ , template := range chart . Templates {
fileName , data := template . Name , template . Data
fileName , data := template . Name , template . Data
path = fileName
f path = fileName
linter . RunLinterRule ( support . ErrorSev , path, validateAllowedExtension ( fileName ) )
linter . RunLinterRule ( support . ErrorSev , f path, validateAllowedExtension ( fileName ) )
// These are v3 specific checks to make sure and warn people if their
// These are v3 specific checks to make sure and warn people if their
// chart is not compatible with v3
// chart is not compatible with v3
linter . RunLinterRule ( support . WarningSev , path, validateNoCRDHooks ( data ) )
linter . RunLinterRule ( support . WarningSev , f path, validateNoCRDHooks ( data ) )
linter . RunLinterRule ( support . ErrorSev , path, validateNoReleaseTime ( data ) )
linter . RunLinterRule ( support . ErrorSev , f path, validateNoReleaseTime ( data ) )
// We only apply the following lint rules to yaml files
// We only apply the following lint rules to yaml files
if filepath . Ext ( fileName ) != ".yaml" || filepath . Ext ( fileName ) == ".yml" {
if filepath . Ext ( fileName ) != ".yaml" || filepath . Ext ( fileName ) == ".yml" {
@ -114,12 +115,12 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
// NOTE: disabled for now, Refs https://github.com/helm/helm/issues/1463
// NOTE: disabled for now, Refs https://github.com/helm/helm/issues/1463
// Check that all the templates have a matching value
// Check that all the templates have a matching value
//linter.RunLinterRule(support.WarningSev, path, validateNoMissingValues(templatesPath, valuesToRender, preExecutedTemplate))
//linter.RunLinterRule(support.WarningSev, f path, validateNoMissingValues(templatesPath, valuesToRender, preExecutedTemplate))
// NOTE: disabled for now, Refs https://github.com/helm/helm/issues/1037
// NOTE: disabled for now, Refs https://github.com/helm/helm/issues/1037
// linter.RunLinterRule(support.WarningSev, path, validateQuotes(string(preExecutedTemplate)))
// linter.RunLinterRule(support.WarningSev, f path, validateQuotes(string(preExecutedTemplate)))
renderedContent := renderedContentMap [ file path. Join ( chart . Name ( ) , fileName ) ]
renderedContent := renderedContentMap [ path. Join ( chart . Name ( ) , fileName ) ]
if strings . TrimSpace ( renderedContent ) != "" {
if strings . TrimSpace ( renderedContent ) != "" {
var yamlStruct K8sYamlStruct
var yamlStruct K8sYamlStruct
// Even though K8sYamlStruct only defines a few fields, an error in any other
// Even though K8sYamlStruct only defines a few fields, an error in any other
@ -128,10 +129,10 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
// If YAML linting fails, we sill progress. So we don't capture the returned state
// If YAML linting fails, we sill progress. So we don't capture the returned state
// on this linter run.
// on this linter run.
linter . RunLinterRule ( support . ErrorSev , path, validateYamlContent ( err ) )
linter . RunLinterRule ( support . ErrorSev , f path, validateYamlContent ( err ) )
linter . RunLinterRule ( support . ErrorSev , path, validateMetadataName ( & yamlStruct ) )
linter . RunLinterRule ( support . ErrorSev , f path, validateMetadataName ( & yamlStruct ) )
linter . RunLinterRule ( support . ErrorSev , path, validateNoDeprecations ( & yamlStruct ) )
linter . RunLinterRule ( support . ErrorSev , f path, validateNoDeprecations ( & yamlStruct ) )
linter . RunLinterRule ( support . ErrorSev , path, validateMatchSelector ( & yamlStruct , renderedContent ) )
linter . RunLinterRule ( support . ErrorSev , f path, validateMatchSelector ( & yamlStruct , renderedContent ) )
}
}
}
}
}
}