mirror of https://github.com/k3s-io/k3s
Improve label selector validations' error messages
parent
85789f319f
commit
c354c12712
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue