74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
|
apiValidation "k8s.io/kubernetes/pkg/api/validation"
|
|
utilValidation "k8s.io/kubernetes/pkg/util/validation"
|
|
)
|
|
|
|
func validateAnnotations(value interface{}, key string) (ws []string, es []error) {
|
|
m := value.(map[string]interface{})
|
|
for k, _ := range m {
|
|
errors := utilValidation.IsQualifiedName(strings.ToLower(k))
|
|
if len(errors) > 0 {
|
|
for _, e := range errors {
|
|
es = append(es, fmt.Errorf("%s (%q) %s", key, k, e))
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func validateName(value interface{}, key string) (ws []string, es []error) {
|
|
v := value.(string)
|
|
|
|
errors := apiValidation.NameIsDNSLabel(v, false)
|
|
if len(errors) > 0 {
|
|
for _, err := range errors {
|
|
es = append(es, fmt.Errorf("%s %s", key, err))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func validateGenerateName(value interface{}, key string) (ws []string, es []error) {
|
|
v := value.(string)
|
|
|
|
errors := apiValidation.NameIsDNSLabel(v, true)
|
|
if len(errors) > 0 {
|
|
for _, err := range errors {
|
|
es = append(es, fmt.Errorf("%s %s", key, err))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func validateLabels(value interface{}, key string) (ws []string, es []error) {
|
|
m := value.(map[string]interface{})
|
|
for k, v := range m {
|
|
for _, msg := range utilValidation.IsQualifiedName(k) {
|
|
es = append(es, fmt.Errorf("%s (%q) %s", key, k, msg))
|
|
}
|
|
val := v.(string)
|
|
for _, msg := range utilValidation.IsValidLabelValue(val) {
|
|
es = append(es, fmt.Errorf("%s (%q) %s", key, val, msg))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func validateResourceList(value interface{}, key string) (ws []string, es []error) {
|
|
m := value.(map[string]interface{})
|
|
for k, v := range m {
|
|
val := v.(string)
|
|
_, err := resource.ParseQuantity(val)
|
|
if err != nil {
|
|
es = append(es, fmt.Errorf("%s.%s (%q): %s", key, k, val, err))
|
|
}
|
|
}
|
|
return
|
|
}
|