1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-01 15:18:20 +00:00

DnsLabelRestricted type to validate against RFC 1035

k8s uses restricted format for services

dnsLabelRestricted: dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
dnsLabel:dns1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
This commit is contained in:
Alena Prokharchyk
2018-05-29 14:34:53 -07:00
committed by Darren Shepherd
parent df1aea6651
commit e03c72e855
2 changed files with 14 additions and 0 deletions

View File

@@ -272,6 +272,18 @@ func (b *Builder) convert(fieldType string, value interface{}, op Operation) (in
}
}
return str, nil
case "dnsLabelRestricted":
str := convert.ToString(value)
if str == "" {
return "", nil
}
if op == Create || op == Update {
if errs := validation.IsDNS1035Label(str); len(errs) != 0 {
return value, httperror.NewAPIError(httperror.InvalidFormat, fmt.Sprintf("invalid value %s: %s", value,
strings.Join(errs, ",")))
}
}
return str, nil
case "hostname":
str := convert.ToString(value)
if str == "" {