Skip to content

Commit a50b4e5

Browse files
authored
Merge pull request kubernetes#128553 from thockin/master
Validation: merge TooLong and TooLongMaxLen
2 parents 5e0b818 + c8eeb48 commit a50b4e5

File tree

20 files changed

+54
-60
lines changed

20 files changed

+54
-60
lines changed

pkg/apis/batch/validation/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func validateJobSpec(spec *batch.JobSpec, fldPath *field.Path, opts apivalidatio
218218
if spec.ManagedBy != nil {
219219
allErrs = append(allErrs, apimachineryvalidation.IsDomainPrefixedPath(fldPath.Child("managedBy"), *spec.ManagedBy)...)
220220
if len(*spec.ManagedBy) > maxManagedByLength {
221-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("managedBy"), *spec.ManagedBy, maxManagedByLength))
221+
allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), "" /*unused*/, maxManagedByLength))
222222
}
223223
}
224224
if spec.CompletionMode != nil {
@@ -435,7 +435,7 @@ func validateSuccessPolicyRule(spec *batch.JobSpec, rule *batch.SuccessPolicyRul
435435
if rule.SucceededIndexes != nil {
436436
succeededIndexes := rulePath.Child("succeededIndexes")
437437
if len(*rule.SucceededIndexes) > maxJobSuccessPolicySucceededIndexesLimit {
438-
allErrs = append(allErrs, field.TooLong(succeededIndexes, *rule.SucceededIndexes, maxJobSuccessPolicySucceededIndexesLimit))
438+
allErrs = append(allErrs, field.TooLong(succeededIndexes, "" /*unused*/, maxJobSuccessPolicySucceededIndexesLimit))
439439
}
440440
var err error
441441
if totalIndexes, err = validateIndexesFormat(*rule.SucceededIndexes, *spec.Completions); err != nil {

pkg/apis/batch/validation/validation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func TestValidateJob(t *testing.T) {
436436
opts JobValidationOptions
437437
job batch.Job
438438
}{
439-
`spec.managedBy: Too long: may not be longer than 63`: {
439+
`spec.managedBy: Too long: may not be more than 63 bytes`: {
440440
opts: JobValidationOptions{RequirePrefixedLabels: true},
441441
job: batch.Job{
442442
ObjectMeta: validJobObjectMeta,
@@ -519,7 +519,7 @@ func TestValidateJob(t *testing.T) {
519519
},
520520
opts: JobValidationOptions{RequirePrefixedLabels: true},
521521
},
522-
`spec.successPolicy.rules[0].succeededIndexes: Too long: must have at most 65536 bytes`: {
522+
`spec.successPolicy.rules[0].succeededIndexes: Too long: may not be more than 65536 bytes`: {
523523
job: batch.Job{
524524
ObjectMeta: validJobObjectMeta,
525525
Spec: batch.JobSpec{

pkg/apis/certificates/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func validateTrustBundle(path *field.Path, in string) field.ErrorList {
509509
var allErrors field.ErrorList
510510

511511
if len(in) > certificates.MaxTrustBundleSize {
512-
allErrors = append(allErrors, field.TooLong(path, fmt.Sprintf("<value omitted, len %d>", len(in)), certificates.MaxTrustBundleSize))
512+
allErrors = append(allErrors, field.TooLong(path, "" /*unused*/, certificates.MaxTrustBundleSize))
513513
return allErrors
514514
}
515515

pkg/apis/certificates/validation/validation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestValidateCertificateSigningRequestCreate(t *testing.T) {
206206
},
207207
},
208208
errs: field.ErrorList{
209-
field.TooLong(specPath.Child("signerName"), maxLengthSignerName+".toolong", len(maxLengthSignerName)),
209+
field.TooLong(specPath.Child("signerName"), "" /*unused*/, len(maxLengthSignerName)),
210210
},
211211
},
212212
"signerName with a fqdn greater than 253 characters should be rejected": {
@@ -220,7 +220,7 @@ func TestValidateCertificateSigningRequestCreate(t *testing.T) {
220220
},
221221
},
222222
errs: field.ErrorList{
223-
field.TooLong(specPath.Child("signerName"), fmt.Sprintf("%s.extra", maxLengthFQDN), len(maxLengthFQDN)),
223+
field.TooLong(specPath.Child("signerName"), "" /*unused*/, len(maxLengthFQDN)),
224224
},
225225
},
226226
"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) {
11371137
},
11381138
},
11391139
wantErrors: field.ErrorList{
1140-
field.TooLong(field.NewPath("spec", "trustBundle"), fmt.Sprintf("<value omitted, len %d>", len(badTooBigBundle)), core.MaxSecretSize),
1140+
field.TooLong(field.NewPath("spec", "trustBundle"), "" /*unused*/, core.MaxSecretSize),
11411141
},
11421142
},
11431143
{

pkg/apis/core/validation/names.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func ValidateSignerName(fldPath *field.Path, signerName string) field.ErrorList
5454
// validate that segments[0] is less than 253 characters altogether
5555
maxDomainSegmentLength := validation.DNS1123SubdomainMaxLength
5656
if len(segments[0]) > maxDomainSegmentLength {
57-
el = append(el, field.TooLong(fldPath, segments[0], maxDomainSegmentLength))
57+
el = append(el, field.TooLong(fldPath, "" /*unused*/, maxDomainSegmentLength))
5858
}
5959
// validate that segments[0] consists of valid DNS1123 labels separated by '.'
6060
domainLabels := strings.Split(segments[0], ".")
@@ -97,7 +97,7 @@ func ValidateSignerName(fldPath *field.Path, signerName string) field.ErrorList
9797
maxPathSegmentLength := validation.DNS1123SubdomainMaxLength + validation.DNS1123LabelMaxLength + 1
9898
maxSignerNameLength := maxDomainSegmentLength + maxPathSegmentLength + 1
9999
if len(signerName) > maxSignerNameLength {
100-
el = append(el, field.TooLong(fldPath, signerName, maxSignerNameLength))
100+
el = append(el, field.TooLong(fldPath, "" /*unused*/, maxSignerNameLength))
101101
}
102102

103103
return el

pkg/apis/core/validation/validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ func ValidateCSIDriverName(driverName string, fldPath *field.Path) field.ErrorLi
16851685
}
16861686

16871687
if len(driverName) > 63 {
1688-
allErrs = append(allErrs, field.TooLong(fldPath, driverName, 63))
1688+
allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, 63))
16891689
}
16901690

16911691
for _, msg := range validation.IsDNS1123Subdomain(strings.ToLower(driverName)) {
@@ -4772,7 +4772,7 @@ func ValidateAppArmorProfileField(profile *core.AppArmorProfile, fldPath *field.
47724772

47734773
const maxLocalhostProfileLength = 4095 // PATH_MAX - 1
47744774
if len(*profile.LocalhostProfile) > maxLocalhostProfileLength {
4775-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("localhostProfile"), *profile.LocalhostProfile, maxLocalhostProfileLength))
4775+
allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), "" /*unused*/, maxLocalhostProfileLength))
47764776
}
47774777
}
47784778

@@ -6589,7 +6589,7 @@ func ValidateSecret(secret *core.Secret) field.ErrorList {
65896589
totalSize += len(value)
65906590
}
65916591
if totalSize > core.MaxSecretSize {
6592-
allErrs = append(allErrs, field.TooLong(dataPath, "", core.MaxSecretSize))
6592+
allErrs = append(allErrs, field.TooLong(dataPath, "" /*unused*/, core.MaxSecretSize))
65936593
}
65946594

65956595
switch secret.Type {
@@ -6704,7 +6704,7 @@ func ValidateConfigMap(cfg *core.ConfigMap) field.ErrorList {
67046704
}
67056705
if totalSize > core.MaxSecretSize {
67066706
// pass back "" to indicate that the error refers to the whole object.
6707-
allErrs = append(allErrs, field.TooLong(field.NewPath(""), cfg, core.MaxSecretSize))
6707+
allErrs = append(allErrs, field.TooLong(field.NewPath(""), "" /*unused*/, core.MaxSecretSize))
67086708
}
67096709

67106710
return allErrs

pkg/apis/core/validation/validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11928,7 +11928,7 @@ func TestValidatePod(t *testing.T) {
1192811928
),
1192911929
},
1193011930
"too long AppArmor localhost profile": {
11931-
expectedError: "Too long: may not be longer than 4095",
11931+
expectedError: "Too long: may not be more than 4095 bytes",
1193211932
spec: *podtest.MakePod("123",
1193311933
podtest.SetSecurityContext(&core.PodSecurityContext{
1193411934
AppArmorProfile: &core.AppArmorProfile{

pkg/apis/networking/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func ValidateIngressClassUpdate(newIngressClass, oldIngressClass *networking.Ing
526526
func validateIngressClassSpec(spec *networking.IngressClassSpec, fldPath *field.Path) field.ErrorList {
527527
allErrs := field.ErrorList{}
528528
if len(spec.Controller) > maxLenIngressClassController {
529-
allErrs = append(allErrs, field.TooLong(fldPath.Child("controller"), spec.Controller, maxLenIngressClassController))
529+
allErrs = append(allErrs, field.TooLong(fldPath.Child("controller"), "" /*unused*/, maxLenIngressClassController))
530530
}
531531
allErrs = append(allErrs, validation.IsDomainPrefixedPath(fldPath.Child("controller"), spec.Controller)...)
532532
allErrs = append(allErrs, validateIngressClassParametersReference(spec.Parameters, fldPath.Child("parameters"))...)

pkg/apis/networking/validation/validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ func TestValidateIngressClass(t *testing.T) {
14551455
},
14561456
"valid name, controller too long": {
14571457
ingressClass: makeValidIngressClass("test123", "foo.co/"+strings.Repeat("a", 244)),
1458-
expectedErrs: field.ErrorList{field.TooLong(field.NewPath("spec.controller"), "", 250)},
1458+
expectedErrs: field.ErrorList{field.TooLong(field.NewPath("spec.controller"), "" /*unused*/, 250)},
14591459
},
14601460
"valid name, valid controller, valid params": {
14611461
ingressClass: makeValidIngressClass("test123", "foo.co/bar",

pkg/apis/resource/validation/validation.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func validatePoolName(name string, fldPath *field.Path) field.ErrorList {
5252
allErrs = append(allErrs, field.Required(fldPath, ""))
5353
} else {
5454
if len(name) > resource.PoolNameMaxLength {
55-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath, name, resource.PoolNameMaxLength))
55+
allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, resource.PoolNameMaxLength))
5656
}
5757
parts := strings.Split(name, "/")
5858
for _, part := range parts {
@@ -168,7 +168,7 @@ func validateCELSelector(celSelector resource.CELDeviceSelector, fldPath *field.
168168
envType = environment.StoredExpressions
169169
}
170170
if len(celSelector.Expression) > resource.CELSelectorExpressionMaxLength {
171-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("expression"), "<value omitted>", resource.CELSelectorExpressionMaxLength))
171+
allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "" /*unused*/, resource.CELSelectorExpressionMaxLength))
172172
// Don't bother compiling too long expressions.
173173
return allErrs
174174
}
@@ -561,7 +561,7 @@ func validateDeviceAttribute(attribute resource.DeviceAttribute, fldPath *field.
561561
}
562562
if attribute.StringValue != nil {
563563
if len(*attribute.StringValue) > resource.DeviceAttributeMaxValueLength {
564-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("string"), *attribute.StringValue, resource.DeviceAttributeMaxValueLength))
564+
allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), "" /*unused*/, resource.DeviceAttributeMaxValueLength))
565565
}
566566
numFields++
567567
}
@@ -571,7 +571,7 @@ func validateDeviceAttribute(attribute resource.DeviceAttribute, fldPath *field.
571571
allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), *attribute.VersionValue, "must be a string compatible with semver.org spec 2.0.0"))
572572
}
573573
if len(*attribute.VersionValue) > resource.DeviceAttributeMaxValueLength {
574-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath.Child("version"), *attribute.VersionValue, resource.DeviceAttributeMaxValueLength))
574+
allErrs = append(allErrs, field.TooLong(fldPath.Child("version"), "" /*unused*/, resource.DeviceAttributeMaxValueLength))
575575
}
576576
}
577577

@@ -628,7 +628,7 @@ func validateFullyQualifiedName(name resource.FullyQualifiedName, fldPath *field
628628
func validateCIdentifier(id string, fldPath *field.Path) field.ErrorList {
629629
var allErrs field.ErrorList
630630
if len(id) > resource.DeviceMaxIDLength {
631-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath, id, resource.DeviceMaxIDLength))
631+
allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, resource.DeviceMaxIDLength))
632632
}
633633
for _, msg := range validation.IsCIdentifier(id) {
634634
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
649649
// Dumping the entire field into the error message is likely to be too long,
650650
// in particular when it is already beyond the maximum size. Instead this
651651
// just shows the number of entries.
652-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath, len(slice), maxSize))
652+
allErrs = append(allErrs, field.TooMany(fldPath, len(slice), maxSize))
653653
}
654654
return allErrs
655655
}
@@ -685,7 +685,7 @@ func stringKey(item string) (string, string) {
685685
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 {
686686
var allErrs field.ErrorList
687687
if maxSize >= 0 && len(m) > maxSize {
688-
allErrs = append(allErrs, field.TooLongMaxLength(fldPath, len(m), maxSize))
688+
allErrs = append(allErrs, field.TooMany(fldPath, len(m), maxSize))
689689
}
690690
for key, item := range m {
691691
allErrs = append(allErrs, validateKey(key, fldPath)...)

0 commit comments

Comments
 (0)