Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
dd2e2c0
update internal apis and their validations
yongruilin Mar 15, 2025
1d2f2a7
update featuregates
yongruilin Mar 15, 2025
f1cfeba
update registry/core/replicationcontroller
yongruilin Mar 15, 2025
7eddef4
update validation-gen validators
yongruilin Mar 15, 2025
97f9b94
chore(validation-gen): fix rebase with codetags across a number of ta…
aaron-prindle Jul 29, 2025
494e155
update encrypt/envelope/kmsv2
yongruilin Mar 15, 2025
575aeb3
update validation-gen/output_tests
yongruilin Mar 15, 2025
f9be72b
chore(validation-gen): fix rebase, update union, zerooroneof, neq, an…
aaron-prindle Jul 29, 2025
a954688
update github action workflow
yongruilin Mar 15, 2025
c471d7b
update TODO
yongruilin Mar 15, 2025
c56e60d
add script to generate validation tags docs
yongruilin Mar 15, 2025
891f699
Revert small diffs vs. master
thockin Mar 16, 2025
5d25312
Fix small diffs vs. master
thockin Mar 16, 2025
1303dbc
Revert test diffs that were relocated in master
thockin Mar 17, 2025
cd425dc
Update TODO
thockin Mar 17, 2025
3a775c6
Update TODO
thockin Mar 24, 2025
f99ff64
Add tests for requiredness of typedef fields
thockin Apr 15, 2025
95caa81
chore(validation-gen): fix rebase, generate code for tags/forbidden a…
aaron-prindle Jul 29, 2025
6463655
Fix maxLength to handle pointer fields properly
thockin Apr 18, 2025
fc4c5a7
Add lint rule: union members must be optional
thockin Apr 19, 2025
e987f35
Handle typedef fields in requiredness
thockin Apr 19, 2025
c605cff
chore(validation-gen): fix rebase, generate code for tags/forbidden a…
aaron-prindle Jul 29, 2025
338245b
Group test cases better
thockin Mar 28, 2025
824dcf3
Fix wrong test case for string format
thockin Mar 28, 2025
df40fd1
Make test more amenable to copying
thockin Mar 28, 2025
21035c9
Add ExpectMatches to ValidationTester, use it in format test
thockin Mar 28, 2025
9a4aa77
treat listtype=set as set without ordering
yongruilin Apr 22, 2025
1908cbc
chore(validation-gen): fix rebase, remove duplicate listset/doc.go Im…
aaron-prindle Jul 29, 2025
0d56781
Change option to a slice
jpbetz Mar 29, 2025
68eb102
Rename `Unique` funcs to match `Immutable` style
thockin May 2, 2025
3daa52c
Fix broken recursion
thockin Apr 27, 2025
6698972
chore(validation-gen): fix rebase, generate code for recursive/pointe…
aaron-prindle Jul 29, 2025
b29374c
Update validation-gen-ci-test.yml
yongruilin May 13, 2025
bd77377
chore: remove TODO now that TODO items are converted to Github issues
aaron-prindle May 19, 2025
c6f1a4f
feat: add isDirectComparable func for types
yongruilin May 15, 2025
0ad7d92
feat: add default ratcheting support
yongruilin May 12, 2025
b6c1990
run codegen
yongruilin May 12, 2025
6547dfc
add ratcheting test case for forbidden tag
yongruilin May 13, 2025
894c89c
add ratcheting testcase for format tag
yongruilin May 13, 2025
23dc46f
add ratcheting testcase for required tag
yongruilin May 13, 2025
1caf2fe
add ratcheting testcase for maxitems tag
yongruilin May 13, 2025
fbcd6dd
add ratcheting testcase for maxlength tag
yongruilin May 13, 2025
2ce175f
Move IsDirectComparable() into validators package
yongruilin May 21, 2025
f52a71a
Fix field path for embedded fields in root types
thockin Jun 4, 2025
cf36b08
run codegen
yongruilin Jun 4, 2025
a44d3e3
Bump gengo/v2
jpbetz Jun 3, 2025
3de883c
chore(validation-gen): fix rebase, run hack/update-vendor.sh
aaron-prindle Jul 29, 2025
de4a9d5
Use codetags in validation-gen
jpbetz Jun 3, 2025
24f81ab
Switch to using named args in output_tests
jpbetz Jun 3, 2025
f2b556e
Add type information to tag Docs() and use it to typecheck tags
jpbetz Jun 3, 2025
31dba4a
Regenerate docs
jpbetz Jun 4, 2025
0881203
Simplify tests and add comments wrt ratcheting
thockin May 23, 2025
c896498
Move utils to a pkg, add tests
thockin May 24, 2025
02ad3b6
Rename format "ip-sloppy" to "k8s-ip-sloppy"
thockin Jun 5, 2025
d449389
Rename format "dns-label" to "k8s-short-name"
thockin Jun 5, 2025
ebb433a
Rename format "qualified-name" to "k8s-qualified-name"
thockin Jun 5, 2025
62f53d0
Rename format "endpoint-ip" to "k8s-endpoint-ip"
thockin Jun 5, 2025
55ae24b
Rename format "ip-strict" to "k8s-ip"
thockin Jun 5, 2025
7188c87
Rename example format to use "k8s" prefix
thockin Jun 5, 2025
ecc49df
address comments - don't have any type for discriminator from patch
aaron-prindle Jun 12, 2025
0f2146e
chore(validation-gen): fix rebase, remove duplicate toSliceAny from v…
aaron-prindle Jul 29, 2025
c552dcc
fix: versioned validation test avoid incorrect conversion
yongruilin Jun 18, 2025
0126e3c
test(github-action): add additional tests for declarative validation
yongruilin Jun 18, 2025
33fba47
feat: add +k8s:neq tag which enforces field is neq to a specified com…
aaron-prindle Jun 16, 2025
f6d59b9
chore(validation-gen): fix rebase, remove duplicate NEQError from con…
aaron-prindle Jul 29, 2025
67c75c4
Implement ListMap uniqueness as a FieldValidator
thockin Jun 11, 2025
8a0c7f6
chore(validation-gen): fix rebase, generate code for tests
aaron-prindle Jul 29, 2025
9893f15
fix formatting and lint issue
lalitc375 Jul 1, 2025
0ec1b05
Add github action to verify go fmt and run lint
lalitc375 Jul 1, 2025
31f3611
Validate typedefs that are declared as listmaps
thockin Jul 3, 2025
08cfdb0
chore(validation-gen): fix rebase, generate code for tests
aaron-prindle Jul 29, 2025
a03a656
chore: update +k8s:neq tests and error text based on review comments
aaron-prindle Jul 2, 2025
9a7350b
address thockin review comments - round 1
aaron-prindle Jul 7, 2025
43843e2
refactor(validation): Rename k8s-ip-sloppy format to k8s-ip
lalitc375 Jul 9, 2025
a8d7b68
run codegen & fix test
yongruilin Jul 1, 2025
8af27ad
add test for ratcheting on listType=set
yongruilin Jul 1, 2025
c977332
chore(validation-gen): fix rebase, remove unused imports in tests + g…
aaron-prindle Jul 29, 2025
9c01739
chore: fix forward on validation versioned test
yongruilin Jul 9, 2025
a8aa52b
Fix uninitialized arg for atomic lists
thockin Jul 10, 2025
9a15332
Consider list metadata defined on types
thockin Jul 10, 2025
49286ad
chore(validation-gen): fix rebase, remove duplicate nt variable from …
aaron-prindle Jul 29, 2025
3608219
Update comments about validator ordering
thockin Jul 10, 2025
ade4478
fix formatting and lint issue
lalitc375 Jul 11, 2025
2b132bc
Add comments to generated code
thockin Jul 11, 2025
606250a
Cleanup: Small lint things
thockin Jul 13, 2025
f3e73f0
feat: update union tags to allow for chaining +k8s:item and union tag…
aaron-prindle Jul 16, 2025
31ce4ba
hold uniqueness check of listmap
yongruilin Jul 15, 2025
0d3dd3a
feat: Enabledeclarative validation in CertificateSigningRequest subre…
yongruilin Jul 18, 2025
95c1a80
add CSR declarative_validation_test.go tests
aaron-prindle Jul 16, 2025
25c28fb
Rename tests before they get copied more widely
thockin Jul 21, 2025
95b3738
Better global variable name and comment
thockin Jul 18, 2025
70dc594
Convert {is,supports}SubResource to modern tag parsing
thockin Jul 18, 2025
01b6b37
chore: fix rebase, add back emitRatcheting TODO
aaron-prindle Jul 28, 2025
c9d45d9
chore(validation-gen): fix rebase, remove dupe methods and add back r…
aaron-prindle Jul 29, 2025
395612a
chore(validation-gen): fix rebase, update field/errors.go error message
aaron-prindle Jul 29, 2025
431bd9e
Emit ratchet check for fields with a type func
thockin Jul 19, 2025
49dbde9
Don't ratchet-check inside type functions
thockin Jul 19, 2025
655f8bc
Prefactor: Fix some bad tests
thockin Aug 1, 2025
196f5ad
Add support for validation cohorts
thockin Jul 31, 2025
2d226f0
Add cohort support to +k8s:subfield
thockin Jul 31, 2025
2f0387c
Add cohort support to +k8s:item
thockin Jul 31, 2025
6bf0f7c
Add ValidateObjectMetaWithOpts() to apimachinery
thockin Jul 31, 2025
409342b
Add DNS subdomain format
thockin Mar 28, 2025
696e3a4
Validate ReplicationController.metadata.name
thockin Apr 14, 2025
3a03608
Eliminate public ValidateReplicationControllerName
thockin Apr 11, 2025
984c597
Move format= tests into dirs for each format
thockin Apr 14, 2025
dc9981c
Update CSR DV test to match RC style
thockin Aug 1, 2025
c019474
Make ErrorMatcher more strict about multi-match
thockin Aug 2, 2025
aa589fa
Fix ReplicationControl double validation
thockin Aug 3, 2025
960024b
Temporary: Re-enable listmap uniqueness checks
thockin Aug 2, 2025
f7e6860
Re-disable listmap uniqueness (for now)
thockin Aug 2, 2025
202a728
Pass equiv func to subfield, like item and eachVal
thockin Jul 14, 2025
3ff1b2d
Remove ExpectRegexpsByPath()
thockin Aug 2, 2025
e435aa4
Remove ExpectInvalid()
thockin Aug 3, 2025
f170da7
Add comments
thockin Aug 3, 2025
74987e7
Merge pull request #148 from thockin/vg_expect_cleanup
yongruilin Aug 7, 2025
0c8892b
Add runtime options validator function
jpbetz Aug 8, 2025
3648e95
Drop conditions in favor of tag chaining for options
jpbetz Aug 8, 2025
4da7fcd
generate
jpbetz Aug 8, 2025
34d7e60
Add subfield test case
jpbetz Aug 8, 2025
86ea029
Apply feedback
jpbetz Aug 8, 2025
79da349
Merge pull request #150 from jpbetz/options-tag-chaining
aaron-prindle Aug 11, 2025
75da739
prefactor: update proto
thockin Jul 29, 2025
b78fbac
Minor validator name-string fix
thockin Jul 16, 2025
024f0c5
Update Context comments and fix some usage
thockin Jul 16, 2025
eb4af0f
validation: Use JSON names in paths
thockin Jul 16, 2025
22c6297
Unions: replace `[2]string` with a type
thockin Jul 16, 2025
0056582
Add ListSelector in validation Context
thockin Jul 17, 2025
4ceb182
Break processFieldMemberValidations into 2 funcs
thockin Jul 17, 2025
168aff9
Rename "fields" to "members"
thockin Jul 17, 2025
f420e23
Improve error reporting in item tag
thockin Jul 17, 2025
a73f7ae
Parse path early, clean up getDisplayFields()
thockin Jul 17, 2025
7255a52
Clarify that union has field- or item-members
thockin Jul 17, 2025
9cf2223
Sort item criteria to match listmap key order
thockin Jul 17, 2025
a96b5cf
Make item validation just use a TagValidator
thockin Jul 17, 2025
ddff0e9
Refactor ItemTagValidator.GetValidations a bit
thockin Jul 17, 2025
06dce5f
Merge pull request #132 from thockin/followup_128_item_unions
aaron-prindle Aug 12, 2025
7590c62
Rename if(OptionsEnabled|Disabled) -> if(Enabled|Disabled)
jpbetz Aug 8, 2025
e227eac
Use positional arg for option name
jpbetz Aug 11, 2025
e50fd8e
Apply feedback
jpbetz Aug 12, 2025
cb84b09
Add stability level in the tags doc.
lalitc375 Aug 7, 2025
62f8a88
Fix documentation for eachKeyTag
lalitc375 Aug 7, 2025
412517e
chore: Enhance error handling for unknown tag validators in registry
yongruilin Aug 12, 2025
2dd701e
test: Add unit tests for tag validation ExtractValidations
yongruilin Aug 12, 2025
f512591
Address comment: Implement recursive tag validation for chained tags …
yongruilin Aug 12, 2025
97bf405
Merge pull request #158 from yongruilin/vg_tag-not-found
jpbetz Aug 12, 2025
827f3c7
Fix failing test
lalitc375 Aug 13, 2025
1625395
Merge pull request #160 from lalitc375/failing-test
yongruilin Aug 14, 2025
7913d1d
feat(validation): Add origin to validation errors
lalitc375 Aug 12, 2025
cdd241d
Merge pull request #159 from lalitc375/origin
yongruilin Aug 15, 2025
d8a2f71
Merge pull request #146 from lalitc375/stability-level
aaron-prindle Aug 15, 2025
d09bedc
Add constant discovery, ScopeConst and StructLiberal. Remove ScopeAny.
jpbetz Aug 18, 2025
9f6669d
Add enumExclude support to enum validator
jpbetz Aug 18, 2025
200d574
Add +k8s:enumExclude and options support to +k8s:enum
jpbetz Aug 18, 2025
9d9aa09
Add output tests
jpbetz Aug 18, 2025
bb7e844
Apply feedback
jpbetz Aug 19, 2025
561c104
Add support variable initialization using any literal type
jpbetz Aug 19, 2025
12bdebb
Omit type names of emitted slice elements to appease gofmt
jpbetz Aug 19, 2025
c6a160b
feat: Add case-insensitive long name validation
lalitc375 Aug 20, 2025
fb89bc4
Generate protobuf properly for core/v1
lalitc375 Aug 21, 2025
5b448e6
Merge pull request #173 from lalitc375/generated-code
yongruilin Aug 21, 2025
80cd9a3
Address comments - part 1
lalitc375 Aug 26, 2025
a402bcb
Merge pull request #171 from lalitc375/k8s-long-name-caseless
aaron-prindle Aug 27, 2025
5bf428c
Fix a small error message, simplfy tests
thockin Aug 29, 2025
15a3004
Add support for UUID format.
lalitc375 Aug 20, 2025
9beae04
Only pass type args when needed in enum init
thockin Aug 29, 2025
7f5028d
Merge pull request #175 from thockin/vg_nits
aaron-prindle Aug 29, 2025
1ed068a
Merge pull request #176 from thockin/vg_enum_no_type_args
jpbetz Aug 29, 2025
c2b0534
feat(validation): Add k8s-label-value format validation
lalitc375 Aug 20, 2025
8a765e2
Merge pull request #169 from lalitc375/k8s-label-value
aaron-prindle Aug 29, 2025
46c0e1f
Add support for k8s-label-key
lalitc375 Aug 20, 2025
700e606
feat(validation-gen): support unique tag on list
yongruilin Aug 13, 2025
596a5d3
feat(validation-gen): Add tests for unique tag combinations
yongruilin Aug 14, 2025
3a2ff20
refactor(validation-gen): simplify listMetadata and improve tag valid…
yongruilin Aug 17, 2025
ee36f54
Apply feedback
yongruilin Aug 20, 2025
dc7faf6
refactor(validation-gen): move list-related validators to list.go
yongruilin Aug 22, 2025
f5458c2
Refactor(validation-gen): Improve list validation logic
yongruilin Aug 22, 2025
1af6fe0
test(validation-gen): Add test for composed item validation tags
yongruilin Aug 29, 2025
2a3ab18
Address feedback
yongruilin Aug 30, 2025
5af7ebe
Revert "Bump gengo/v2"
thockin Sep 3, 2025
3e4f75c
Revert "chore(validation-gen): fix rebase, run hack/update-vendor.sh"
thockin Sep 3, 2025
2402cfc
Use consistent documentation of aliases in the API
jpbetz Aug 29, 2025
00be606
Bump gengo
thockin Sep 3, 2025
dae7861
Revert "Omit type names of emitted slice elements to appease gofmt"
thockin Sep 3, 2025
ea0383c
Update codegen
thockin Sep 3, 2025
9924a4f
Merge pull request #179 from thockin/vg_remove_manual_gofmt
jpbetz Sep 3, 2025
aba381f
Remove origins that are not adding any value
lalitc375 Sep 2, 2025
18453ce
Change new validation for IPs to be strict
thockin Jul 26, 2025
db91dd6
Call new validate.IP from old
thockin Jul 26, 2025
5a6906d
Add comments about ratcheting for IPs
thockin Jul 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 46 additions & 0 deletions .github/workflows/validation-gen-ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: validation-gen CI Tests

on:
pull_request:
branches:
- "main"

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4

- name: Run code generation and check for diffs
run: |
hack/update-codegen.sh validation
git diff --exit-code

- name: Run gofmt and check for diffs
run: |
hack/verify-gofmt.sh
git diff --exit-code

- name: Run golangci-lint CI Test
run: |
hack/verify-golangci-lint.sh

- name: Run validation-gen go tests and also check for diffs with generated test fixture code
env:
UPDATE_VALIDATION_GEN_FIXTURE_DATA: "true"
run: |
go test ./staging/src/k8s.io/code-generator/cmd/validation-gen/...
go test ./staging/src/k8s.io/apimachinery/pkg/api/...
go test ./staging/src/k8s.io/apimachinery/pkg/util/...
go test ./pkg/api/testing/...
go test ./pkg/apis/autoscaling/validation/...
go test ./pkg/registry/core/replicationcontroller/...
go test ./pkg/registry/certificates/certificates/...
go test ./pkg/apis/autoscaling/validation/...
git diff --exit-code

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20250604051438-85fd79dbfd9f // indirect
k8s.io/gengo/v2 v2.0.0-20250903151518-081d64401ab4 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/kustomize/api v0.20.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
k8s.io/gengo/v2 v2.0.0-20250604051438-85fd79dbfd9f h1:SLb+kxmzfA87x4E4brQzB33VBbT2+x7Zq9ROIHmGn9Q=
k8s.io/gengo/v2 v2.0.0-20250604051438-85fd79dbfd9f/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU=
k8s.io/gengo/v2 v2.0.0-20250903151518-081d64401ab4 h1:I8k0vOOD2ZQWs3PtYXC0mjJdlIMriS0O/N+RjSkWB48=
k8s.io/gengo/v2 v2.0.0-20250903151518-081d64401ab4/go.mod h1:CgujABENc3KuTrcsdpGmrrASjtQsWCT7R99mEV4U/fM=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA=
Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/admissionregistration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,16 +1033,18 @@ type MutatingWebhook struct {
MatchConditions []MatchCondition
}

