🐛 fix(crd): +kubebuilder:default={} now includes nested field defaults in generated CRDs#1392
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: camilamacedo86 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
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 |
a1617c1 to
61c75f1
Compare
a6d092b to
a393310
Compare
…in generated CRDs
a393310 to
92bcaf9
Compare
|
Hi @sbueringer,
This is not a breaking change. The actual runtime behavior stays the same. The Kubernetes API server already applies defaults recursively from top to bottom.
So the end result is identical. What actually changes is only the generated CRD YAML:
This just makes the defaults easier to understand.
Yes, exactly — this PR doesn’t change that behavior. It just makes it visible in the schema and avoids confusion (as described in #622). Before, users would see I also added tests to confirm this behaviour, and that is not a breaking change. |
|
PR needs rebase. DetailsInstructions 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. |
Problem
Using
+kubebuilder:default={}on an object field does not include nested defaults in the generated CRD schema. Then, CRD showsdefault: {}instead of a populated object with merged nested defaults.Therefore, users looking at the CRD schema cannot see what default values will actually be applied, leading to confusion and bug reports (see #622).
Example
Go
Before (broken)
After (fixed)
Fix
When a schema has default: {} (empty object):
Result: users get a fully populated default object.
For users regenerating CRDs:
When you regenerate CRDs with this version, you'll see a one-time diff showing merged defaults:
This is cosmetic only - runtime behaviour is unchanged. Review and commit the updated CRD.
No action required for existing resources - they continue to work unchange
Fixes: #622