diff --git a/pkg/chart/v2/lint/rules/chartfile.go b/pkg/chart/v2/lint/rules/chartfile.go index d6e5d86f4..28aaafbf1 100644 --- a/pkg/chart/v2/lint/rules/chartfile.go +++ b/pkg/chart/v2/lint/rules/chartfile.go @@ -21,9 +21,11 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/Masterminds/semver/v3" "github.com/asaskevich/govalidator" + "k8s.io/apimachinery/pkg/api/validation" "sigs.k8s.io/yaml" chart "helm.sh/helm/v4/pkg/chart/v2" @@ -124,8 +126,8 @@ func validateChartName(cf *chart.Metadata) error { // Chart names must also be valid Kubernetes metadata names so they can be // used safely as resource name prefixes (lowercase, alphanumeric, hyphens // and dots only; must start and end with an alphanumeric character). - if err := chartutil.ValidateMetadataName(cf.Name); err != nil { - return fmt.Errorf("chart name %q is not a valid Kubernetes name: use lowercase letters, digits, hyphens, and dots only (e.g. my-chart, my.chart)", cf.Name) + if errs := validation.NameIsDNSSubdomain(cf.Name, false); len(errs) > 0 { + return fmt.Errorf("chart name %q is not a valid Kubernetes name: %s", cf.Name, strings.Join(errs, ", ")) } return nil } diff --git a/pkg/chart/v2/lint/rules/chartfile_test.go b/pkg/chart/v2/lint/rules/chartfile_test.go index 7307c0360..139fc9230 100644 --- a/pkg/chart/v2/lint/rules/chartfile_test.go +++ b/pkg/chart/v2/lint/rules/chartfile_test.go @@ -61,6 +61,8 @@ func TestValidateChartName(t *testing.T) { // empty name (badChart has name: "") require.Error(t, validateChartName(badChart), "validateChartName to return a linter error, got no error") + assert.Error(t, validateChartName(badChartName), "expected validateChartName to return a linter error for an invalid name, got no error") + invalidNames := []struct { name string reason string diff --git a/pkg/chart/v2/lint/rules/testdata/badchartname/Chart.yaml b/pkg/chart/v2/lint/rules/testdata/badchartname/Chart.yaml index 0f3333423..64f8fb8bf 100644 --- a/pkg/chart/v2/lint/rules/testdata/badchartname/Chart.yaml +++ b/pkg/chart/v2/lint/rules/testdata/badchartname/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 description: A Helm chart for Kubernetes version: 0.1.0 -name: "MyInvalidChart" +name: "../badchartname" type: application