Skip to content

Commit 5813ca9

Browse files
committed
Fix invalid ConfigMap key translation
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.
1 parent 3212635 commit 5813ca9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

pkg/configmap/configmap_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewConfigMapLoaderWithClient(configMapName, namespace, manifestsDir string,
6767
}
6868

6969
func TranslateInvalidChars(input string) string {
70-
validConfigMapKey := unallowedKeyChars.ReplaceAllString(input, "~")
70+
validConfigMapKey := unallowedKeyChars.ReplaceAllString(input, "-")
7171
return validConfigMapKey
7272
}
7373

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package configmap
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestTranslateInvalidChars(t *testing.T) {
8+
t.Parallel()
9+
10+
tt := []struct {
11+
name string
12+
input string
13+
expectedOutput string
14+
}{
15+
{
16+
name: "identity when there're no invalid characters",
17+
input: "foo-bar.yaml",
18+
expectedOutput: "foo-bar.yaml",
19+
},
20+
{
21+
name: "input having invalid character",
22+
input: "foo:bar.yaml",
23+
expectedOutput: "foo-bar.yaml",
24+
},
25+
}
26+
27+
for _, tc := range tt {
28+
t.Run(tc.name, func(t *testing.T) {
29+
t.Parallel()
30+
31+
got := TranslateInvalidChars(tc.input)
32+
if tc.expectedOutput != got {
33+
t.Errorf("expected %s, got %s", tc.expectedOutput, got)
34+
}
35+
36+
if unallowedKeyChars.MatchString(got) {
37+
t.Errorf("translated output %q contains invalid characters", got)
38+
}
39+
})
40+
}
41+
}

0 commit comments

Comments
 (0)