2024-07-09 17:08:13 -05:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
2024-07-18 09:47:47 -05:00
|
|
|
var validNameCharPattern = `a-zA-Z0-9\-\_\.`
|
2024-07-09 17:08:13 -05:00
|
|
|
var validNamePattern = regexp.MustCompile(`^[` + validNameCharPattern + `]*$`).MatchString
|
|
|
|
|
|
|
|
func validateName(name string) error {
|
|
|
|
if len(name) < 2 {
|
|
|
|
return fmt.Errorf("name is too short")
|
|
|
|
}
|
|
|
|
if len(name) > 64 {
|
|
|
|
return fmt.Errorf("name is too long")
|
|
|
|
}
|
|
|
|
if !validNamePattern(name) {
|
|
|
|
return fmt.Errorf("name includes invalid characters")
|
|
|
|
}
|
|
|
|
// In standard k8s, it must not start with a number
|
|
|
|
// however that would force us to update many many many existing resources
|
|
|
|
// so we will be slightly more lenient than standard k8s
|
|
|
|
return nil
|
|
|
|
}
|