Merge pull request #18423 from tombenner/improve_label_validation_error_messages

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-12-16 14:08:21 -08:00
commit 91ef756bea

View File

@ -675,8 +675,8 @@ func (p *Parser) parseExactValue() (sets.String, error) {
// <value-set> ::= "(" <values> ")" // <value-set> ::= "(" <values> ")"
// <values> ::= VALUE | VALUE "," <values> // <values> ::= VALUE | VALUE "," <values>
// <exact-match-restriction> ::= ["="|"=="|"!="] VALUE // <exact-match-restriction> ::= ["="|"=="|"!="] VALUE
// KEY is a sequence of one or more characters following [ DNS_SUBDOMAIN "/" ] DNS_LABEL // 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 64 character. // VALUE is a sequence of zero or more characters "([A-Za-z0-9_-\.])". Max length is 63 characters.
// Delimiter is white space: (' ', '\t') // Delimiter is white space: (' ', '\t')
// Example of valid syntax: // Example of valid syntax:
// "x in (foo,,baz),y,z notin ()" // "x in (foo,,baz),y,z notin ()"
@ -701,7 +701,8 @@ func Parse(selector string) (Selector, error) {
return nil, 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 { func validateLabelKey(k string) error {
if !validation.IsQualifiedName(k) { if !validation.IsQualifiedName(k) {
@ -712,8 +713,7 @@ func validateLabelKey(k string) error {
func validateLabelValue(v string) error { func validateLabelValue(v string) error {
if !validation.IsValidLabelValue(v) { if !validation.IsValidLabelValue(v) {
//FIXME: this is not the right regex! return fmt.Errorf("invalid label value: %s", labelValueErrorMsg)
return fmt.Errorf("invalid label value: %s", qualifiedNameErrorMsg)
} }
return nil return nil
} }