mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Clarify that value arg to field.TooLong is unused
This commit is contained in:
parent
4d0e1c8fd4
commit
8a7af90300
@ -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 {
|
||||
|
@ -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("<value omitted, len %d>", len(in)), certificates.MaxTrustBundleSize))
|
||||
allErrors = append(allErrors, field.TooLong(path, "", certificates.MaxTrustBundleSize))
|
||||
return allErrors
|
||||
}
|
||||
|
||||
|
@ -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("<value omitted, len %d>", len(badTooBigBundle)), core.MaxSecretSize),
|
||||
field.TooLong(field.NewPath("spec", "trustBundle"), "", core.MaxSecretSize),
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"))...)
|
||||
|
@ -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"), "<value omitted>", 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))
|
||||
|
@ -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"), "<value omitted>", 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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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(), "<value omitted>", msg}
|
||||
}
|
||||
|
||||
// TooLongMaxLength returns a *Error indicating "too long".
|
||||
|
Loading…
Reference in New Issue
Block a user