From 5813ca963326cf27c404e0c679b34a2ab0f5ab30 Mon Sep 17 00:00:00 2001 From: Maciej Zimnoch Date: Fri, 8 Aug 2025 15:46:59 +0200 Subject: [PATCH] Fix invalid ConfigMap key translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When generating ConfigMap keys from OLM bundle filenames, colons (`:`) were being replaced with tildes (`~`). However, `~` is not a valid character for ConfigMap keys, leading to errors like: ``` binaryData[scylladb~controller~aggregate-to-operator_rbac.authorization.k8s.io_v1_clusterrole.yaml]: Invalid value: "...": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (regex: '[-._a-zA-Z0-9]+') ``` This commit fixes the issue by replacing `:` with hyphens (`-`) instead, which are allowed in ConfigMap keys. For example: * Before: `scylladb:controller:aggregate-to-operator...` → `scylladb~controller~aggregate-to-operator...` (invalid) * After: `scylladb:controller:aggregate-to-operator...` → `scylladb-controller-aggregate-to-operator...` (valid) This ensures all generated ConfigMap keys conform to Kubernetes naming requirements. --- pkg/configmap/configmap_writer.go | 2 +- pkg/configmap/configmap_writer_test.go | 41 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 pkg/configmap/configmap_writer_test.go diff --git a/pkg/configmap/configmap_writer.go b/pkg/configmap/configmap_writer.go index 1ee4ff917..11846fad5 100644 --- a/pkg/configmap/configmap_writer.go +++ b/pkg/configmap/configmap_writer.go @@ -67,7 +67,7 @@ func NewConfigMapLoaderWithClient(configMapName, namespace, manifestsDir string, } func TranslateInvalidChars(input string) string { - validConfigMapKey := unallowedKeyChars.ReplaceAllString(input, "~") + validConfigMapKey := unallowedKeyChars.ReplaceAllString(input, "-") return validConfigMapKey } diff --git a/pkg/configmap/configmap_writer_test.go b/pkg/configmap/configmap_writer_test.go new file mode 100644 index 000000000..d91a3b333 --- /dev/null +++ b/pkg/configmap/configmap_writer_test.go @@ -0,0 +1,41 @@ +package configmap + +import ( + "testing" +) + +func TestTranslateInvalidChars(t *testing.T) { + t.Parallel() + + tt := []struct { + name string + input string + expectedOutput string + }{ + { + name: "identity when there're no invalid characters", + input: "foo-bar.yaml", + expectedOutput: "foo-bar.yaml", + }, + { + name: "input having invalid character", + input: "foo:bar.yaml", + expectedOutput: "foo-bar.yaml", + }, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + got := TranslateInvalidChars(tc.input) + if tc.expectedOutput != got { + t.Errorf("expected %s, got %s", tc.expectedOutput, got) + } + + if unallowedKeyChars.MatchString(got) { + t.Errorf("translated output %q contains invalid characters", got) + } + }) + } +}