diff --git a/pkg/apis/batch/validation/validation.go b/pkg/apis/batch/validation/validation.go index 0f83ac28d3c..bcce6089a23 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.TooLongMaxLength(fldPath.Child("managedBy"), *spec.ManagedBy, maxManagedByLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), "" /*unused*/, 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, "" /*unused*/, maxJobSuccessPolicySucceededIndexesLimit)) } var err error if totalIndexes, err = validateIndexesFormat(*rule.SucceededIndexes, *spec.Completions); err != nil { diff --git a/pkg/apis/batch/validation/validation_test.go b/pkg/apis/batch/validation/validation_test.go index 64c50e50318..3f23cf0ae3c 100644 --- a/pkg/apis/batch/validation/validation_test.go +++ b/pkg/apis/batch/validation/validation_test.go @@ -436,7 +436,7 @@ func TestValidateJob(t *testing.T) { opts JobValidationOptions job batch.Job }{ - `spec.managedBy: Too long: may not be longer than 63`: { + `spec.managedBy: Too long: may not be more than 63 bytes`: { opts: JobValidationOptions{RequirePrefixedLabels: true}, job: batch.Job{ ObjectMeta: validJobObjectMeta, @@ -519,7 +519,7 @@ func TestValidateJob(t *testing.T) { }, opts: JobValidationOptions{RequirePrefixedLabels: true}, }, - `spec.successPolicy.rules[0].succeededIndexes: Too long: must have at most 65536 bytes`: { + `spec.successPolicy.rules[0].succeededIndexes: Too long: may not be more than 65536 bytes`: { job: batch.Job{ ObjectMeta: validJobObjectMeta, Spec: batch.JobSpec{ diff --git a/pkg/apis/certificates/validation/validation.go b/pkg/apis/certificates/validation/validation.go index 841844dc65b..750a9748e40 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, "" /*unused*/, certificates.MaxTrustBundleSize)) return allErrors } diff --git a/pkg/apis/certificates/validation/validation_test.go b/pkg/apis/certificates/validation/validation_test.go index 19f694ce7d8..8e2751876b0 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"), "" /*unused*/, 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"), "" /*unused*/, 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"), "" /*unused*/, core.MaxSecretSize), }, }, { diff --git a/pkg/apis/core/validation/names.go b/pkg/apis/core/validation/names.go index 398a1cb3a2c..fd9779779a5 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, "" /*unused*/, 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, "" /*unused*/, maxSignerNameLength)) } return el diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index 031f4494f51..511429c6c3f 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, "" /*unused*/, 63)) } for _, msg := range validation.IsDNS1123Subdomain(strings.ToLower(driverName)) { @@ -4772,7 +4772,7 @@ func ValidateAppArmorProfileField(profile *core.AppArmorProfile, fldPath *field. const maxLocalhostProfileLength = 4095 // PATH_MAX - 1 if len(*profile.LocalhostProfile) > maxLocalhostProfileLength { - allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("localhostProfile"), *profile.LocalhostProfile, maxLocalhostProfileLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), "" /*unused*/, maxLocalhostProfileLength)) } } @@ -6589,7 +6589,7 @@ func ValidateSecret(secret *core.Secret) field.ErrorList { totalSize += len(value) } if totalSize > core.MaxSecretSize { - allErrs = append(allErrs, field.TooLong(dataPath, "", core.MaxSecretSize)) + allErrs = append(allErrs, field.TooLong(dataPath, "" /*unused*/, core.MaxSecretSize)) } switch secret.Type { @@ -6704,7 +6704,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(""), "" /*unused*/, core.MaxSecretSize)) } return allErrs diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go index 6adb7d1892b..b3c9306f22d 100644 --- a/pkg/apis/core/validation/validation_test.go +++ b/pkg/apis/core/validation/validation_test.go @@ -11928,7 +11928,7 @@ func TestValidatePod(t *testing.T) { ), }, "too long AppArmor localhost profile": { - expectedError: "Too long: may not be longer than 4095", + expectedError: "Too long: may not be more than 4095 bytes", spec: *podtest.MakePod("123", podtest.SetSecurityContext(&core.PodSecurityContext{ AppArmorProfile: &core.AppArmorProfile{ diff --git a/pkg/apis/networking/validation/validation.go b/pkg/apis/networking/validation/validation.go index 0750851dd85..f41ba5f3826 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"), "" /*unused*/, 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/networking/validation/validation_test.go b/pkg/apis/networking/validation/validation_test.go index c59b1a1ef09..bb1f579a211 100644 --- a/pkg/apis/networking/validation/validation_test.go +++ b/pkg/apis/networking/validation/validation_test.go @@ -1455,7 +1455,7 @@ func TestValidateIngressClass(t *testing.T) { }, "valid name, controller too long": { ingressClass: makeValidIngressClass("test123", "foo.co/"+strings.Repeat("a", 244)), - expectedErrs: field.ErrorList{field.TooLong(field.NewPath("spec.controller"), "", 250)}, + expectedErrs: field.ErrorList{field.TooLong(field.NewPath("spec.controller"), "" /*unused*/, 250)}, }, "valid name, valid controller, valid params": { ingressClass: makeValidIngressClass("test123", "foo.co/bar", diff --git a/pkg/apis/resource/validation/validation.go b/pkg/apis/resource/validation/validation.go index d451f3912c8..c5917acf415 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.TooLongMaxLength(fldPath, name, resource.PoolNameMaxLength)) + allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, 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.TooLongMaxLength(fldPath.Child("expression"), "", resource.CELSelectorExpressionMaxLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "" /*unused*/, 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.TooLongMaxLength(fldPath.Child("string"), *attribute.StringValue, resource.DeviceAttributeMaxValueLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), "" /*unused*/, 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.TooLongMaxLength(fldPath.Child("version"), *attribute.VersionValue, resource.DeviceAttributeMaxValueLength)) + allErrs = append(allErrs, field.TooLong(fldPath.Child("version"), "" /*unused*/, 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.TooLongMaxLength(fldPath, id, resource.DeviceMaxIDLength)) + allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, resource.DeviceMaxIDLength)) } for _, msg := range validation.IsCIdentifier(id) { allErrs = append(allErrs, field.TypeInvalid(fldPath, id, msg)) @@ -649,7 +649,7 @@ func validateSlice[T any](slice []T, maxSize int, validateItem func(T, *field.Pa // Dumping the entire field into the error message is likely to be too long, // in particular when it is already beyond the maximum size. Instead this // just shows the number of entries. - allErrs = append(allErrs, field.TooLongMaxLength(fldPath, len(slice), maxSize)) + allErrs = append(allErrs, field.TooMany(fldPath, len(slice), maxSize)) } return allErrs } @@ -685,7 +685,7 @@ func stringKey(item string) (string, string) { func validateMap[K ~string, T any](m map[K]T, maxSize int, validateKey func(K, *field.Path) field.ErrorList, validateItem func(T, *field.Path) field.ErrorList, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList if maxSize >= 0 && len(m) > maxSize { - allErrs = append(allErrs, field.TooLongMaxLength(fldPath, len(m), maxSize)) + allErrs = append(allErrs, field.TooMany(fldPath, len(m), maxSize)) } for key, item := range m { allErrs = append(allErrs, validateKey(key, fldPath)...) diff --git a/pkg/apis/resource/validation/validation_resourceclaim_test.go b/pkg/apis/resource/validation/validation_resourceclaim_test.go index 516fa6f9dfc..c8fc7cdb88a 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.TooLongMaxLength(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"), "" /*unused*/, resource.CELSelectorExpressionMaxLength), }, claim: func() *resource.ResourceClaim { claim := testClaim(goodName, goodNS, validClaimSpec) @@ -552,7 +552,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) { }, }, "invalid-reserved-for-too-large": { - wantFailures: field.ErrorList{field.TooLongMaxLength(field.NewPath("status", "reservedFor"), resource.ResourceClaimReservedForMaxSize+1, resource.ResourceClaimReservedForMaxSize)}, + wantFailures: field.ErrorList{field.TooMany(field.NewPath("status", "reservedFor"), resource.ResourceClaimReservedForMaxSize+1, resource.ResourceClaimReservedForMaxSize)}, oldClaim: validAllocatedClaim, update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { for i := 0; i < resource.ResourceClaimReservedForMaxSize+1; i++ { diff --git a/pkg/apis/storage/validation/validation.go b/pkg/apis/storage/validation/validation.go index 035650da47f..3e83d2eb4f4 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, "" /*unused*/, maxProvisionerParameterLen)) return allErrs } @@ -112,7 +112,7 @@ func validateParameters(params map[string]string, allowEmpty bool, fldPath *fiel } if totalSize > maxProvisionerParameterSize { - allErrs = append(allErrs, field.TooLong(fldPath, "", maxProvisionerParameterSize)) + allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, maxProvisionerParameterSize)) } if !allowEmpty && len(params) == 0 { @@ -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, "" /*unused*/, 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"), "" /*unused*/, maxAttachedVolumeMetadataSize)) } return allErrs } diff --git a/pkg/apis/storagemigration/validation/validation.go b/pkg/apis/storagemigration/validation/validation.go index 39ea8cfbd3e..01f6d69b7e1 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"), "" /*unused*/, 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"), "" /*unused*/, 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 d593799ee82..d9e3a217dd6 100644 --- a/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go +++ b/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go @@ -374,14 +374,14 @@ 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(""), "" /*unused*/, corev1.MaxSecretSize)}) }) client.PrependReactor("delete", "configmaps", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) { return true, nil, nil }) err := writeConfigMap(client.CoreV1(), cm) - if err == nil || err.Error() != `ConfigMap "extension-apiserver-authentication" is invalid: []: Too long: must have at most 1048576 bytes` { + if err == nil || err.Error() != `ConfigMap "extension-apiserver-authentication" is invalid: []: Too long: may not be more than 1048576 bytes` { t.Fatal(err) } if len(client.Actions()) != 2 { 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 7304018fb34..85f1ffca7fd 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.TooLongMaxLength(errPath, value, int(max))) + allErrs = append(allErrs, field.TooLong(errPath, "" /*unused*/, int(max))) case openapierrors.MaxItemsFailCode: actual := int64(-1) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go index d1b9da2e5df..27a10f4dc05 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/validation_test.go @@ -594,7 +594,7 @@ func TestValidateCustomResource(t *testing.T) { }, failingObjects: []failingObject{ {object: map[string]interface{}{"fieldX": "abc"}, expectErrs: []string{ - `fieldX: Too long: may not be longer than 2`, + `fieldX: Too long: may not be more than 2 bytes`, }}, }, }, diff --git a/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go b/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go index 593d7ba8cf7..54a2883a35d 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go @@ -50,7 +50,7 @@ func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) fie } } if err := ValidateAnnotationsSize(annotations); err != nil { - allErrs = append(allErrs, field.TooLong(fldPath, "", TotalAnnotationSizeLimitB)) + allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, TotalAnnotationSizeLimitB)) } return allErrs } 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..ba61ddc8bac 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, "" /*unused*/, 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"), "" /*unused*/, 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"), "" /*unused*/, 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"), "" /*unused*/, 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 bc387d01163..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,26 +220,24 @@ 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. +// 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 { - return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d bytes", maxLength)} -} - -// TooLongMaxLength 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, no max length will be included in the message. -func TooLongMaxLength(field *Path, value interface{}, maxLength int) *Error { var msg string if maxLength >= 0 { - msg = fmt.Sprintf("may not be longer than %d", maxLength) + msg = fmt.Sprintf("may not be more than %d bytes", maxLength) } 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". +// Deprecated: Use TooLong instead. +func TooLongMaxLength(field *Path, value interface{}, maxLength int) *Error { + return TooLong(field, "", maxLength) } // TooMany returns a *Error indicating "too many". This is used to diff --git a/test/integration/controlplane/synthetic_controlplane_test.go b/test/integration/controlplane/synthetic_controlplane_test.go index c5f661df736..615b35e62ed 100644 --- a/test/integration/controlplane/synthetic_controlplane_test.go +++ b/test/integration/controlplane/synthetic_controlplane_test.go @@ -338,7 +338,7 @@ func TestObjectSizeResponses(t *testing.T) { expectedMsgFor1MB := `etcdserver: request is too large` expectedMsgFor2MB := `rpc error: code = ResourceExhausted desc = trying to send message larger than max` expectedMsgFor3MB := `Request entity too large: limit is 3145728` - expectedMsgForLargeAnnotation := `metadata.annotations: Too long: must have at most 262144 bytes` + expectedMsgForLargeAnnotation := `metadata.annotations: Too long: may not be more than 262144 bytes` deployment1 := constructBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DeploymentMegabyteSize, "labels", t) // >1.5 MB file deployment2 := constructBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DeploymentTwoMegabyteSize, "labels", t) // >2 MB file