Improve label selector validations' error messages

pull/6/head
Tom Benner 2015-12-09 00:45:31 -08:00
parent 85789f319f
commit c354c12712
1 changed files with 5 additions and 5 deletions

View File

@ -671,8 +671,8 @@ func (p *Parser) parseExactValue() (sets.String, error) {
// <value-set> ::= "(" <values> ")"
// <values> ::= VALUE | VALUE "," <values>
// <exact-match-restriction> ::= ["="|"=="|"!="] VALUE
// KEY is a sequence of one or more characters following [ DNS_SUBDOMAIN "/" ] DNS_LABEL
// VALUE is a sequence of zero or more characters "([A-Za-z0-9_-\.])". Max length is 64 character.
// KEY is a sequence of one or more characters following [ DNS_SUBDOMAIN "/" ] DNS_LABEL. Max length is 63 characters.
// VALUE is a sequence of zero or more characters "([A-Za-z0-9_-\.])". Max length is 63 characters.
// Delimiter is white space: (' ', '\t')
// Example of valid syntax:
// "x in (foo,,baz),y,z notin ()"
@ -697,7 +697,8 @@ func Parse(selector string) (Selector, error) {
return nil, error
}
const qualifiedNameErrorMsg string = "must match regex [" + validation.DNS1123SubdomainFmt + " / ] " + validation.DNS1123LabelFmt
var qualifiedNameErrorMsg string = fmt.Sprintf(`must be a qualified name (at most %d characters, matching regex %s), with an optional DNS subdomain prefix (at most %d characters, matching regex %s) and slash (/): e.g. "MyName" or "example.com/MyName"`, validation.QualifiedNameMaxLength, validation.QualifiedNameFmt, validation.DNS1123SubdomainMaxLength, validation.DNS1123SubdomainFmt)
var labelValueErrorMsg string = fmt.Sprintf(`must have at most %d characters, matching regex %s: e.g. "MyValue" or ""`, validation.LabelValueMaxLength, validation.LabelValueFmt)
func validateLabelKey(k string) error {
if !validation.IsQualifiedName(k) {
@ -708,8 +709,7 @@ func validateLabelKey(k string) error {
func validateLabelValue(v string) error {
if !validation.IsValidLabelValue(v) {
//FIXME: this is not the right regex!
return fmt.Errorf("invalid label value: %s", qualifiedNameErrorMsg)
return fmt.Errorf("invalid label value: %s", labelValueErrorMsg)
}
return nil
}