terraform/builtin/providers/kubernetes/validators.go

61 lines
1.4 KiB
Go

package kubernetes
import (
"fmt"
"strings"
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
}