-
Notifications
You must be signed in to change notification settings - Fork 1.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
ClusterClass Patches add operation can not concatenate a list to existing list #6245
Comments
I'm not sure how we can implement it given that JSON patch does not support any such operation. Do you have an idea how this can be solved within the limitations of the JSON Patch RFC6902 spec that we're using? (related #5944) |
I tried to initialize a list by add operation. As long as the stanza is empty, the json patch creates a list for me. But it means only the first patch to that stanza can work like concatenation. jsonPatches:
- op: add
path: /spec/template/spec/kubeadmConfigSpec/files
valueFrom:
template: |
{{- range .foo }}
content: |
{{ .data }}
{{- end }} |
Yup. I think that's how JSON Patches (RFC6902) work. I think if the array essentially does not exist, it is added. If it already exists it adds the whole array as a new array element. |
But it implies that if I have another array type variable called |
Yup definitely. In general adding an array to an existing array will lead to the nested array. Independent of how that situation occurs (from two variables or if the array already exists before) |
@sbueringer should we close #5944 in favor of this? It seems to cover the same ground, just in a less detailed way. |
Sounds good. I think at some point we mainly wanted to document the limitation in #5944. But as that's done we can close it. (I'll do it) |
One possible way of solving this might to enhance the Examples of similar idea can be seen in ansible task loops construct https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html The idea would be something like below:
The above code then could iteratively apply new jsonpatch add within the guideline on the RFC and still provide a solution. Note: What I am suggesting is not to support all possible looping constructs that ansible supports, but rather just have support for the most basic looping over array object |
/milestone v1.2 However, given that Runtime SDK/external patches is still a WIP we could also consider an option that does not require API changes nor adding other abstractions/constructs on top of JSON patches. The idea is to surface a new built-in variable with the current value being replaced and then rely on sprig functions; the expected result should be something like
But this requires a little bit of research first |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
@sbueringer @weikaipan can we close this now that we have topology mutation hooks? |
I think we have no intention to implement it for inline patches. So in my opinion - yes. (there also wasn't that much demand for it looking at the issue history) |
/close per above |
@vincepri: 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. |
User Story
As a operator I would like to author a patch that create a list of items and concatenate it to an existing list for users who supply an unknown size of list in
Cluster
Variables
Detailed Description
ClusterClass
Cluster
VSphereMachineTemplate
This results in error below
Since currently appending a list to a list resulting a nested list.
https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md#writing-json-patches
Anything else you would like to add:
[Miscellaneous information that will assist in solving the issue.]
/kind feature
The text was updated successfully, but these errors were encountered: