Skip to content

Commit 343d0a9

Browse files
committed
add validateNamespaceName
Signed-off-by: Mike Interlandi <[email protected]>
1 parent 3d9d726 commit 343d0a9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pkg/cmd/namespace/common.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
package namespace
1818

19-
import "strings"
19+
import (
20+
"strings"
21+
"unicode"
22+
"errors"
23+
)
2024

2125
func objectWithLabelArgs(args []string) map[string]string {
2226
if len(args) >= 1 {
@@ -39,3 +43,18 @@ func labelArgs(labelStrings []string) map[string]string {
3943

4044
return labels
4145
}
46+
47+
func validateNamespaceName(name string) error {
48+
for _, c := range(name) {
49+
if (
50+
c == ' ' ||
51+
unicode.IsLower(c) ||
52+
unicode.IsNumber(c)) {
53+
continue
54+
}
55+
56+
return errors.New("invalid namespace name - use only lowercase alphanumeric characters and hyphens")
57+
}
58+
59+
return nil
60+
}

0 commit comments

Comments
 (0)