Commit 06867b22 authored by Michelle Noorali's avatar Michelle Noorali
Browse files

fix(linter): disable checking for empty values

resolves #1463
parent 5fc020f0
main Release add-codeql dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible dependabot/go_modules/github.com/lib/pq-1.10.9 dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0 dependabot/go_modules/golang.org/x/crypto-0.9.0 dependabot/go_modules/golang.org/x/term-0.8.0 dependabot/go_modules/k8s.io/klog/v2-2.100.1 dev-v2 feat-v3/event-emitter-lua release-2.10 release-2.11 release-2.12 release-2.13 release-2.14 release-2.15 release-2.16 release-2.17 release-2.2 release-2.3 release-2.4 release-2.5 release-2.6 release-2.7 release-2.8 release-2.9 release-3.0 release-3.1 release-3.10 release-3.11 release-3.12 release-3.2 release-3.3 release-3.4 release-3.5 release-3.6 release-3.6.1 release-3.6.2 release-3.7 release-3.8 release-3.9 release-v3.0.0-beta.4 v3.12.0 v3.12.0-rc.1 v3.12.0-dev.1 v3.11.3 v3.11.2 v3.11.1 v3.11.0 v3.11.0-rc.2 v3.11.0-rc.1 v3.10.3 v3.10.2 v3.10.1 v3.10.0 v3.10.0-rc.1 v3.9.4 v3.9.3 v3.9.2 v3.9.1 v3.9.0 v3.9.0-rc.1 v3.8.2 v3.8.1 v3.8.0 v3.8.0-rc.2 v3.8.0-rc.1 v3.7.2 v3.7.1 v3.7.0 v3.7.0-rc.3 v3.7.0-rc.2 v3.7.0-rc.1 v3.6.3 v3.6.2 v3.6.1 v3.6.0 v3.6.0-rc.1 v3.5.4 v3.5.3 v3.5.2 v3.5.1 v3.5.0 v3.5.0-rc.2 v3.5.0-rc.1 v3.4.2 v3.4.1 v3.4.0 v3.4.0-rc.1 v3.3.4 v3.3.3 v3.3.2 v3.3.1 v3.3.0 v3.3.0-rc.2 v3.3.0-rc.1 v3.2.4 v3.2.3 v3.2.2 v3.2.1 v3.2.0 v3.2.0-rc.1 v3.1.3 v3.1.2 v3.1.1 v3.1.0 v3.1.0-rc.3 v3.1.0-rc.2 v3.1.0-rc.1 v3.0.3 v3.0.2 v3.0.1 v3.0.0 v3.0.0-rc.4 v3.0.0-rc.3 v3.0.0-rc.2 v3.0.0-rc.1 v3.0.0-beta.5 v3.0.0-beta.4 v3.0.0-beta.3 v3.0.0-beta.2 v3.0.0-beta.1 v3.0.0-alpha.2 v3.0.0-alpha.1 v2.17.0 v2.17.0-rc.1 v2.16.12 v2.16.11 v2.16.10 v2.16.9 v2.16.8 v2.16.7 v2.16.6 v2.16.5 v2.16.4 v2.16.3 v2.16.2 v2.16.1 v2.16.0 v2.16.0-rc.2 v2.16.0-rc.1 v2.15.2 v2.15.1 v2.15.0 v2.15.0-rc.2 v2.15.0-rc.1 v2.14.3 v2.14.2 v2.14.1 v2.14.0 v2.14.0-rc.2 v2.14.0-rc.1 v2.13.1 v2.13.1-rc.1 v2.13.0 v2.13.0-rc.2 v2.13.0-rc.1 v2.12.3 v2.12.2 v2.12.1 v2.12.0 v2.12.0-rc.2 v2.12.0-rc.1 v2.11.0 v2.11.0-rc.4 v2.11.0-rc.3 v2.11.0-rc.2 v2.11.0-rc.1 v2.10.0 v2.10.0-rc.3 v2.10.0-rc.2 v2.10.0-rc.1 v2.9.1 v2.9.0 v2.9.0-rc5 v2.9.0-rc4 v2.9.0-rc3 v2.9.0-rc2 v2.9.0-rc1 v2.8.2 v2.8.2-rc1 v2.8.1 v2.8.0 v2.8.0-rc.1 v2.7.2 v2.7.1 v2.7.0 v2.7.0-rc1 v2.6.2 v2.6.1 v2.6.0 v2.5.1 v2.5.0 v2.4.2 v2.4.1 v2.4.0 v2.3.1 v2.3.0 v2.2.3 v2.2.2 v2.2.1 v2.2.0
No related merge requests found
Showing with 4 additions and 66 deletions
+4 -66
...@@ -17,13 +17,10 @@ limitations under the License. ...@@ -17,13 +17,10 @@ limitations under the License.
package rules package rules
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"text/template"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
...@@ -77,7 +74,7 @@ func Templates(linter *support.Linter) { ...@@ -77,7 +74,7 @@ func Templates(linter *support.Linter) {
- Metadata.Namespace is not set - Metadata.Namespace is not set
*/ */
for _, template := range chart.Templates { for _, template := range chart.Templates {
fileName, preExecutedTemplate := template.Name, template.Data fileName, _ := template.Name, template.Data
path = fileName path = fileName
linter.RunLinterRule(support.ErrorSev, path, validateAllowedExtension(fileName)) linter.RunLinterRule(support.ErrorSev, path, validateAllowedExtension(fileName))
...@@ -87,10 +84,11 @@ func Templates(linter *support.Linter) { ...@@ -87,10 +84,11 @@ func Templates(linter *support.Linter) {
continue continue
} }
// NOTE: disabled for now, Refs https://github.com/kubernetes/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, path, validateNoMissingValues(templatesPath, valuesToRender, preExecutedTemplate))
// NOTE, disabled for now, Refs https://github.com/kubernetes/helm/issues/1037 // NOTE: disabled for now, Refs https://github.com/kubernetes/helm/issues/1037
// linter.RunLinterRule(support.WarningSev, path, validateQuotes(string(preExecutedTemplate))) // linter.RunLinterRule(support.WarningSev, path, validateQuotes(string(preExecutedTemplate)))
renderedContent := renderedContentMap[filepath.Join(chart.GetMetadata().Name, fileName)] renderedContent := renderedContentMap[filepath.Join(chart.GetMetadata().Name, fileName)]
...@@ -130,66 +128,6 @@ func validateAllowedExtension(fileName string) error { ...@@ -130,66 +128,6 @@ func validateAllowedExtension(fileName string) error {
return fmt.Errorf("file extension '%s' not valid. Valid extensions are .yaml, .tpl, or .txt", ext) return fmt.Errorf("file extension '%s' not valid. Valid extensions are .yaml, .tpl, or .txt", ext)
} }
// validateNoMissingValues checks that all the {{}} functions returns a non empty value (<no value> or "")
// and return an error otherwise.
func validateNoMissingValues(templatesPath string, chartValues chartutil.Values, templateContent []byte) error {
// 1 - Load Main and associated templates
// Main template that we will parse dynamically
tmpl := template.New("tpl").Funcs(engine.FuncMap())
// If the templatesPath includes any *.tpl files we will parse and import them as associated templates
associatedTemplates, err := filepath.Glob(filepath.Join(templatesPath, "*.tpl"))
if err != nil {
return err
}
if len(associatedTemplates) > 0 {
tmpl, err = tmpl.ParseFiles(associatedTemplates...)
if err != nil {
return err
}
}
var buf bytes.Buffer
var emptyValues []string
// 2 - Extract every function and execute them against the loaded values
// Supported {{ .Chart.Name }}, {{ .Chart.Name | quote }}
r, _ := regexp.Compile(`{{[\w.\s|"'-]+}}`)
functions := r.FindAllString(string(templateContent), -1)
skipRegex, _ := regexp.Compile(`if|else|end`)
// Iterate over the {{ FOO }} templates, executing them against the chartValues
// We do individual templates parsing so we keep the reference for the key (str) that we want it to be interpolated.
for _, str := range functions {
if skipRegex.MatchString(str) {
continue
}
newtmpl, err := tmpl.Parse(str)
if err != nil {
return err
}
err = newtmpl.ExecuteTemplate(&buf, "tpl", chartValues)
if err != nil {
return err
}
renderedValue := buf.String()
if renderedValue == "<no value>" || renderedValue == "" {
emptyValues = append(emptyValues, str)
}
buf.Reset()
}
if len(emptyValues) > 0 {
return fmt.Errorf("these substitution functions are returning no value: %v", emptyValues)
}
return nil
}
func validateYamlContent(err error) error { func validateYamlContent(err error) error {
if err != nil { if err != nil {
return fmt.Errorf("unable to parse YAML\n\t%s", err) return fmt.Errorf("unable to parse YAML\n\t%s", err)
......
Supports Markdown
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