mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #5786 from fgrzadkowski/better_errors
Add validation error explanation for long annotations.
This commit is contained in:
commit
282f605241
@ -71,13 +71,10 @@ func ValidateAnnotations(annotations map[string]string, field string) errs.Valid
|
|||||||
if !util.IsQualifiedName(strings.ToLower(k)) {
|
if !util.IsQualifiedName(strings.ToLower(k)) {
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid(field, k, qualifiedNameErrorMsg))
|
allErrs = append(allErrs, errs.NewFieldInvalid(field, k, qualifiedNameErrorMsg))
|
||||||
}
|
}
|
||||||
if !util.IsValidAnnotationValue(v) {
|
|
||||||
allErrs = append(allErrs, errs.NewFieldInvalid(field, k, ""))
|
|
||||||
}
|
|
||||||
totalSize += (int64)(len(k)) + (int64)(len(v))
|
totalSize += (int64)(len(k)) + (int64)(len(v))
|
||||||
}
|
}
|
||||||
if totalSize > (int64)(totalAnnotationSizeLimitB) {
|
if totalSize > (int64)(totalAnnotationSizeLimitB) {
|
||||||
allErrs = append(allErrs, errs.NewFieldTooLong("annotations", ""))
|
allErrs = append(allErrs, errs.NewFieldTooLong(field, "", totalAnnotationSizeLimitB))
|
||||||
}
|
}
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ var _ error = &ValidationError{}
|
|||||||
func (v *ValidationError) Error() string {
|
func (v *ValidationError) Error() string {
|
||||||
var s string
|
var s string
|
||||||
switch v.Type {
|
switch v.Type {
|
||||||
case ValidationErrorTypeRequired:
|
case ValidationErrorTypeRequired, ValidationErrorTypeTooLong:
|
||||||
s = spew.Sprintf("%s: %s", v.Field, v.Type)
|
s = spew.Sprintf("%s: %s", v.Field, v.Type)
|
||||||
default:
|
default:
|
||||||
s = spew.Sprintf("%s: %s '%+v'", v.Field, v.Type, v.BadValue)
|
s = spew.Sprintf("%s: %s '%+v'", v.Field, v.Type, v.BadValue)
|
||||||
@ -133,8 +133,8 @@ func NewFieldNotFound(field string, value interface{}) *ValidationError {
|
|||||||
return &ValidationError{ValidationErrorTypeNotFound, field, value, ""}
|
return &ValidationError{ValidationErrorTypeNotFound, field, value, ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFieldTooLong(field string, value interface{}) *ValidationError {
|
func NewFieldTooLong(field string, value interface{}, maxLength int) *ValidationError {
|
||||||
return &ValidationError{ValidationErrorTypeTooLong, field, value, ""}
|
return &ValidationError{ValidationErrorTypeTooLong, field, value, fmt.Sprintf("must have at most %d characters", maxLength)}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValidationErrorList []error
|
type ValidationErrorList []error
|
||||||
|
@ -33,11 +33,6 @@ func IsValidLabelValue(value string) bool {
|
|||||||
return (len(value) <= LabelValueMaxLength && labelValueRegexp.MatchString(value))
|
return (len(value) <= LabelValueMaxLength && labelValueRegexp.MatchString(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotation values are opaque.
|
|
||||||
func IsValidAnnotationValue(value string) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
const QualifiedNameFmt string = "(" + qnameTokenFmt + "/)?" + qnameTokenFmt
|
const QualifiedNameFmt string = "(" + qnameTokenFmt + "/)?" + qnameTokenFmt
|
||||||
const QualifiedNameMaxLength int = 253
|
const QualifiedNameMaxLength int = 253
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user