🌱Add envtest tests for +kubebuilder:default={} with nested field defaults by camilamacedo86 · Pull Request #1392 · kubernetes-sigs/controller-tools · GitHub
Skip to content

🌱Add envtest tests for +kubebuilder:default={} with nested field defaults - #1392

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-issue-nested-values
Aug 30, 2026
Merged

kubernetes-prow[bot] merged 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-issue-nested-values

Conversation

@camilamacedo86

@camilamacedo86 camilamacedo86 commented Apr 27, 2026 •

Copy link
Copy Markdown
Member

Adds test coverage for the scenarios in #622 (+kubebuilder:default={} on a pointer field whose nested fields have their own defaults)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 27, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 27, 2026
@sbueringer

Copy link
Copy Markdown
Member

This seems like a breaking change to me.

Additional I think the CRDs we generate already behave this way as the apiserver recursively defaults top down

@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch from a1617c1 to 61c75f1 Compare April 29, 2026 10:54
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 29, 2026
@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch 3 times, most recently from a393310 to 92bcaf9 Compare April 29, 2026 11:21
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2026
@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch from 92bcaf9 to 7bf3534 Compare June 28, 2026 19:53
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2026
@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch from 7bf3534 to 5b00aab Compare June 28, 2026 20:45
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 28, 2026
@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch from 5b00aab to 6795224 Compare June 28, 2026 20:51
@camilamacedo86 camilamacedo86 changed the title 🐛 fix(crd): +kubebuilder:default={} now includes nested field defaults in generated CRDs 🌱Add coverage to demonstrate that the scenario from 622 is solved Jun 28, 2026
@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch 2 times, most recently from ac6b199 to 28e6c25 Compare June 28, 2026 21:03
@camilamacedo86

camilamacedo86 commented Jun 28, 2026 •

Copy link
Copy Markdown
Member Author

Hi @sbueringer,

Sorry, I took a closer look at this, and you're absolutely right to push back.

I also read your comment on the issue, and I agree.

We could add tests to verify the current behavior, but I don't think this warrants keeping the issue open. I'll leave a comment on the issue and suggest we close it.

@JoelSpeed

Copy link
Copy Markdown
Contributor

This doesn't really test our behaviour so much as it tests the API server behaviour, but I guess if that's beneficial to make sure that if the upstream behaviour changes, that we can handle it, then I'm ~ok with merging this

/lgtm

@sbueringer do you agree?

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: b953854e8253fd092eef1fd57c00a956a5d015fd

@camilamacedo86

Copy link
Copy Markdown
Member Author

Hi @sbueringer,

Could you please help with this one?

After taking a deeper look and revisiting your comment, I completely agree with your feedback. We're only adding tests here now, as discussed: #622 (comment)

Thank you so much for your help!

@sbueringer

sbueringer commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

This doesn't really test our behaviour so much as it tests the API server behaviour,

Agree. controller-gen just takes the default values from the markers and sets them in the corresponding fields in the CRD. I assume we already have sufficient test coverage for this. Accordingly this PR just adds regression test coverage for the defaulting code in the kube-apiserver. I would assume and hope that this test coverage already exists in the k/k repository and they don't intentionally make breaking changes to the v1 CRD API.

but I guess if that's beneficial to make sure that if the upstream behaviour changes, that we can handle it, then I'm ~ok with merging this
@sbueringer do you agree?

Independent of that, as Joel's okay with it and I don't have a strong objection against it, I"m fine with adding this test coverage.

But can we please change this test to use envtest so it tests actual kube-apiserver behavior? This would not be guaranteed if we directly call the same functions that the apiserver is currently calling internally. Additionally the maintenance effort for the test should be lower if we don't have to keep the test code in sync with the kube-apiserver code.

Please also change the PR title to refer to what we are testing vs. just pointing to an issue.

@camilamacedo86
camilamacedo86 force-pushed the fix-issue-nested-values branch from 28e6c25 to 0c68234 Compare July 28, 2026 12:18
@kubernetes-prow kubernetes-prow Bot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 28, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from JoelSpeed July 28, 2026 12:18
@camilamacedo86 camilamacedo86 changed the title 🌱Add coverage to demonstrate that the scenario from 622 is solved 🌱Add envtest tests for +kubebuilder:default={} with nested field defaults Jul 28, 2026
@camilamacedo86

camilamacedo86 commented Jul 28, 2026 •

Copy link
Copy Markdown
Member Author

Hi @sbueringer

Thank you for looking this one.

But can we please change this test to use envtest so it tests actual kube-apiserver behavior? This would not be guaranteed if we directly call the same functions that the apiserver is currently calling internally. Additionally the maintenance effort for the test should be lower if we don't have to keep the test code in sync with the kube-apiserver code.

That was indeed a good idea and suggestion done !
Rebased with main as well.
So we are probably good to fly 🪰 here.

@sbueringer

Copy link
Copy Markdown
Member

Thx

/lgtm

/assign @JoelSpeed
(in case you want to take another look)

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 28, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: f1c6055a2ab81ac808a5f2f5b23fd3727734ce02

@camilamacedo86

Copy link
Copy Markdown
Member Author

@JoelSpeed could you give a help here for we get this one merged?

c/c @sbueringer

@sbueringer

Copy link
Copy Markdown
Member

I think it's okay, let's merge

/lgtm
/approve

@kubernetes-prow

Copy link
Copy Markdown
Contributor

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 56c538d into kubernetes-sigs:main Aug 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants