mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 14:32:52 +08:00

* resource-api: Loosen name validation to match K8s requirements This patch modifies some of the requirements for name validation of objects in Resource API to match Kubernetes. The limit we have on characters in name is 64, but some resources allow upto 253 characters. Similarly we also include `:` in the regex, as many objects in default K8s setup use it in the name (the group `system:masters` for example) Signed-off-by: Prem Kumar <prem.saraswat@grafana.com> * Update the name column length in migrator and update e2e test to verify --------- Signed-off-by: Prem Kumar <prem.saraswat@grafana.com>
25 lines
668 B
Go
25 lines
668 B
Go
package resource
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
var validNameCharPattern = `a-zA-Z0-9:\-\_\.`
|
|
var validNamePattern = regexp.MustCompile(`^[` + validNameCharPattern + `]*$`).MatchString
|
|
|
|
func validateName(name string) *ErrorResult {
|
|
if len(name) == 0 {
|
|
return NewBadRequestError("name is too short")
|
|
}
|
|
if len(name) > 253 {
|
|
return NewBadRequestError("name is too long")
|
|
}
|
|
if !validNamePattern(name) {
|
|
return NewBadRequestError("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
|
|
}
|