Skip to content

Commit 8e5163e

Browse files
jkatzJonathan S. Katz
authored andcommitted
Allow for the existence of no labels when creating a cluster
This fell on the trap of the "empty string being split", which by default creates a single entry in an array. As an empty string is not a valid label, this would fail on the default command.
1 parent 54c8437 commit 8e5163e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/apiserver/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func IsValidPVC(pvcName, ns string) bool {
131131
func ValidateLabel(labelStr string) (map[string]string, error) {
132132
labelMap := map[string]string{}
133133

134+
// if this is an empty string, return
135+
if strings.TrimSpace(labelStr) == "" {
136+
return labelMap, nil
137+
}
138+
134139
for _, v := range strings.Split(labelStr, ",") {
135140
pair := strings.Split(v, "=")
136141
if len(pair) != 2 {

internal/apiserver/common_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ func TestValidateLabel(t *testing.T) {
3030
map[string]string{"key": "value"},
3131
map[string]string{"example.com/key": "value"},
3232
map[string]string{"key1": "value1", "key2": "value2"},
33+
map[string]string{"": ""},
3334
}
3435

3536
for _, input := range inputs {
3637
labelStr := ""
3738

3839
for k, v := range input {
40+
if k == "" && v == "" {
41+
continue
42+
}
43+
3944
labelStr += fmt.Sprintf("%s=%s,", k, v)
4045
}
4146

0 commit comments

Comments
 (0)