diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 36564d7f..56e12612 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -32,7 +32,12 @@ import ( "github.com/helm/chart-testing/v3/pkg/util" ) -const maxNameLength = 63 +const ( + // maxNameLength is the longest name Kubernetes accepts for a namespace. + maxNameLength = 63 + // maxReleaseNameLength is the longest release name Helm accepts. + maxReleaseNameLength = 53 +) // Git is the Interface that wraps Git operations. // @@ -228,7 +233,7 @@ func (c *Chart) CreateInstallParams(buildID string, releaseName string) (release // unconditionally, which made --release-name appear to be ignored (#198). release = releaseName } else { - release = util.SanitizeName(fmt.Sprintf("%s-%s", release, randomSuffix), maxNameLength) + release = util.SanitizeName(fmt.Sprintf("%s-%s", release, randomSuffix), maxReleaseNameLength) } namespace = util.SanitizeName(fmt.Sprintf("%s-%s", namespace, randomSuffix), maxNameLength) return diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index f849cbd7..41f18499 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -602,6 +602,18 @@ func TestChart_CreateInstallParams(t *testing.T) { assert.NotEqual(t, "simple-deployment", release) } +func TestChart_CreateInstallParams_LongChartDir(t *testing.T) { + // Helm rejects release names longer than 53 characters, while Kubernetes + // allows namespaces of up to 63. + chrt := &Chart{path: "charts/" + strings.Repeat("a", 60), yaml: &util.ChartYaml{Name: "long"}} + + release, namespace := chrt.CreateInstallParams("", "") + assert.LessOrEqual(t, len(release), 53) + assert.LessOrEqual(t, len(namespace), 63) + assert.Regexp(t, `-[0-9a-z]{10}$`, release) + assert.Regexp(t, `-[0-9a-z]{10}$`, namespace) +} + func TestInstallChart_SkipsLibraryChart(t *testing.T) { chrt, err := NewChart("testdata/library_chart") assert.Nil(t, err)