// ReinvocationPolicyType specifies what type of policy the admission hook uses.
// ReinvocationPolicyType specifies what type of policy is used when other admission plugins also perform
// modifications.
// +enum
type ReinvocationPolicyType string

var (
// NeverReinvocationPolicy indicates that the webhook must not be called more than once in a
// NeverReinvocationPolicy indicates that the mutation must not be called more than once in a
// single admission evaluation.
NeverReinvocationPolicy ReinvocationPolicyType = "Never"
// IfNeededReinvocationPolicy indicates that the webhook may be called at least one
// IfNeededReinvocationPolicy indicates that the mutation may be called at least one
// additional time as part of the admission evaluation if the object being admitted is
// modified by other admission plugins after the initial webhook call.
// modified by other admission plugins after the initial mutation call.
IfNeededReinvocationPolicy ReinvocationPolicyType = "IfNeeded"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apiserverinternal/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,13 @@ func TestValidateStorageVersionName(t *testing.T) {
expectedErr: "",
}, {
name: strings.Repeat("x", 254) + ".tokenreviews",
expectedErr: `the group segment must be no more than 253 characters`,
expectedErr: `the group segment must be no more than 253 bytes`,
}, {
name: "authentication.k8s.io." + strings.Repeat("x", 63),
expectedErr: "",
}, {
name: "authentication.k8s.io." + strings.Repeat("x", 64),
expectedErr: `the resource segment must be no more than 63 characters`,
expectedErr: `the resource segment must be no more than 63 bytes`,
}}
for _, tc := range cases {
errs := ValidateStorageVersionName(tc.name, false)
Expand Down
14 changes: 13 additions & 1 deletion pkg/apis/apps/v1beta1/zz_generated.validations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion pkg/apis/apps/v1beta2/zz_generated.validations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion pkg/apis/autoscaling/v1/zz_generated.validations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"k8s.io/kubernetes/pkg/features"
)

