-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Patch literal JSON in ConfigMap item #680
Comments
@narg95 Patching doesn't support that. It will replace the value of |
It seems to be a common practice to store config files in ConfigMap properties. |
I need this as well. Another option would be to pass along var references to the external program as environment variables and use the output of that program as the configmap. @Liujingfang1, would that be better aligned with the philosophy of kustomize? |
Hi @Liujingfang1,
In a greenfield project I will do as suggested, but I am porting an application, that uses a rather complex json config file, to kubernetes, so using a ConfigMapGenerator will not be ideal because I would have to repeate the whole JSON file for a trivial json property change. I currently solve it post-processing kustomize's output with If this is a wanted feature I am willing to invest some time in a PR, but if this is something very specific to my use-case I rather solve it by using configMap literals, which can be re-used and overrided, and add a sidecar that converts it to the expected application config json format. @Liujingfang1 let me know your thoughts! |
@narg95 According to the comment history here, it could be a common use case. If would be nice if Kustomize can provide some convenience here. The example listed is a JSON file as the value. There are other cases as well. For example, I may have the configmap generated from following files
There is no limitation on what type of files can be used to create a ConfigMap. How to detect the format and apply proper merging is tricky. |
@Liujingfang1 thanks for your feedback!
did you mean: "generated from a file with the following values" right?
right, it should be extensible to incrementally support more patching strategies, we can start with The following example shows my two-cents proposal :) , note the new ExampleOverlaykustomization with patch
patch.json
basebase/my-app/kustomization.yaml
my-app-settings.json {
"name": "my app",
"environment": "demo",
"version": "1.0",
"args": ["--debug-mode"]
} output
I'd love to hear your opinions @Liujingfang1 @dperetti @ajbouh ! |
One more option to discuss here: make it possible to render configmap/secret content as templates, e.g. golang templates. I understand that kustomize's awesomeness stems from the fact that it does not use templating to build kubernetes objects which are structured data by nature. But configmap/secret content is opaque data, so making it possible to render with templates sounds cool. For example make it work like helm template processing, but only for configmap/secret content. Maybe other literal field content, e.g. JSON stored in annotations. Here's a very rough sketch of how this might look like:
I'm not presenting an API for review here as it definitely needs more thought, but more an idea of what you could accomplish with it. |
Attemping to summarize: Say you want to use kustomize to make the configmaps used in production differ in some way from that used in development and staging. Mixins might work. Suppose the configmap held a java properties file (k=v pairs, one per line), and one wanted to use kustomize to “edit” the value for one particular key. The kustomize way to do this would be to split the file - put the bulk of the k=v’s into a configmap in the base, then put the particular k=v in an overlay and get the final configmap as a merger (example) which then goes to production or development, etc. This works because kustomize understands that particular file format. It knows the values are whatever comes between the More generally, configmap values are opaque to k8s - they could be a simple port number, or some snippet of json/javascript/lisp/whatever. A scheme to allow kustomize to edit any configmap value would have to be in the form of an unstructured edit, e.g.
@narg95 focusses on a structured JSON edit instead of an unstructure edit, to address the particular case of an app being ported to k8s that consumes some complex JSON config file, and @narg95 wants to apply structured edits (e.g. to get loglevel:info in production instead of loglevel:debug). @narg95 SGTM - can you write a short KEP (e.g 892, 886) - you pretty much have the meat of it above - and then provide the impl? Do you have any notion of how common this might be? It’s a structured edit, so it’s consistent with kustomize in that sense. As an aside, Secrets are getting a big upgrade, where we allow a plugin to generate KV pairs (since the V’s are not just opaque - they are secret). This isn’t an patch mechanism (create KV’s only), and it’s not going to be active in configmaps - but folks on this thread might be interested. |
@monopole Maybe I'm missing something, but adding another file to configMap is not actually a merge. |
this is another case where variables would help like https://github.com/kontena/mortar has |
@narg95 this can be done in the following way: Below is in a file
The kustomization file looks like
params.env contains
params.yaml contains
Note that this inserts an extra ConfigMap which you would probably delete afterwards.
outputs
|
@kkasravi works fine except the config hash (if enabled) won't be updated when vars change, which result in the deployment can not rolling update. |
Hi @kkasravi, thanks for the explanation and the code! I ended up with a similar solution but in my case at that time I generated all the configs with |
Hi, just met the same issue here.
Should result in a configmap with a single key |
Hi, same problem here. |
@SilverXXX @benjamin-bergia The configMapGenerator overlay does not seems to work write. There is bug in the Resource.replace/merge implementation and we end up with invalid labels: apiVersion: v1
data:
settings.cfg: |
Content of the overlay settings.cfg
kind: ConfigMap
metadata:
annotations: {}
labels: {}
name: my-configmap-8gkkcddg96 |
@ikatson @monopole @Liujingfang1 I think this another use case where the autovar PR We are basically able to achieve exactly what ikatson was asking without templating and by levering multiple key features of kustomize. Have a look at the third solution The output is basically the following: apiVersion: v1
data:
app.properties: |
foo=production-foo-value
bar=production-foo-value
kind: ConfigMap
metadata:
name: myJavaServerProps-7m6dhd66bg
---
apiVersion: v1
kind: Values
metadata:
name: file1
spec:
bar: production-foo-value
foo: production-foo-value |
Nothing? Sometimes the unresponsive attitude of kustomize team about open issues/prs are really sad. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
Will there ever be a valid solution for patching a JSON base/thing/kustomization.yaml
overlay/foo/kustomization.yaml
This is really error prone and not ideal. Is there not some way we can use |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: 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. |
Just a note to say this is still needed... |
not sure if i can/should but |
@afirth: 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. |
How do we do this now that var is deprecated? |
/remove-lifecycle rotten |
Hi all,
I want to patch a literal json from a configMap item, but I have not found an example in the docu, do you know if that is possible? For example, assuming the following configmap:
Base configMap
I want to apply this patch:
So the resulting configMap looks like:
Thanks !
P.S. Great job with kustomize!
The text was updated successfully, but these errors were encountered: