mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Convert validation to use FieldPath
Before this change we have a mish-mash of ways to pass field names around for error generation. Sometimes string fieldnames, sometimes .Prefix(), sometimes neither, often wrong names or not indexed when it should be. Instead of that mess, this is part one of a couple of commits that will make it more strongly typed and hopefully encourage correct behavior. At least you will have to think about field names, which is better than nothing. It turned out to be really hard to do this incrementally.
This commit is contained in:
@@ -701,14 +701,15 @@ const qualifiedNameErrorMsg string = "must match regex [" + validation.DNS1123Su
|
||||
|
||||
func validateLabelKey(k string) error {
|
||||
if !validation.IsQualifiedName(k) {
|
||||
return validation.NewInvalidError("label key", k, qualifiedNameErrorMsg)
|
||||
return fmt.Errorf("invalid label key: %s", qualifiedNameErrorMsg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateLabelValue(v string) error {
|
||||
if !validation.IsValidLabelValue(v) {
|
||||
return validation.NewInvalidError("label value", v, qualifiedNameErrorMsg)
|
||||
//FIXME: this is not the right regex!
|
||||
return fmt.Errorf("invalid label value: %s", qualifiedNameErrorMsg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user