func TestValidateScaleForDeclarative(t *testing.T) {
func TestScaleDeclarativeValidation(t *testing.T) {
ctx := genericapirequest.WithRequestInfo(genericapirequest.NewDefaultContext(), &genericapirequest.RequestInfo{
APIGroup: "autoscaling",
APIVersion: "v1",
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/autoscaling/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ValidateScale(scale *autoscaling.Scale) field.ErrorList {

// ValidateHorizontalPodAutoscalerName can be used to check whether the given autoscaler name is valid.
// Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.
var ValidateHorizontalPodAutoscalerName = apivalidation.ValidateReplicationControllerName
var ValidateHorizontalPodAutoscalerName = apimachineryvalidation.NameIsDNSSubdomain

func validateHorizontalPodAutoscalerSpec(autoscaler autoscaling.HorizontalPodAutoscalerSpec, fldPath *field.Path, opts HorizontalPodAutoscalerSpecValidationOptions) field.ErrorList {
allErrs := field.ErrorList{}
Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/batch/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/robfig/cron/v3"

apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/validate/content"
apimachineryapivalidation "k8s.io/apimachinery/pkg/api/validation"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -150,7 +152,7 @@ func validateGeneratedSelector(obj *batch.Job, validateBatchLabels bool) field.E
// ValidateJob validates a Job and returns an ErrorList with any errors.
func ValidateJob(job *batch.Job, opts JobValidationOptions) field.ErrorList {
// Jobs and rcs have the same name validation
allErrs := apivalidation.ValidateObjectMeta(&job.ObjectMeta, true, apivalidation.ValidateReplicationControllerName, field.NewPath("metadata"))
allErrs := apivalidation.ValidateObjectMeta(&job.ObjectMeta, true, apimachineryapivalidation.NameIsDNSSubdomain, field.NewPath("metadata"))
allErrs = append(allErrs, validateGeneratedSelector(job, opts.RequirePrefixedLabels)...)
allErrs = append(allErrs, ValidateJobSpec(&job.Spec, field.NewPath("spec"), opts.PodValidationOptions)...)
if job.Spec.CompletionMode != nil && *job.Spec.CompletionMode == batch.IndexedCompletion && job.Spec.Completions != nil && *job.Spec.Completions > 0 {
Expand Down Expand Up @@ -714,14 +716,14 @@ func ValidateJobStatusUpdate(job, oldJob *batch.Job, opts JobStatusValidationOpt
// ValidateCronJobCreate validates a CronJob on creation and returns an ErrorList with any errors.
func ValidateCronJobCreate(cronJob *batch.CronJob, opts apivalidation.PodValidationOptions) field.ErrorList {
// CronJobs and rcs have the same name validation
allErrs := apivalidation.ValidateObjectMeta(&cronJob.ObjectMeta, true, apivalidation.ValidateReplicationControllerName, field.NewPath("metadata"))
allErrs := apivalidation.ValidateObjectMeta(&cronJob.ObjectMeta, true, apimachineryapivalidation.NameIsDNSSubdomain, field.NewPath("metadata"))
allErrs = append(allErrs, validateCronJobSpec(&cronJob.Spec, nil, field.NewPath("spec"), opts)...)
if len(cronJob.ObjectMeta.Name) > apimachineryvalidation.DNS1035LabelMaxLength-11 {
if max := apimachineryvalidation.DNS1035LabelMaxLength - 11; len(cronJob.Name) > max {
// The cronjob controller appends a 11-character suffix to the cronjob (`-$TIMESTAMP`) when
// creating a job. The job name length limit is 63 characters.
// Therefore cronjob names must have length <= 63-11=52. If we don't validate this here,
// then job creation will fail later.
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), cronJob.ObjectMeta.Name, "must be no more than 52 characters"))
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), cronJob.Name, content.MaxLenError(max)))
}
return allErrs
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/batch/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ func TestValidateCronJob(t *testing.T) {
},
},
},
"metadata.name: must be no more than 52 characters": {
"metadata.name: must be no more than 52 bytes": {
ObjectMeta: metav1.ObjectMeta{
Name: "10000000002000000000300000000040000000005000000000123",
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -2885,7 +2885,7 @@ func TestValidateCronJob(t *testing.T) {

errs = ValidateCronJobUpdate(&newSpec, &oldSpec, corevalidation.PodValidationOptions{})
if len(errs) == 0 {
if k == "metadata.name: must be no more than 52 characters" {
if k == "metadata.name: must be no more than 52 bytes" {
return
}
t.Errorf("expected failure for %s", k)
Expand Down
Loading