Merge pull request #128553 from thockin/master

Validation: merge TooLong and TooLongMaxLen
This commit is contained in:
Kubernetes Prow Robot
2024-11-06 04:19:43 +00:00
committed by GitHub
20 changed files with 54 additions and 60 deletions

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
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

View File

@@ -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

View File

@@ -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{