-
Notifications
You must be signed in to change notification settings - Fork 45
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
[Feature Suggestion/Request] Helm YAML Templates #36
Comments
HELM should be valid YAML. I couldn't find a specific version of YAML, but I'd assume HELM is valid YAML 1.2. The problem you describing is not specific to this library, it will crash any YAML parser. In order to fix this ambiguity you have to do the following: 1. Enclose in templates in quotesYou can either use single or double quotes. For your specific usecase, if shouldn't really matter. apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ .Values.app.label }}-deployment"
spec:
replicas: "{{ .Values.app.replicas | default 2 }}"
selector:
matchLabels:
app: "{{ .Values.app.label }}"
template:
metadata:
labels:
app: "{{ .Values.app.label }}"
spec:
imagePullSecrets:
- name: secrets
containers:
- name: example
image: 'example/example:{{ .Values.image.tag }}' 2. Use multiline stringsIn this particular example I've used Folded Block Scalar Style with Strip Block Chomping (more info here) apiVersion: apps/v1
kind: Deployment
metadata:
name: >-
{{ .Values.app.label }}-deployment
spec:
replicas: >-
{{ .Values.app.replicas | default 2 }}
selector:
matchLabels:
app: >-
{{ .Values.app.label }}
template:
metadata:
labels:
app: >-
{{ .Values.app.label }}
spec:
imagePullSecrets:
- name: secrets
containers:
- name: example
image: 'example/example:{{ .Values.image.tag }}' Both examples are parsing just fine as demonstrated in https://ikatyang.github.io/tree-sitter-yaml/. Also have a look at HEML | Appendix: YAML Techniques | Indenting and Templates. |
To me it seems that it breaks when the helm chart uses control blocks, eg:
Or for loops are another possibility that isn't covered in normal YAML. |
@char0n You're correct, my example was poorly chosen. But @canadiannomad illustrates it better. It's not just possible to template values or items in arrays, or even only strings. But it's also necessary to template random parts of the chart.
Yes, you are correct. And I wasn't trying to imply that. If I miscommunicated, I apologize for that. I simply stumbled over this problem when trying to use |
@hellerbarde np, the examples could be written as valid YAML but having @canadiannomad provide more examples that prove that HEML is not a yaml disregard my comment ;] I'm not a maintainer here, so cannot do anything anyway to really help. |
According to my (little) knowledge, they can be at least two approaches to this issue:
|
Yeah, I think helm templates are go templates first and should be treated as such. The question I don't quite understand is who is responsible for identifying those go templates among the other yaml files. Is that the editor's job or does tree-sitter help with that? |
Hi, I have the same problem with Rails YAML Templates. Yes, the yaml file is not valid but is after being processed by erb. production:
clients:
default:
uri: <%= MongoClientUriBuilder.new(mongo_client_name: 'audits').call %>
options:
max_pool_size: <%= MaxPoolSizeComputer.new.call %> |
Do helm templates need to be included in this tree-sitter or should helm have it's own tree-sitter? |
I need this badly. |
https://github.com/ngalaiko/tree-sitter-go-template has support for Helm which includes yaml as well. |
Hi!
Helm Templates mostly consist of YAML, due to kubernetes resources commonly being specified in YAML. But due to the double curly bracket templating signifier, it trips this tree-sitter up (understandably, of course).
Is there something I could do to help tree-sitter in a direction to support this situation in some way?
And just to be clear:
I absolutely understand that syntactically, Helm templates are not valid YAML. And I absolutely do expect an answer along the lines of "this is not tree-sitter-yaml's problem", I just would like a hint in which direction I should go in search for a solution, because I don't know the tree-sitter ecosystem yet.
Helm Reference:
https://helm.sh/docs/chart_template_guide/getting_started/#adding-a-simple-template-call
Example case:
before.yaml
after.yaml
Tree-Sitter result is the same for both:
The text was updated successfully, but these errors were encountered: