diff --git a/pkg/apis/batch/validation/validation.go b/pkg/apis/batch/validation/validation.go index 86b80394cce..945094c20ed 100644 --- a/pkg/apis/batch/validation/validation.go +++ b/pkg/apis/batch/validation/validation.go @@ -218,7 +218,7 @@ func validateJobSpec(spec *batch.JobSpec, fldPath *field.Path, opts apivalidatio if spec.ManagedBy != nil { allErrs = append(allErrs, apimachineryvalidation.IsDomainPrefixedPath(fldPath.Child("managedBy"), *spec.ManagedBy)...) if len(*spec.ManagedBy) > maxManagedByLength { - allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), *spec.ManagedBy, maxManagedByLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), "", maxManagedByLength)) } } if spec.CompletionMode != nil { @@ -435,7 +435,7 @@ func validateSuccessPolicyRule(spec *batch.JobSpec, rule *batch.SuccessPolicyRul if rule.SucceededIndexes != nil { succeededIndexes := rulePath.Child("succeededIndexes") if len(*rule.SucceededIndexes) > maxJobSuccessPolicySucceededIndexesLimit { - allErrs = append(allErrs, field.TooLong(succeededIndexes, *rule.SucceededIndexes, maxJobSuccessPolicySucceededIndexesLimit)) + allErrs = append(allErrs, field.TooLong(succeededIndexes, "", maxJobSuccessPolicySucceededIndexesLimit)) } var err error if totalIndexes, err = validateIndexesFormat(*rule.SucceededIndexes, *spec.Completions); err != nil { diff --git a/pkg/apis/certificates/validation/validation.go b/pkg/apis/certificates/validation/validation.go index 841844dc65b..32d7b2ca8f3 100644 --- a/pkg/apis/certificates/validation/validation.go +++ b/pkg/apis/certificates/validation/validation.go @@ -509,7 +509,7 @@ func validateTrustBundle(path *field.Path, in string) field.ErrorList { var allErrors field.ErrorList if len(in) > certificates.MaxTrustBundleSize { - allErrors = append(allErrors, field.TooLong(path, fmt.Sprintf("", len(in)), certificates.MaxTrustBundleSize)) + allErrors = append(allErrors, field.TooLong(path, "", certificates.MaxTrustBundleSize)) return allErrors } diff --git a/pkg/apis/certificates/validation/validation_test.go b/pkg/apis/certificates/validation/validation_test.go index 19f694ce7d8..a838fc903b4 100644 --- a/pkg/apis/certificates/validation/validation_test.go +++ b/pkg/apis/certificates/validation/validation_test.go @@ -206,7 +206,7 @@ func TestValidateCertificateSigningRequestCreate(t *testing.T) { }, }, errs: field.ErrorList{ - field.TooLong(specPath.Child("signerName"), maxLengthSignerName+".toolong", len(maxLengthSignerName)), + field.TooLong(specPath.Child("signerName"), "", len(maxLengthSignerName)), }, }, "signerName with a fqdn greater than 253 characters should be rejected": { @@ -220,7 +220,7 @@ func TestValidateCertificateSigningRequestCreate(t *testing.T) { }, }, errs: field.ErrorList{ - field.TooLong(specPath.Child("signerName"), fmt.Sprintf("%s.extra", maxLengthFQDN), len(maxLengthFQDN)), + field.TooLong(specPath.Child("signerName"), "", len(maxLengthFQDN)), }, }, "signerName can have a longer path if the domain component is less than the max length": { @@ -1137,7 +1137,7 @@ func TestValidateClusterTrustBundle(t *testing.T) { }, }, wantErrors: field.ErrorList{ - field.TooLong(field.NewPath("spec", "trustBundle"), fmt.Sprintf("", len(badTooBigBundle)), core.MaxSecretSize), + field.TooLong(field.NewPath("spec", "trustBundle"), "", core.MaxSecretSize), }, }, { diff --git a/pkg/apis/core/validation/names.go b/pkg/apis/core/validation/names.go index 398a1cb3a2c..35722ed3d8d 100644 --- a/pkg/apis/core/validation/names.go +++ b/pkg/apis/core/validation/names.go @@ -54,7 +54,7 @@ func ValidateSignerName(fldPath *field.Path, signerName string) field.ErrorList // validate that segments[0] is less than 253 characters altogether maxDomainSegmentLength := validation.DNS1123SubdomainMaxLength if len(segments[0]) > maxDomainSegmentLength { - el = append(el, field.TooLong(fldPath, segments[0], maxDomainSegmentLength)) + el = append(el, field.TooLong(fldPath, "", maxDomainSegmentLength)) } // validate that segments[0] consists of valid DNS1123 labels separated by '.' domainLabels := strings.Split(segments[0], ".") @@ -97,7 +97,7 @@ func ValidateSignerName(fldPath *field.Path, signerName string) field.ErrorList maxPathSegmentLength := validation.DNS1123SubdomainMaxLength + validation.DNS1123LabelMaxLength + 1 maxSignerNameLength := maxDomainSegmentLength + maxPathSegmentLength + 1 if len(signerName) > maxSignerNameLength { - el = append(el, field.TooLong(fldPath, signerName, maxSignerNameLength)) + el = append(el, field.TooLong(fldPath, "", maxSignerNameLength)) } return el diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index 9cb0a614c1b..2d3aff5f95f 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -1685,7 +1685,7 @@ func ValidateCSIDriverName(driverName string, fldPath *field.Path) field.ErrorLi } if len(driverName) > 63 { - allErrs = append(allErrs, field.TooLong(fldPath, driverName, 63)) + allErrs = append(allErrs, field.TooLong(fldPath, "", 63)) } for _, msg := range validation.IsDNS1123Subdomain(strings.ToLower(driverName)) { @@ -4758,7 +4758,7 @@ func ValidateAppArmorProfileField(profile *core.AppArmorProfile, fldPath *field. const maxLocalhostProfileLength = 4095 // PATH_MAX - 1 if len(*profile.LocalhostProfile) > maxLocalhostProfileLength { - allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), *profile.LocalhostProfile, maxLocalhostProfileLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), "", maxLocalhostProfileLength)) } } @@ -6661,7 +6661,7 @@ func ValidateConfigMap(cfg *core.ConfigMap) field.ErrorList { } if totalSize > core.MaxSecretSize { // pass back "" to indicate that the error refers to the whole object. - allErrs = append(allErrs, field.TooLong(field.NewPath(""), cfg, core.MaxSecretSize)) + allErrs = append(allErrs, field.TooLong(field.NewPath(""), "", core.MaxSecretSize)) } return allErrs diff --git a/pkg/apis/networking/validation/validation.go b/pkg/apis/networking/validation/validation.go index 0750851dd85..91f381de2d0 100644 --- a/pkg/apis/networking/validation/validation.go +++ b/pkg/apis/networking/validation/validation.go @@ -526,7 +526,7 @@ func ValidateIngressClassUpdate(newIngressClass, oldIngressClass *networking.Ing func validateIngressClassSpec(spec *networking.IngressClassSpec, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if len(spec.Controller) > maxLenIngressClassController { - allErrs = append(allErrs, field.TooLong(fldPath.Child("controller"), spec.Controller, maxLenIngressClassController)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("controller"), "", maxLenIngressClassController)) } allErrs = append(allErrs, validation.IsDomainPrefixedPath(fldPath.Child("controller"), spec.Controller)...) allErrs = append(allErrs, validateIngressClassParametersReference(spec.Parameters, fldPath.Child("parameters"))...) diff --git a/pkg/apis/resource/validation/validation.go b/pkg/apis/resource/validation/validation.go index 022cbecc02f..ce519f50ebe 100644 --- a/pkg/apis/resource/validation/validation.go +++ b/pkg/apis/resource/validation/validation.go @@ -52,7 +52,7 @@ func validatePoolName(name string, fldPath *field.Path) field.ErrorList { allErrs = append(allErrs, field.Required(fldPath, "")) } else { if len(name) > resource.PoolNameMaxLength { - allErrs = append(allErrs, field.TooLong(fldPath, name, resource.PoolNameMaxLength)) + allErrs = append(allErrs, field.TooLong(fldPath, "", resource.PoolNameMaxLength)) } parts := strings.Split(name, "/") for _, part := range parts { @@ -168,7 +168,7 @@ func validateCELSelector(celSelector resource.CELDeviceSelector, fldPath *field. envType = environment.StoredExpressions } if len(celSelector.Expression) > resource.CELSelectorExpressionMaxLength { - allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "", resource.CELSelectorExpressionMaxLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "", resource.CELSelectorExpressionMaxLength)) // Don't bother compiling too long expressions. return allErrs } @@ -561,7 +561,7 @@ func validateDeviceAttribute(attribute resource.DeviceAttribute, fldPath *field. } if attribute.StringValue != nil { if len(*attribute.StringValue) > resource.DeviceAttributeMaxValueLength { - allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), *attribute.StringValue, resource.DeviceAttributeMaxValueLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), "", resource.DeviceAttributeMaxValueLength)) } numFields++ } @@ -571,7 +571,7 @@ func validateDeviceAttribute(attribute resource.DeviceAttribute, fldPath *field. allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), *attribute.VersionValue, "must be a string compatible with semver.org spec 2.0.0")) } if len(*attribute.VersionValue) > resource.DeviceAttributeMaxValueLength { - allErrs = append(allErrs, field.TooLong(fldPath.Child("version"), *attribute.VersionValue, resource.DeviceAttributeMaxValueLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("version"), "", resource.DeviceAttributeMaxValueLength)) } } @@ -628,7 +628,7 @@ func validateFullyQualifiedName(name resource.FullyQualifiedName, fldPath *field func validateCIdentifier(id string, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList if len(id) > resource.DeviceMaxIDLength { - allErrs = append(allErrs, field.TooLong(fldPath, id, resource.DeviceMaxIDLength)) + allErrs = append(allErrs, field.TooLong(fldPath, "", resource.DeviceMaxIDLength)) } for _, msg := range validation.IsCIdentifier(id) { allErrs = append(allErrs, field.TypeInvalid(fldPath, id, msg)) diff --git a/pkg/apis/resource/validation/validation_resourceclaim_test.go b/pkg/apis/resource/validation/validation_resourceclaim_test.go index ad9a7a6cb11..7e0dee03f72 100644 --- a/pkg/apis/resource/validation/validation_resourceclaim_test.go +++ b/pkg/apis/resource/validation/validation_resourceclaim_test.go @@ -322,7 +322,7 @@ func TestValidateClaim(t *testing.T) { }, "CEL-length": { wantFailures: field.ErrorList{ - field.TooLong(field.NewPath("spec", "devices", "requests").Index(1).Child("selectors").Index(1).Child("cel", "expression"), "", resource.CELSelectorExpressionMaxLength), + field.TooLong(field.NewPath("spec", "devices", "requests").Index(1).Child("selectors").Index(1).Child("cel", "expression"), "", resource.CELSelectorExpressionMaxLength), }, claim: func() *resource.ResourceClaim { claim := testClaim(goodName, goodNS, validClaimSpec) diff --git a/pkg/apis/storage/validation/validation.go b/pkg/apis/storage/validation/validation.go index 035650da47f..007553aebba 100644 --- a/pkg/apis/storage/validation/validation.go +++ b/pkg/apis/storage/validation/validation.go @@ -100,7 +100,7 @@ func validateParameters(params map[string]string, allowEmpty bool, fldPath *fiel allErrs := field.ErrorList{} if len(params) > maxProvisionerParameterLen { - allErrs = append(allErrs, field.TooLong(fldPath, "Provisioner Parameters exceeded max allowed", maxProvisionerParameterLen)) + allErrs = append(allErrs, field.TooLong(fldPath, "", maxProvisionerParameterLen)) return allErrs } @@ -223,7 +223,7 @@ func validateAttachmentMetadata(metadata map[string]string, fldPath *field.Path) size += (int64)(len(k)) + (int64)(len(v)) } if size > maxAttachedVolumeMetadataSize { - allErrs = append(allErrs, field.TooLong(fldPath, metadata, maxAttachedVolumeMetadataSize)) + allErrs = append(allErrs, field.TooLong(fldPath, "", maxAttachedVolumeMetadataSize)) } return allErrs } @@ -235,7 +235,7 @@ func validateVolumeError(e *storage.VolumeError, fldPath *field.Path) field.Erro return allErrs } if len(e.Message) > maxVolumeErrorMessageSize { - allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), e.Message, maxAttachedVolumeMetadataSize)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxAttachedVolumeMetadataSize)) } return allErrs } diff --git a/pkg/apis/storagemigration/validation/validation.go b/pkg/apis/storagemigration/validation/validation.go index 39ea8cfbd3e..3e774b5d5a8 100644 --- a/pkg/apis/storagemigration/validation/validation.go +++ b/pkg/apis/storagemigration/validation/validation.go @@ -183,13 +183,13 @@ func validateCondition(condition storagemigration.MigrationCondition, fldPath *f const maxReasonLen int = 1 * 1024 // 1024 if len(condition.Reason) > maxReasonLen { - allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), condition.Reason, maxReasonLen)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "", maxReasonLen)) } } const maxMessageLen int = 32 * 1024 // 32768 if len(condition.Message) > maxMessageLen { - allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), condition.Message, maxMessageLen)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxMessageLen)) } return allErrs diff --git a/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go b/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go index b9181104801..16a2fb4d979 100644 --- a/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go +++ b/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go @@ -374,7 +374,7 @@ func TestWriteConfigMapDeleted(t *testing.T) { t.Run("ca bundle too large", func(t *testing.T) { client := fake.NewSimpleClientset() client.PrependReactor("update", "configmaps", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) { - return true, nil, apierrors.NewInvalid(schema.GroupKind{Kind: "ConfigMap"}, cm.Name, field.ErrorList{field.TooLong(field.NewPath(""), cm, corev1.MaxSecretSize)}) + return true, nil, apierrors.NewInvalid(schema.GroupKind{Kind: "ConfigMap"}, cm.Name, field.ErrorList{field.TooLong(field.NewPath(""), "", corev1.MaxSecretSize)}) }) client.PrependReactor("delete", "configmaps", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) { return true, nil, nil diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation.go index 9c49f39841d..1b6e0daf88f 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation.go @@ -182,15 +182,11 @@ func kubeOpenAPIResultToFieldErrors(fldPath *field.Path, result *validate.Result allErrs = append(allErrs, field.NotSupported(errPath, err.Value, values)) case openapierrors.TooLongFailCode: - value := interface{}("") - if err.Value != nil { - value = err.Value - } max := int64(-1) if i, ok := err.Valid.(int64); ok { max = i } - allErrs = append(allErrs, field.TooLong(errPath, value, int(max))) + allErrs = append(allErrs, field.TooLong(errPath, "", int(max))) case openapierrors.MaxItemsFailCode: actual := int64(-1) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go index a89e65dda25..c98eb49f5fe 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go @@ -213,7 +213,7 @@ func ValidateFieldManager(fieldManager string, fldPath *field.Path) field.ErrorL // considered as not set and is defaulted by the rest of the process // (unless apply is used, in which case it is required). if len(fieldManager) > FieldManagerMaxLength { - allErrs = append(allErrs, field.TooLong(fldPath, fieldManager, FieldManagerMaxLength)) + allErrs = append(allErrs, field.TooLong(fldPath, "", FieldManagerMaxLength)) } // Verify that all characters are printable. for i, r := range fieldManager { @@ -278,7 +278,7 @@ func ValidateManagedFields(fieldsList []metav1.ManagedFieldsEntry, fldPath *fiel allErrs = append(allErrs, ValidateFieldManager(fields.Manager, fldPath.Child("manager"))...) if len(fields.Subresource) > MaxSubresourceNameLength { - allErrs = append(allErrs, field.TooLong(fldPath.Child("subresource"), fields.Subresource, MaxSubresourceNameLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("subresource"), "", MaxSubresourceNameLength)) } } return allErrs @@ -335,12 +335,12 @@ func ValidateCondition(condition metav1.Condition, fldPath *field.Path) field.Er allErrs = append(allErrs, field.Invalid(fldPath.Child("reason"), condition.Reason, currErr)) } if len(condition.Reason) > maxReasonLen { - allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), condition.Reason, maxReasonLen)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "", maxReasonLen)) } } if len(condition.Message) > maxMessageLen { - allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), condition.Message, maxMessageLen)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxMessageLen)) } return allErrs diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go index 3c2db9a32b4..f1634bc0df8 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go @@ -220,10 +220,10 @@ func Forbidden(field *Path, detail string) *Error { return &Error{ErrorTypeForbidden, field.String(), "", detail} } -// TooLong returns a *Error indicating "too long". This is used to -// report that the given value is too long. This is similar to -// Invalid, but the returned error will not include the too-long -// value. If maxLength is negative, it will be included in the message. +// TooLong returns a *Error indicating "too long". This is used to report that +// the given value is too long. This is similar to Invalid, but the returned +// error will not include the too-long value. If maxLength is negative, it will +// be included in the message. The value argument is not used. func TooLong(field *Path, value interface{}, maxLength int) *Error { var msg string if maxLength >= 0 { @@ -231,7 +231,7 @@ func TooLong(field *Path, value interface{}, maxLength int) *Error { } else { msg = "value is too long" } - return &Error{ErrorTypeTooLong, field.String(), value, msg} + return &Error{ErrorTypeTooLong, field.String(), "", msg} } // TooLongMaxLength returns a *Error indicating "too long".