-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Question: how to handle user input parameters (RawExtension) in custom resource #3677
Comments
@natasha41575 Can you take a look at this? Looks like it's OpenAPI related. |
Is the settings field completely unstructured? Are users allowed to input any keys and values they choose? |
For the OpenAPI schema to merge correctly, it needs two variables in the OpenAPI schema that you would need to add manually (x-kubernetes-patch-merge-key and x-kubernetes-patch-strategy). E.g. for PodSpec containers, it looks like this:
For your case, the OpenAPI for settings would need to look something like:
If you know the desired merge key then you can put it in your OpenAPI specification. (Side note: working on documentation to make this more clear.) You may have to ask the user to specify their desired merge key. |
Right. Entirely unstructured.
The example you gave looks awesome! |
I did some investigation and I've discovered your problem. You also need to add the x-kubernetes-group-version-kind extension to your OpenAPI schema. This is unrelated to the merge keys. I used the following schema here and it worked for your use case: https://pastebin.com/L3igtp78. Notice at the very bottom I added a x-kubernetes-group-version-kind field. This is necessary for kustomize to be able to properly understand your schema. I am closing this issue, but feel free to reopen if for some reason this doesn't work for you or you have more questions. |
Hi, I'm working on the KubeVela project and trying to use Kustomize to handle multi-environment application deployment. We have a CRD that looks like below:
I'm super excited about the upcoming support for custom resource via OpenAPI schema. I have been hoping that once applying openapi schema we can use Kustomize native patchesStrategicMerge over our Application resources too.
I give it a try -- here is main.go and schema.json: https://gist.github.com/hongchaodeng/2a3fe0afcb7ab2e116d2533e407ce151
But something unexpected happens. The fields
settings
andproperties
are unstructured user input and of typeruntime.RawExtension
. The schema couldn't be know ahead of time and in openapi schema is described asobject
type:The problem is when applying patches it overrides instead of merging fields. Let me give an example below.
Here's the base:
Here's the patch:
Here will be the final output:
As shown above, the
keep
field is gone since the entiresettings
is overriden.Would appreciate any solutions for this problem. Thanks!
The text was updated successfully, but these errors were encountered: