Call-site comments: the "" arg to TooLong is unused

This commit is contained in:
Tim Hockin
2024-11-05 09:11:03 -08:00
parent 8a7af90300
commit c8eeb486f4
15 changed files with 33 additions and 33 deletions

View File

@@ -218,7 +218,7 @@ func validateJobSpec(spec *batch.JobSpec, fldPath *field.Path, opts apivalidatio
if spec.ManagedBy != nil { if spec.ManagedBy != nil {
allErrs = append(allErrs, apimachineryvalidation.IsDomainPrefixedPath(fldPath.Child("managedBy"), *spec.ManagedBy)...) allErrs = append(allErrs, apimachineryvalidation.IsDomainPrefixedPath(fldPath.Child("managedBy"), *spec.ManagedBy)...)
if len(*spec.ManagedBy) > maxManagedByLength { if len(*spec.ManagedBy) > maxManagedByLength {
allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), "", maxManagedByLength)) allErrs = append(allErrs, field.TooLong(fldPath.Child("managedBy"), "" /*unused*/, maxManagedByLength))
} }
} }
if spec.CompletionMode != nil { if spec.CompletionMode != nil {
@@ -435,7 +435,7 @@ func validateSuccessPolicyRule(spec *batch.JobSpec, rule *batch.SuccessPolicyRul
if rule.SucceededIndexes != nil { if rule.SucceededIndexes != nil {
succeededIndexes := rulePath.Child("succeededIndexes") succeededIndexes := rulePath.Child("succeededIndexes")
if len(*rule.SucceededIndexes) > maxJobSuccessPolicySucceededIndexesLimit { if len(*rule.SucceededIndexes) > maxJobSuccessPolicySucceededIndexesLimit {
allErrs = append(allErrs, field.TooLong(succeededIndexes, "", maxJobSuccessPolicySucceededIndexesLimit)) allErrs = append(allErrs, field.TooLong(succeededIndexes, "" /*unused*/, maxJobSuccessPolicySucceededIndexesLimit))
} }
var err error var err error
if totalIndexes, err = validateIndexesFormat(*rule.SucceededIndexes, *spec.Completions); err != nil { if totalIndexes, err = validateIndexesFormat(*rule.SucceededIndexes, *spec.Completions); err != nil {

View File

@@ -509,7 +509,7 @@ func validateTrustBundle(path *field.Path, in string) field.ErrorList {
var allErrors field.ErrorList var allErrors field.ErrorList
if len(in) > certificates.MaxTrustBundleSize { if len(in) > certificates.MaxTrustBundleSize {
allErrors = append(allErrors, field.TooLong(path, "", certificates.MaxTrustBundleSize)) allErrors = append(allErrors, field.TooLong(path, "" /*unused*/, certificates.MaxTrustBundleSize))
return allErrors return allErrors
} }

View File

@@ -206,7 +206,7 @@ func TestValidateCertificateSigningRequestCreate(t *testing.T) {
}, },
}, },
errs: field.ErrorList{ errs: field.ErrorList{
field.TooLong(specPath.Child("signerName"), "", len(maxLengthSignerName)), field.TooLong(specPath.Child("signerName"), "" /*unused*/, len(maxLengthSignerName)),
}, },
}, },
"signerName with a fqdn greater than 253 characters should be rejected": { "signerName with a fqdn greater than 253 characters should be rejected": {
@@ -220,7 +220,7 @@ func TestValidateCertificateSigningRequestCreate(t *testing.T) {
}, },
}, },
errs: field.ErrorList{ errs: field.ErrorList{
field.TooLong(specPath.Child("signerName"), "", 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": { "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{ wantErrors: field.ErrorList{
field.TooLong(field.NewPath("spec", "trustBundle"), "", core.MaxSecretSize), field.TooLong(field.NewPath("spec", "trustBundle"), "" /*unused*/, core.MaxSecretSize),
}, },
}, },
{ {

View File

@@ -54,7 +54,7 @@ func ValidateSignerName(fldPath *field.Path, signerName string) field.ErrorList
// validate that segments[0] is less than 253 characters altogether // validate that segments[0] is less than 253 characters altogether
maxDomainSegmentLength := validation.DNS1123SubdomainMaxLength maxDomainSegmentLength := validation.DNS1123SubdomainMaxLength
if len(segments[0]) > maxDomainSegmentLength { if len(segments[0]) > maxDomainSegmentLength {
el = append(el, field.TooLong(fldPath, "", maxDomainSegmentLength)) el = append(el, field.TooLong(fldPath, "" /*unused*/, maxDomainSegmentLength))
} }
// validate that segments[0] consists of valid DNS1123 labels separated by '.' // validate that segments[0] consists of valid DNS1123 labels separated by '.'
domainLabels := strings.Split(segments[0], ".") domainLabels := strings.Split(segments[0], ".")
@@ -97,7 +97,7 @@ func ValidateSignerName(fldPath *field.Path, signerName string) field.ErrorList
maxPathSegmentLength := validation.DNS1123SubdomainMaxLength + validation.DNS1123LabelMaxLength + 1 maxPathSegmentLength := validation.DNS1123SubdomainMaxLength + validation.DNS1123LabelMaxLength + 1
maxSignerNameLength := maxDomainSegmentLength + maxPathSegmentLength + 1 maxSignerNameLength := maxDomainSegmentLength + maxPathSegmentLength + 1
if len(signerName) > maxSignerNameLength { if len(signerName) > maxSignerNameLength {
el = append(el, field.TooLong(fldPath, "", maxSignerNameLength)) el = append(el, field.TooLong(fldPath, "" /*unused*/, maxSignerNameLength))
} }
return el return el

View File

@@ -1685,7 +1685,7 @@ func ValidateCSIDriverName(driverName string, fldPath *field.Path) field.ErrorLi
} }
if len(driverName) > 63 { if len(driverName) > 63 {
allErrs = append(allErrs, field.TooLong(fldPath, "", 63)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, 63))
} }
for _, msg := range validation.IsDNS1123Subdomain(strings.ToLower(driverName)) { 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 const maxLocalhostProfileLength = 4095 // PATH_MAX - 1
if len(*profile.LocalhostProfile) > maxLocalhostProfileLength { if len(*profile.LocalhostProfile) > maxLocalhostProfileLength {
allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), "", maxLocalhostProfileLength)) allErrs = append(allErrs, field.TooLong(fldPath.Child("localhostProfile"), "" /*unused*/, maxLocalhostProfileLength))
} }
} }
@@ -6546,7 +6546,7 @@ func ValidateSecret(secret *core.Secret) field.ErrorList {
totalSize += len(value) totalSize += len(value)
} }
if totalSize > core.MaxSecretSize { if totalSize > core.MaxSecretSize {
allErrs = append(allErrs, field.TooLong(dataPath, "", core.MaxSecretSize)) allErrs = append(allErrs, field.TooLong(dataPath, "" /*unused*/, core.MaxSecretSize))
} }
switch secret.Type { switch secret.Type {
@@ -6661,7 +6661,7 @@ func ValidateConfigMap(cfg *core.ConfigMap) field.ErrorList {
} }
if totalSize > core.MaxSecretSize { if totalSize > core.MaxSecretSize {
// pass back "" to indicate that the error refers to the whole object. // pass back "" to indicate that the error refers to the whole object.
allErrs = append(allErrs, field.TooLong(field.NewPath(""), "", core.MaxSecretSize)) allErrs = append(allErrs, field.TooLong(field.NewPath(""), "" /*unused*/, core.MaxSecretSize))
} }
return allErrs return allErrs

View File

@@ -526,7 +526,7 @@ func ValidateIngressClassUpdate(newIngressClass, oldIngressClass *networking.Ing
func validateIngressClassSpec(spec *networking.IngressClassSpec, fldPath *field.Path) field.ErrorList { func validateIngressClassSpec(spec *networking.IngressClassSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
if len(spec.Controller) > maxLenIngressClassController { if len(spec.Controller) > maxLenIngressClassController {
allErrs = append(allErrs, field.TooLong(fldPath.Child("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, validation.IsDomainPrefixedPath(fldPath.Child("controller"), spec.Controller)...)
allErrs = append(allErrs, validateIngressClassParametersReference(spec.Parameters, fldPath.Child("parameters"))...) allErrs = append(allErrs, validateIngressClassParametersReference(spec.Parameters, fldPath.Child("parameters"))...)

View File

@@ -1455,7 +1455,7 @@ func TestValidateIngressClass(t *testing.T) {
}, },
"valid name, controller too long": { "valid name, controller too long": {
ingressClass: makeValidIngressClass("test123", "foo.co/"+strings.Repeat("a", 244)), 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": { "valid name, valid controller, valid params": {
ingressClass: makeValidIngressClass("test123", "foo.co/bar", ingressClass: makeValidIngressClass("test123", "foo.co/bar",

View File

@@ -52,7 +52,7 @@ func validatePoolName(name string, fldPath *field.Path) field.ErrorList {
allErrs = append(allErrs, field.Required(fldPath, "")) allErrs = append(allErrs, field.Required(fldPath, ""))
} else { } else {
if len(name) > resource.PoolNameMaxLength { if len(name) > resource.PoolNameMaxLength {
allErrs = append(allErrs, field.TooLong(fldPath, "", resource.PoolNameMaxLength)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, resource.PoolNameMaxLength))
} }
parts := strings.Split(name, "/") parts := strings.Split(name, "/")
for _, part := range parts { for _, part := range parts {
@@ -168,7 +168,7 @@ func validateCELSelector(celSelector resource.CELDeviceSelector, fldPath *field.
envType = environment.StoredExpressions envType = environment.StoredExpressions
} }
if len(celSelector.Expression) > resource.CELSelectorExpressionMaxLength { if len(celSelector.Expression) > resource.CELSelectorExpressionMaxLength {
allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "", resource.CELSelectorExpressionMaxLength)) allErrs = append(allErrs, field.TooLong(fldPath.Child("expression"), "" /*unused*/, resource.CELSelectorExpressionMaxLength))
// Don't bother compiling too long expressions. // Don't bother compiling too long expressions.
return allErrs return allErrs
} }
@@ -561,7 +561,7 @@ func validateDeviceAttribute(attribute resource.DeviceAttribute, fldPath *field.
} }
if attribute.StringValue != nil { if attribute.StringValue != nil {
if len(*attribute.StringValue) > resource.DeviceAttributeMaxValueLength { if len(*attribute.StringValue) > resource.DeviceAttributeMaxValueLength {
allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), "", resource.DeviceAttributeMaxValueLength)) allErrs = append(allErrs, field.TooLong(fldPath.Child("string"), "" /*unused*/, resource.DeviceAttributeMaxValueLength))
} }
numFields++ 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")) 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 { if len(*attribute.VersionValue) > resource.DeviceAttributeMaxValueLength {
allErrs = append(allErrs, field.TooLong(fldPath.Child("version"), "", 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 { func validateCIdentifier(id string, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList var allErrs field.ErrorList
if len(id) > resource.DeviceMaxIDLength { if len(id) > resource.DeviceMaxIDLength {
allErrs = append(allErrs, field.TooLong(fldPath, "", resource.DeviceMaxIDLength)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, resource.DeviceMaxIDLength))
} }
for _, msg := range validation.IsCIdentifier(id) { for _, msg := range validation.IsCIdentifier(id) {
allErrs = append(allErrs, field.TypeInvalid(fldPath, id, msg)) allErrs = append(allErrs, field.TypeInvalid(fldPath, id, msg))

View File

@@ -322,7 +322,7 @@ func TestValidateClaim(t *testing.T) {
}, },
"CEL-length": { "CEL-length": {
wantFailures: field.ErrorList{ 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"), "" /*unused*/, resource.CELSelectorExpressionMaxLength),
}, },
claim: func() *resource.ResourceClaim { claim: func() *resource.ResourceClaim {
claim := testClaim(goodName, goodNS, validClaimSpec) claim := testClaim(goodName, goodNS, validClaimSpec)

View File

@@ -100,7 +100,7 @@ func validateParameters(params map[string]string, allowEmpty bool, fldPath *fiel
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
if len(params) > maxProvisionerParameterLen { if len(params) > maxProvisionerParameterLen {
allErrs = append(allErrs, field.TooLong(fldPath, "", maxProvisionerParameterLen)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, maxProvisionerParameterLen))
return allErrs return allErrs
} }
@@ -112,7 +112,7 @@ func validateParameters(params map[string]string, allowEmpty bool, fldPath *fiel
} }
if totalSize > maxProvisionerParameterSize { if totalSize > maxProvisionerParameterSize {
allErrs = append(allErrs, field.TooLong(fldPath, "", maxProvisionerParameterSize)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, maxProvisionerParameterSize))
} }
if !allowEmpty && len(params) == 0 { 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)) size += (int64)(len(k)) + (int64)(len(v))
} }
if size > maxAttachedVolumeMetadataSize { if size > maxAttachedVolumeMetadataSize {
allErrs = append(allErrs, field.TooLong(fldPath, "", maxAttachedVolumeMetadataSize)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, maxAttachedVolumeMetadataSize))
} }
return allErrs return allErrs
} }
@@ -235,7 +235,7 @@ func validateVolumeError(e *storage.VolumeError, fldPath *field.Path) field.Erro
return allErrs return allErrs
} }
if len(e.Message) > maxVolumeErrorMessageSize { if len(e.Message) > maxVolumeErrorMessageSize {
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxAttachedVolumeMetadataSize)) allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "" /*unused*/, maxAttachedVolumeMetadataSize))
} }
return allErrs return allErrs
} }

