-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
CustomResourceDefinitions should support maps in OpenAPI schema #59485
Comments
There is a workaround to this: JSONSchema has something called as
I understand that having a map means that you don't know about the keys in advance but you can modify the regex to support all keys. Hijacking some comments from the previous thread #58746: @sttts wrote:
Using @ash2k wrote:
Like @ash2k mentioned, maybe we should make it the responsibility of the author to make sure that forward compatibility exists for In a gist,
|
Also, in #59972, we can make sure that we strip only those fields which are not present in |
I'm lost in the background discussion in the other bug, but I see a few mentions of workarounds .. could someone please summarise for me what I should put in my CRD schema now so a |
I'm getting an error while trying to use PatternProperties: map[string]apiext_v1b1.JSONSchemaProps{
".*": {
Type: "string",
MaxLength: int64ptr(63),
Pattern: "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$",
},
}, Error: |
Er, yes, that's because OpenAPI v3 does not support https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject https://docs.google.com/spreadsheets/d/1Mkm9L7CXGvRorV0Cr4Vwfu0DH7XRi24YHPiDK1NZWo4/edit#gid=0 |
because it seems like it's not supported by kubernetes 1.9: kubernetes/kubernetes#59485 (comment)
I might have a solution to this, the problem with using |
This is a common type when CRDs have spec:
nodeSelector:
ingress: true This breaks controller for this CRD. Because now both So, we would like to see this supported in CRD schema. |
Added a milestone. IMO we have to solve this in 1.11. Who has capacity to work on this? |
[MILESTONENOTIFIER] Milestone Issue Needs Approval @ash2k @kubernetes/sig-api-machinery-misc Action required: This issue must have the Issue Labels
|
@sttts I'm interested. This is also in my gsoc proposal. |
Automatic merge from submit-queue (batch tested with PRs 59027, 62333, 57661, 62086, 61584). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. CustomResources: in OpenAPI spec allow additionalProperties without properties This implements @ayushpateria's idea #59485 (comment). With this PR it becomes possible to specify `map[string]Interface{}` non-object types, e.g. `map[string]string` for selectors. On the other hands, "normal" objects use `properties`, mutually exclusively to `additionalProperties`. This way we avoid a conflict with Kubernetes API conventions that unknown objects fields are dropped. Fixes #59485 ```release-note Allow additionalProperties in CRD OpenAPI v3 specification for validation, mutually exclusive to properties. ```
Automatic merge from submit-queue (batch tested with PRs 59027, 62333, 57661, 62086, 61584). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. CustomResources: in OpenAPI spec allow additionalProperties without properties This implements @ayushpateria's idea kubernetes/kubernetes#59485 (comment). With this PR it becomes possible to specify `map[string]Interface{}` non-object types, e.g. `map[string]string` for selectors. On the other hands, "normal" objects use `properties`, mutually exclusively to `additionalProperties`. This way we avoid a conflict with Kubernetes API conventions that unknown objects fields are dropped. Fixes #59485 ```release-note Allow additionalProperties in CRD OpenAPI v3 specification for validation, mutually exclusive to properties. ``` Kubernetes-commit: f3cad465d53a77c7b6b1f073b79755d4644d7011
Maybe, the OpenAPI specification could allow a pattern to be defined on the key of a dictionary. |
There is no |
What happened:
Currently it is not possible to set
additionalProperties
in a CRD validation section of the spec to a schema. If set, validation rejects such CRD. That means OpenAPI schema for CustomResourceDefinitions does not support describing fields that are "maps" i.e. objects that do not have a pre-defined set of properties. Examples of such fields are labels and annotations in object metadata. For more context please see #58746.What you expected to happen:
It should be possible to describe a schema for a field that is a
map[string]string
equivalent in a Go struct (or amap[string]<anything valid here>
/etc where keys are not known in advance). For example to restrict the keys that can be used - see https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set./kind bug
/sig api-machinery
/area custom-resources
/cc @sttts @nikhita
The text was updated successfully, but these errors were encountered: