Skip to content

Commit 8a7af90

Browse files
committed
Clarify that value arg to field.TooLong is unused
1 parent 4d0e1c8 commit 8a7af90

File tree

14 files changed

+34
-38
lines changed

14 files changed

+34
-38
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.TooLong(fldPath.Child("managedBy"), *spec.ManagedBy, maxManagedByLength))
221+
allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), "", 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, "", maxJobSuccessPolicySucceededIndexesLimit))
439439
}
440440
var err error
441441
if totalIndexes, err = validateIndexesFormat(*rule.SucceededIndexes, *spec.Completions); err != nil {

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, "", 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"), "", 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"), "", 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"), "", 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, "", 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, "", maxSignerNameLength))
101101
}
102102

103103
return el

pkg/apis/core/validation/validation.go

Lines changed: 3 additions & 3 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, "", 63))
16891689
}
16901690

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

47594759
const maxLocalhostProfileLength = 4095 // PATH_MAX - 1
47604760
if len(*profile.LocalhostProfile) > maxLocalhostProfileLength {
4761-
allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), *profile.LocalhostProfile, maxLocalhostProfileLength))
4761+
allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), "", maxLocalhostProfileLength))
47624762
}
47634763
}
47644764

@@ -6661,7 +6661,7 @@ func ValidateConfigMap(cfg *core.ConfigMap) field.ErrorList {
66616661
}
66626662
if totalSize > core.MaxSecretSize {
66636663
// pass back "" to indicate that the error refers to the whole object.
6664-
allErrs = append(allErrs, field.TooLong(field.NewPath(""), cfg, core.MaxSecretSize))
6664+
allErrs = append(allErrs, field.TooLong(field.NewPath(""), "", core.MaxSecretSize))
66656665
}
66666666

66676667
return allErrs

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"), "", 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/resource/validation/validation.go

Lines changed: 5 additions & 5 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.TooLong(fldPath, name, resource.PoolNameMaxLength))
55+
allErrs = append(allErrs, field.TooLong(fldPath, "", 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.TooLong(fldPath.Child("expression"), "<value omitted>", resource.CELSelectorExpressionMaxLength))
171+
allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "", 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.TooLong(fldPath.Child("string"), *attribute.StringValue, resource.DeviceAttributeMaxValueLength))
564+
allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), "", 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.TooLong(fldPath.Child("version"), *attribute.VersionValue, resource.DeviceAttributeMaxValueLength))
574+
allErrs = append(allErrs, field.TooLong(fldPath.Child("version"), "", 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.TooLong(fldPath, id, resource.DeviceMaxIDLength))
631+
allErrs = append(allErrs, field.TooLong(fldPath, "", resource.DeviceMaxIDLength))
632632
}
633633
for _, msg := range validation.IsCIdentifier(id) {
634634
allErrs = append(allErrs, field.TypeInvalid(fldPath, id, msg))

pkg/apis/resource/validation/validation_resourceclaim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func TestValidateClaim(t *testing.T) {
322322
},
323323
"CEL-length": {
324324
wantFailures: field.ErrorList{
325-
field.TooLong(field.NewPath("spec", "devices", "requests").Index(1).Child("selectors").Index(1).Child("cel", "expression"), "<value omitted>", resource.CELSelectorExpressionMaxLength),
325+
field.TooLong(field.NewPath("spec", "devices", "requests").Index(1).Child("selectors").Index(1).Child("cel", "expression"), "", resource.CELSelectorExpressionMaxLength),
326326
},
327327
claim: func() *resource.ResourceClaim {
328328
claim := testClaim(goodName, goodNS, validClaimSpec)

pkg/apis/storage/validation/validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func validateParameters(params map[string]string, allowEmpty bool, fldPath *fiel
100100
allErrs := field.ErrorList{}
101101

102102
if len(params) > maxProvisionerParameterLen {
103-
allErrs = append(allErrs, field.TooLong(fldPath, "Provisioner Parameters exceeded max allowed", maxProvisionerParameterLen))
103+
allErrs = append(allErrs, field.TooLong(fldPath, "", maxProvisionerParameterLen))
104104
return allErrs
105105
}
106106

@@ -223,7 +223,7 @@ func validateAttachmentMetadata(metadata map[string]string, fldPath *field.Path)
223223
size += (int64)(len(k)) + (int64)(len(v))
224224
}
225225
if size > maxAttachedVolumeMetadataSize {
226-
allErrs = append(allErrs, field.TooLong(fldPath, metadata, maxAttachedVolumeMetadataSize))
226+
allErrs = append(allErrs, field.TooLong(fldPath, "", maxAttachedVolumeMetadataSize))
227227
}
228228
return allErrs
229229
}
@@ -235,7 +235,7 @@ func validateVolumeError(e *storage.VolumeError, fldPath *field.Path) field.Erro
235235
return allErrs
236236
}
237237
if len(e.Message) > maxVolumeErrorMessageSize {
238-
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), e.Message, maxAttachedVolumeMetadataSize))
238+
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxAttachedVolumeMetadataSize))
239239
}
240240
return allErrs
241241
}

pkg/apis/storagemigration/validation/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ func validateCondition(condition storagemigration.MigrationCondition, fldPath *f
183183

184184
const maxReasonLen int = 1 * 1024 // 1024
185185
if len(condition.Reason) > maxReasonLen {
186-
allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), condition.Reason, maxReasonLen))
186+
allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "", maxReasonLen))
187187
}
188188
}
189189

190190
const maxMessageLen int = 32 * 1024 // 32768
191191
if len(condition.Message) > maxMessageLen {
192-
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), condition.Message, maxMessageLen))
192+
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxMessageLen))
193193
}
194194

195195
return allErrs

0 commit comments

Comments
 (0)