Skip to content

Commit a8adcd0

Browse files
authored
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 a2a3456 commit a8adcd0

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
@@ -155,6 +155,11 @@ func IsValidPVC(pvcName, ns string) bool {
155155
func ValidateLabel(labelStr string) (map[string]string, error) {
156156
labelMap := map[string]string{}
157157

158+
// if this is an empty string, return
159+
if strings.TrimSpace(labelStr) == "" {
160+
return labelMap, nil
161+
}
162+
158163
for _, v := range strings.Split(labelStr, ",") {
159164
pair := strings.Split(v, "=")
160165
if len(pair) != 2 {

internal/apiserver/common_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ func TestValidateLabel(t *testing.T) {
7272
map[string]string{"key": "value"},
7373
map[string]string{"example.com/key": "value"},
7474
map[string]string{"key1": "value1", "key2": "value2"},
75+
map[string]string{"": ""},
7576
}
7677

7778
for _, input := range inputs {
7879
labelStr := ""
7980

8081
for k, v := range input {
82+
if k == "" && v == "" {
83+
continue
84+
}
85+
8186
labelStr += fmt.Sprintf("%s=%s,", k, v)
8287
}
8388

0 commit comments

Comments
 (0)