From cef4923a58f9481cc420fe1d81a3dba873202568 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Tue, 3 Nov 2026 07:26:53 +0000 Subject: [PATCH 1/2] Count the separator in ObjectNameForBaseAndSuffix length check ObjectNameForBaseAndSuffix joins base and suffix with "-", but the truncation check compared only len(base)+len(suffix) against the 63-character limit. When the two add up to exactly 63 characters, the returned name is 64 characters long. The webhook Service name is built with this helper, so a bundle whose deployment name is 56 characters long renders a 64-character Service name, which the API server rejects. Include the separator in the length check. Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> --- internal/operator-controller/rukpak/util/util.go | 3 ++- .../operator-controller/rukpak/util/util_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/operator-controller/rukpak/util/util.go b/internal/operator-controller/rukpak/util/util.go index 067722c47e..e4ae9dd245 100644 --- a/internal/operator-controller/rukpak/util/util.go +++ b/internal/operator-controller/rukpak/util/util.go @@ -14,7 +14,8 @@ import ( const maxNameLength = 63 func ObjectNameForBaseAndSuffix(base string, suffix string) string { - if len(base)+len(suffix) > maxNameLength { + // Account for the "-" separator when checking the length. + if len(base)+len(suffix)+1 > maxNameLength { base = base[:maxNameLength-len(suffix)-1] } return fmt.Sprintf("%s-%s", base, suffix) diff --git a/internal/operator-controller/rukpak/util/util_test.go b/internal/operator-controller/rukpak/util/util_test.go index 25073f0ce4..5f48b87256 100644 --- a/internal/operator-controller/rukpak/util/util_test.go +++ b/internal/operator-controller/rukpak/util/util_test.go @@ -22,6 +22,21 @@ func Test_ObjectNameForBaseAndSuffix(t *testing.T) { require.Equal(t, "my.object.thing.has.a.really.really.really.really.really-suffix", name) } +func Test_ObjectNameForBaseAndSuffix_SeparatorCountsTowardMaxLength(t *testing.T) { + // base and suffix add up to 63 characters, so the "-" separator pushes the name to 64 + base := strings.Repeat("a", 56) + name := util.ObjectNameForBaseAndSuffix(base, "service") + require.Len(t, name, 63) + require.Equal(t, strings.Repeat("a", 55)+"-service", name) +} + +func Test_ObjectNameForBaseAndSuffix_ShortNameIsNotTruncated(t *testing.T) { + base := strings.Repeat("a", 55) + name := util.ObjectNameForBaseAndSuffix(base, "service") + require.Len(t, name, 63) + require.Equal(t, base+"-service", name) +} + func TestMergeMaps(t *testing.T) { tests := []struct { name string From 779d008ed7f5bc43279563d10274d4834a2dcde7 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Fri, 6 Nov 2026 20:46:51 +0000 Subject: [PATCH 2/2] Collapse ObjectNameForBaseAndSuffix tests into a table test Cover base and suffix lengths that add up to less than, exactly, and more than 63 characters in one table. Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> --- .../rukpak/util/util_test.go | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/internal/operator-controller/rukpak/util/util_test.go b/internal/operator-controller/rukpak/util/util_test.go index 5f48b87256..1a2923d59d 100644 --- a/internal/operator-controller/rukpak/util/util_test.go +++ b/internal/operator-controller/rukpak/util/util_test.go @@ -17,24 +17,38 @@ import ( ) func Test_ObjectNameForBaseAndSuffix(t *testing.T) { - name := util.ObjectNameForBaseAndSuffix("my.object.thing.has.a.really.really.really.really.really.long.name", "suffix") - require.Len(t, name, 63) - require.Equal(t, "my.object.thing.has.a.really.really.really.really.really-suffix", name) -} - -func Test_ObjectNameForBaseAndSuffix_SeparatorCountsTowardMaxLength(t *testing.T) { - // base and suffix add up to 63 characters, so the "-" separator pushes the name to 64 - base := strings.Repeat("a", 56) - name := util.ObjectNameForBaseAndSuffix(base, "service") - require.Len(t, name, 63) - require.Equal(t, strings.Repeat("a", 55)+"-service", name) -} - -func Test_ObjectNameForBaseAndSuffix_ShortNameIsNotTruncated(t *testing.T) { - base := strings.Repeat("a", 55) - name := util.ObjectNameForBaseAndSuffix(base, "service") - require.Len(t, name, 63) - require.Equal(t, base+"-service", name) + for _, tc := range []struct { + name string + base string + suffix string + expected string + }{ + { + name: "base and suffix add up to less than 63 characters", + base: strings.Repeat("a", 55), + suffix: "service", + expected: strings.Repeat("a", 55) + "-service", + }, + { + // the "-" separator would push the name to 64 characters + name: "base and suffix add up to 63 characters", + base: strings.Repeat("a", 56), + suffix: "service", + expected: strings.Repeat("a", 55) + "-service", + }, + { + name: "base and suffix add up to more than 63 characters", + base: "my.object.thing.has.a.really.really.really.really.really.long.name", + suffix: "suffix", + expected: "my.object.thing.has.a.really.really.really.really.really-suffix", + }, + } { + t.Run(tc.name, func(t *testing.T) { + name := util.ObjectNameForBaseAndSuffix(tc.base, tc.suffix) + require.Equal(t, tc.expected, name) + require.LessOrEqual(t, len(name), 63) + }) + } } func TestMergeMaps(t *testing.T) {