-
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
Proposal: Replacements and Patch value in the structured data #4558
Proposal: Replacements and Patch value in the structured data #4558
Conversation
Hi @koba1t. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/ok-to-test |
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.
Thanks for writing this up! It looks great. Some comments, mostly that we should include the ConfigMapGenerator proposal here too, that's already written up here #680 (comment) and we should try to make sure the two syntaxes for replacements and ConfigMapGenerator make sense when we look at them side by side.
@koba1t: This PR has multiple commits, and the default merge method is: merge. 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, @natasha41575. Sorry for the delay to reply. |
Thank you! Will take another look later this week |
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.
Overall this is getting close to something I am open to accepting. I have some minor wording suggestions in the motivation section so that the scope is clear, and apart from that I'd like to get more feedback about the configMapGenerator syntax from @KnVerey.
- name: demo-settings | ||
behavior: merge # This function requires `behavior: merge`. | ||
option: | ||
valueStructuredMergeFormat: json # Setting structured data format. |
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.
I see you've made a modification to the original proposal in #680 (comment), which looks like:
configMapGenerator:
- name: demo-settings
behavior: merge
patchContent: json-strategic-merge
- file: my-app-settings=patch.json
- literals:
- foo= -|
{
"logLevel": "info"
}
I feel that the original proposal is a bit more descriptive, but yours feels a bit more closely tied with the replacements syntax. WDYT about doing this:
configMapGenerator:
- name: demo-settings
behavior: merge # This function requires `behavior: merge`.
option:
patchContent: strategic-merge
format: json # Setting structured data format.
literals:
- config.json: |-
{
"config": {
"hostname": "REPLACE_TARGET_HOSTNAME",
"value": {
"foo": "bar"
}
}
}
?
@KnVerey would also appreciate your feedback on the right syntax here
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.
hi @KnVerey
Could you give me any feedback for this?
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.
Hmm...
I thought this implementation would only be used to simply merge 2 or more json contents.
And if we're implementing json6902 , we probably need extra sintax like patchesjson6902.
So, if you have other ideas, could you please tell me?
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.
I don't think it is easy to understand what happens with this syntax.
# overlay/kustomization.yaml
resources:
- ../base
configMapGenerator:
- name: demo
option:
patchContent: json6902
format: json # Setting structured data format.
literals:
- config.json: |-
- op: replace
path: /config/value/foo
value: qux
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.
Sorry for the extreme delay. First, I don't think we should support json6902 or anything other than strategic merge, i.e. the behavior already implied by behavior: merge
for the rest of the object. That seems sufficient to cover the use case.
Second, I think this option needs to move up a level, i.e. in GeneratorArgs
rather than GeneratorOptions
. The latter can be provided globally in a kustomization, and the new data here is specific to the generated object in question.
Third and most importantly, I think we need more information from the user than what the proposals so far have provided for. During overlay configmap generation, we essentially end up with a configmap from the base + a new one from the overlay's files/envs/literals. Currently, behavior: merge
applies the overlay to the base as an SMP. To support this feature, it seems to me will first need to merge specific fields' values as SMPs before merging the whole object. How do we know which fields we need to do that for? We can't assume they're all JSON whenever the user wants one of them to be merged.
configMapGenerator:
- name: demo-settings
behavior: merge
mergeValues: # or something like mergeOptions.yamlValues? Not under "options" at any rate
- config.json # Value at this key MUST be YAML/JSON
literals:
- config.json: |-
{
"config": {
"hostname": "REPLACE_TARGET_HOSTNAME",
"value": {
"foo": "bar"
}
}
}
Finally, a bit of a sidenote: if you try to specify duplicate keys across literal, env and file sources, Kustomize currently throws an error. That behaviour should be retained. In other words, the new feature should only affect the final merge operation.
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.
@KnVerey
I fix from your comments. At d99011f
Cloud you recheck it to reflect on your suggestion?
Second, I think this option needs to move up a level, i.e. in GeneratorArgs rather than GeneratorOptions.
I move it.
Third and most importantly, How do we know which fields we need to do that for?
I think it is my insufficient consideration and agree with you. I add a parameter to choose a key for the configMap.
But, I think we need any parameter to select a value format which is JSON or YAML. because we can't discriminant clearly the value format when it is not selected with the file extension. For example, value is used by env in deployments like JSON in the environment values.
Therefore I try to add a parameter mergeValues.format
to select the value format which is JSON or YAML.
d99011f#diff-2b5a81ecf356afb37e2653ac1e2daf0b6af6cd126aec835df3c25b2a8be29389R153-R155
|
||
kustomize can strong patch to Kubernetes objects (yaml file in most cases) with structured edit. And, It is structured data.\ | ||
Sometimes structured multi-line or long single line string (ex. json,yaml, and other structured format data) is injected in Kubernetes objects' string literal field. And, kustomize seems it only string literal.\ | ||
So, kustomize can't manipulate one value on structured, formatted data in the Kubernetes object's string literal field. This function is expected behavior, but kustomize will be very helpful if it can change the value of structured data like json and yaml substrings in a string literal.\ |
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.
So kustomize doesn't allow it to be manipulated. This is expected behavior, but we would like to make an exception for some structured JSON within string literal fields.
a037c1e
to
f232602
Compare
2e9c750
to
647113f
Compare
/remove-lifecycle stale |
@natasha41575 @koba1t @KnVerey Any updates or projected timeline on this feature? This feature would resolve an issue that our management regularly mentions as a big drawback for kustomize. We often run into this scenario: a kubernetes deployment has been configured to read in a config file
This feature would not only save time/money but also improve the readability and maintainability of our code base. We'd love to see this prioritized and merged as soon as possible! |
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.
proposal LGTM
Thank you for working on this and pinging me. I think you will have to rebase to make the test suite run so we can merge this.
/lgtm
/approve
Once this is merged, I'll be interested to see what gaps (in existing vars functionality) remain to be filled. I created a discussion in hopes of clarifying the current deficits, as well as plans to address them: |
/lgtm cancel Ongoing discussion in #4558 (comment), should get resolved soon |
d99011f
to
2831689
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: koba1t, natasha41575 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 |
We appreciate the contributions and discussion but knverey is no longer active in this project.
This proposal decides the interfaces to change values in the structured data (like json,yaml) inside a Kubernetes objects' field value and implements changing function target a few formats (mainly json).
appendix