From cf572cd9c4a4203bfb215e0e517f4cf30c763a5c Mon Sep 17 00:00:00 2001 From: vigneshwar Date: Fri, 20 Nov 2026 17:32:48 +0530 Subject: [PATCH] fix: keep generated release names within Helm's 53 character limit CreateInstallParams truncated the generated release name to 63 characters, which is the Kubernetes namespace limit. Helm rejects release names longer than 53 characters, so charts whose directory name is longer than about 42 characters failed to install with an invalid release name error. Truncate the release name to 53 characters and keep the namespace at 63. The random suffix is at the end and is still preserved. Signed-off-by: vigneshwar --- pkg/chart/chart.go | 9 +++++++-- pkg/chart/chart_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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)