-
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
🐛 Allow nested maps in Go types #518
Conversation
I noticed that previously an error was being generated, but it does not get surfaced anywhere and |
Using maps in Kubernetes API resources at all is not recommended (as per the sig-architecture api-conventions doc): Not too sure if it's something the project still wants to accept anyway - but it'd be good for us to encourage following the api conventions doc through the feature-set exposed |
In our case we are accepting specs for external resources which require maps and nested maps in their configuration. Without support in |
This will also unblock ACK (AWS Controllers for Kubernetes) project. ACK uses controller-gen to create Kubernetes custom resources for AWS resources. There are AWS resources which contain nested map and fails with controller-gen. I also second @Porges 's thought here. |
These map to nested maps in CRDs. Also improve an error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
/assign @DirectXMan12 |
* Regenerating apigatewayv2 service controllers after repo split. * Using aws-sdk-go 1.35.5 because latest sdk-go is not compatible with controller-gen 0.4.0 . The PR for compatibilty is tracked here kubernetes-sigs/controller-tools#518
Sorry for the delay on this - for context, I do not have approval rights here :)
Embedding external types (i.e. ones that were not originally designed to be used as part of a Kubernetes API) is also something that has been typically best avoided. I would always strongly recommend either building your own abstraction over these types (and writing functions that can be used to convert from your API type to the external project's types), or otherwise using something like When you begin to generate e.g. openapi schemas, conversion functions, and even DeepCopy functions, you can quickly run into all sorts of issues if you have embedded an external type. I'm conscious that by supporting it, we'd encourage this kind of thing in other projects/APIs. I can appreciate that there are some projects wanting to use maps, but I think as a project we should help users to do the right thing. Interested to hear viewpoints from others (cc @DirectXMan12 @pwittrock) |
@munnerz The kinds of things we are embedding are configurations, so it's nice for the end user if the configuration format is the same inside Kubernetes or outside it. With regards to API complexity: I'd note that you can already write I’ve added an example of this to the test file. |
This is not supposed to be possible, and I'd almost consider it a bug that we allow it. At the very least, it's a non-reccomended type -- maps in Kubernetes APIs are generally restricted to scalar values, and the occasional slice in very specific circumstances. Otherwise, Kubernetes-style associated lists are the reccomended pattern. |
/hold |
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. |
/remove-lifecycle stale |
To comment directly here, kube discourages but does not disallow certain constructs in core apis. I would not consider any construct described here as dangerous, nor would I say our api conventions are a counter to the stated goal for CRDs to allow the kube server to accommodate new concepts to extend Kube. As an API reviewer I might guide a core API author away from map of map, but that should not constrain how users can express valid CRD APIs in wide use. Map of map should absolutely be allowed under a CRD, and in general any valid JSON structure should be allowed inside of the body of a CRD (any limitations are bugs). |
/test all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/label tide/merge-method-squash
/hold cancel
/assign @vincepri
/lgtm |
In that case the array-value case should be loosened as well (currently only |
/assign @droot |
@Porges can you resolve the merge conflicts, please? |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, Porges, vijtrip2 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
voilà! |
/test all |
These map to nested maps in CRDs. Also improve an error message.
I have marked this as a bug, as the omission of support for these nested maps seems like an oversight, since there is already support for and tests for nested maps in the deep-copy code (in
legacy_deepcopy_cases.go
).Note that in addition a type like
map[string]Foo
whereFoo
has a fieldmap[string]string
is already permitted, so this only allows an “unwrapped” version of the above. (An example of this is also added into the test as part of this PR.)This will help address some cases in #287.