Merge pull request #5730 from mattfarina/fix-lint-apiversion-v3

Fix lint apiversion v3
pull/5735/head
Matt Farina 6 years ago committed by GitHub
commit c62a3a4896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,12 +35,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) != 5 { if len(m) != 6 {
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 one ERROR messages, check for them // There should be one INFO, 2 WARNINGs and one ERROR messages, check for them
var i, w, e, e2, e3 bool var i, w, e, e2, e3, e4 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") {
@ -62,9 +62,13 @@ func TestBadChart(t *testing.T) {
if strings.Contains(msg.Err.Error(), "directory name (badchartfile) and chart name () must be the same") { if strings.Contains(msg.Err.Error(), "directory name (badchartfile) and chart name () must be the same") {
e3 = true e3 = true
} }
if strings.Contains(msg.Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") {
e4 = true
}
} }
} }
if !e || !e2 || !e3 || !w || !i { if !e || !e2 || !e3 || !e4 || !w || !i {
t.Errorf("Didn't find all the expected errors, got %#v", m) t.Errorf("Didn't find all the expected errors, got %#v", m)
} }
} }

@ -17,6 +17,7 @@ limitations under the License.
package rules // import "helm.sh/helm/pkg/lint/rules" package rules // import "helm.sh/helm/pkg/lint/rules"
import ( import (
"fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -48,6 +49,7 @@ func Chartfile(linter *support.Linter) {
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartNameDirMatch(linter.ChartDir, chartFile)) linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartNameDirMatch(linter.ChartDir, chartFile))
// Chart metadata // Chart metadata
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartAPIVersion(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartVersion(chartFile)) linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartVersion(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartMaintainer(chartFile)) linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartMaintainer(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartSources(chartFile)) linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartSources(chartFile))
@ -85,6 +87,18 @@ func validateChartNameDirMatch(chartDir string, cf *chart.Metadata) error {
return nil return nil
} }
func validateChartAPIVersion(cf *chart.Metadata) error {
if cf.APIVersion == "" {
return errors.New("apiVersion is required. The value must be either \"v1\" or \"v2\"")
}
if cf.APIVersion != "v1" && cf.APIVersion != "v2" {
return fmt.Errorf("apiVersion '%s' is not valid. The value must be either \"v1\" or \"v2\"", cf.APIVersion)
}
return nil
}
func validateChartVersion(cf *chart.Metadata) error { func validateChartVersion(cf *chart.Metadata) error {
if cf.Version == "" { if cf.Version == "" {
return errors.New("version is required") return errors.New("version is required")

@ -209,8 +209,8 @@ func TestChartfile(t *testing.T) {
Chartfile(&linter) Chartfile(&linter)
msgs := linter.Messages msgs := linter.Messages
if len(msgs) != 4 { if len(msgs) != 5 {
t.Errorf("Expected 3 errors, got %d", len(msgs)) t.Errorf("Expected 4 errors, got %d", len(msgs))
} }
if !strings.Contains(msgs[0].Err.Error(), "name is required") { if !strings.Contains(msgs[0].Err.Error(), "name is required") {
@ -221,12 +221,16 @@ func TestChartfile(t *testing.T) {
t.Errorf("Unexpected message 1: %s", msgs[1].Err) t.Errorf("Unexpected message 1: %s", msgs[1].Err)
} }
if !strings.Contains(msgs[2].Err.Error(), "version 0.0.0 is less than or equal to 0") { if !strings.Contains(msgs[2].Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") {
t.Errorf("Unexpected message 2: %s", msgs[2].Err) t.Errorf("Unexpected message 2: %s", msgs[2].Err)
} }
if !strings.Contains(msgs[3].Err.Error(), "icon is recommended") { if !strings.Contains(msgs[3].Err.Error(), "version 0.0.0 is less than or equal to 0") {
t.Errorf("Unexpected message 3: %s", msgs[3].Err) t.Errorf("Unexpected message 3: %s", msgs[2].Err)
}
if !strings.Contains(msgs[4].Err.Error(), "icon is recommended") {
t.Errorf("Unexpected message 4: %s", msgs[3].Err)
} }
} }

@ -1,4 +1,3 @@
apiVersion: v1
description: A Helm chart for Kubernetes description: A Helm chart for Kubernetes
version: 0.0.0 version: 0.0.0
home: "" home: ""

Loading…
Cancel
Save