Open naseemkullah opened 4 years ago
We're using Go templates in YAML files - and the space insertion breaks them. Furthermore, type checking doesn't work where templates are used (e.g. if the template expands to an integer.
Is it possible to stop checking when encountering a {{ }} sequence ?
Is it possible to stop checking when encountering a {{ }} sequence ?
I'm assuming you mean stop validating when {{}} are hit so that no error is reported? Technically it's possible but the problem is then we're implementing helm specific things into this extension when this extension is supposed to be only for pure yaml.
This extension has some support for helm that I think would be better suited: https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools you just need to change your file type association to helm and then the error dissapears
Our stuff is not Helm-related - it just uses the YAML as input to the Go template engine. So for the time being, the file in question is not pure YAML yet.
So the question remains: how can I configure the vscode-yaml extension that I can use it also for "not pure YAML yet" files?
how can I configure the vscode-yaml extension that I can use it also for "not pure YAML yet" files?
There's currently no way to do that, but it would be an interesting enhancement
Hey all! I got around this by strong quoting ('
) my go templating and my helmfile still seems to render my helm chart properly when examed with helmfile -f path/to/helmfile.yaml diff
.
Here's an example of what I mean:
- namespace: {{ requiredEnv "NAMESPACE" }}
+ namespace: '{{ requiredEnv "NAMESPACE" }}'
I haven't tested this in a helm chart yet so I don't know if this change will work there (meaning I am not sure if this will be interpreted properly by the go templating parser).
Additionally, I am not sure if this will work for stuff like Jinja2 (I don't think so) so it might be worth just writing an exception for this plugin to just ignore {{ ...blah... }}
.
A simple solution now is close the bracketSpacing in Yaml Plugin.
{
"yaml.format.bracketSpacing": false,
}
But this will get a 'side-effect', the space inside double braces also removed.
- {{.Values.node2}}
But at least it works now.
"yaml.format.bracketSpacing": false,
Not working for me.
@c0bra Try "prettier.bracketSpacing" instead.
@AdamPodolski's suggestion worked for me ("prettier.bracketSpacing": false
).
An alternative solution is to use a .prettierignore
file with *.yaml
inside, which will still allow Prettier to add bracket spacing on other file types.
Really wish they didn't remove the disableLanguages
config from prettier-vscode
!
"yaml.format.bracketSpacing": false,
Not working for me.
It's not work because you may using prettier as your yaml formatter, you can change your yaml formatter with
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml",
}
or use @AdamPodolski 's suggestion "prettier.bracketSpacing": false
, but the side effect is all languages formatted with prettier will ignore bracket spacing.
I created ~/.prettierignore file, added .yaml, .yml to it, then updated vscode User setting "prettier.ignorePath": "~/.prettierignore"
.
Pain in the neck.
Previously, i saw the above behaviour, but with "prettier.bracketSpacing": false
I now see this...
{{ include (print $.Template.BasePath "/configMap.yaml") . | sha256sum }}
Format to this...
{
{
include (print $.Template.BasePath "/configMap.yaml") . | sha256sum,
},
},
It seems that go-style templating of yaml files is just too common in kubernetes world... What this issue is about, I think, is devex, meaning, if I pick some existing codebase and make some small changes to it, I don't want my tools to break existing conventions. And FWIW k8s is kinda popular. Some kind of copout is needed.
P.S. '{{ val }}'
is not an answer, because some values must be of specific type, not strings.
So, still no solution without side effects found?
The recommended "prettier.bracketSpacing": false
produces this side effect:
But this will get a 'side-effect', the space inside double braces also removed.
That is very annoying!
Please add an option like prettier.bracketSpacing.ignore
that will skip all formatting of the bracket spacing!
+1
I'll add an extra use case.
The helmfile format allows in-line go templates in the values section of a release. I am using this behavior to pass in all of the values from the environment into a helm release like this:
- name: aws-load-balancer-controller-iam
namespace: kube-system
chart: ../argocd/aws-load-balancer-controller-iam
values:
- {{ toYaml .Values | nindent 8 }}
When I save the file the toYaml
gets destroyed:
- name: aws-load-balancer-controller-iam
namespace: kube-system
chart: ../argocd/aws-load-balancer-controller-iam
values:
- {? {toYaml .Values | nindent 8: ''} : '',}
I don't know what the syntax is supposed to be, but I've turned off JSON schema, disable formatters, turned off validation, turned off bracket spacing, and I'm still getting this output.
{{
become{ {
... not desired