View File

@@ -183,13 +183,13 @@ func validateCondition(condition storagemigration.MigrationCondition, fldPath *f
const maxReasonLen int = 1 * 1024 // 1024 const maxReasonLen int = 1 * 1024 // 1024
if len(condition.Reason) > maxReasonLen { if len(condition.Reason) > maxReasonLen {
allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "", maxReasonLen)) allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "" /*unused*/, maxReasonLen))
} }
} }
const maxMessageLen int = 32 * 1024 // 32768 const maxMessageLen int = 32 * 1024 // 32768
if len(condition.Message) > maxMessageLen { if len(condition.Message) > maxMessageLen {
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxMessageLen)) allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "" /*unused*/, maxMessageLen))
} }
return allErrs return allErrs

View File

@@ -374,7 +374,7 @@ func TestWriteConfigMapDeleted(t *testing.T) {
t.Run("ca bundle too large", func(t *testing.T) { t.Run("ca bundle too large", func(t *testing.T) {
client := fake.NewSimpleClientset() client := fake.NewSimpleClientset()
client.PrependReactor("update", "configmaps", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) { 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(""), "", 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) { client.PrependReactor("delete", "configmaps", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, nil return true, nil, nil

View File

@@ -186,7 +186,7 @@ func kubeOpenAPIResultToFieldErrors(fldPath *field.Path, result *validate.Result
if i, ok := err.Valid.(int64); ok { if i, ok := err.Valid.(int64); ok {
max = i max = i
} }
allErrs = append(allErrs, field.TooLong(errPath, "", int(max))) allErrs = append(allErrs, field.TooLong(errPath, "" /*unused*/, int(max)))
case openapierrors.MaxItemsFailCode: case openapierrors.MaxItemsFailCode:
actual := int64(-1) actual := int64(-1)

View File

@@ -50,7 +50,7 @@ func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) fie
} }
} }
if err := ValidateAnnotationsSize(annotations); err != nil { if err := ValidateAnnotationsSize(annotations); err != nil {
allErrs = append(allErrs, field.TooLong(fldPath, "", TotalAnnotationSizeLimitB)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, TotalAnnotationSizeLimitB))
} }
return allErrs return allErrs
} }

View File

@@ -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 // considered as not set and is defaulted by the rest of the process
// (unless apply is used, in which case it is required). // (unless apply is used, in which case it is required).
if len(fieldManager) > FieldManagerMaxLength { if len(fieldManager) > FieldManagerMaxLength {
allErrs = append(allErrs, field.TooLong(fldPath, "", FieldManagerMaxLength)) allErrs = append(allErrs, field.TooLong(fldPath, "" /*unused*/, FieldManagerMaxLength))
} }
// Verify that all characters are printable. // Verify that all characters are printable.
for i, r := range fieldManager { 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"))...) allErrs = append(allErrs, ValidateFieldManager(fields.Manager, fldPath.Child("manager"))...)
if len(fields.Subresource) > MaxSubresourceNameLength { if len(fields.Subresource) > MaxSubresourceNameLength {
allErrs = append(allErrs, field.TooLong(fldPath.Child("subresource"), "", MaxSubresourceNameLength)) allErrs = append(allErrs, field.TooLong(fldPath.Child("subresource"), "" /*unused*/, MaxSubresourceNameLength))
} }
} }
return allErrs 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)) allErrs = append(allErrs, field.Invalid(fldPath.Child("reason"), condition.Reason, currErr))
} }
if len(condition.Reason) > maxReasonLen { if len(condition.Reason) > maxReasonLen {
allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "", maxReasonLen)) allErrs = append(allErrs, field.TooLong(fldPath.Child("reason"), "" /*unused*/, maxReasonLen))
} }
} }
if len(condition.Message) > maxMessageLen { if len(condition.Message) > maxMessageLen {
allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "", maxMessageLen)) allErrs = append(allErrs, field.TooLong(fldPath.Child("message"), "" /*unused*/, maxMessageLen))
} }
return allErrs return allErrs