-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use an empty map with kubebuilder:default marker #550
Comments
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closing this issue. In response to this:
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/test-infra repository. |
/reopen |
@MaxThom: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
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/test-infra repository. |
Im facing the same exact issue. |
/reopen |
@Danil-Grigorev: Reopened this issue. In response to this:
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/test-infra repository. |
Hi,
I'm using kubebuilder to generate a CRD from the following type definition (minimized):
This gives the following CRD (comments added manually):
The issue I'm facing is that if I apply an empty spec for my custom resource, with
spec: {}
thenfoo
only contains the golang type defaults, e.g.baz
is 0 andqux
is an empty string.If I use
spec: {foo: {}}
thenfoo
is populated with all the correct default values for its properties, however I don't want to force my clients to definefoo
.If I modify the CRD manually (after
controller-gen
, but beforekustomize
) to adddefault: {}
inside the CRD, everything behaves as expected, and an empty spec gives a correct CR when usingkubectl get
:The current workaround I've found is to use the following annotation (which is non-ideal):
This has the effect of defining
foo
with the correct defaults, butfoo.baz
takes the value defined in foo's default over baz's default, so this can override default values on properties if the defaults are changed.It seems the main issue is that controller-gen parses
{}
as an empty slice, whichjson.Marshal
then marshalls asnull
, which gets ignored when writing the CRD. Here's the code that scans the slice, it appears this edge case was considered but not implemented yet:https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/markers/parse.go#L297
Hopefully this is fixable without breaking stuff, or maybe a cleaner workaround can be found 🙂
The text was updated successfully, but these errors were encountered: