Skip to content
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

double braces (for helm stuff) get a space put in between them #246

Open
naseemkullah opened this issue Nov 11, 2019 · 17 comments
Open

double braces (for helm stuff) get a space put in between them #246

naseemkullah opened this issue Nov 11, 2019 · 17 comments

Comments

@naseemkullah
Copy link

{{ become { { ... not desired

@cfiderer
Copy link

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 ?

@JPinkney
Copy link
Contributor

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

@cfiderer
Copy link

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?

@JPinkney
Copy link
Contributor

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

@unacceptable
Copy link

unacceptable commented Jun 12, 2020

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... }}.

@liyzcj
Copy link

liyzcj commented Nov 3, 2020

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.

@c0bra
Copy link

c0bra commented Mar 17, 2021

"yaml.format.bracketSpacing": false,

Not working for me.

@a-ski
Copy link

a-ski commented Mar 21, 2021

@c0bra Try "prettier.bracketSpacing" instead.

@coopbri
Copy link

coopbri commented Mar 29, 2021

@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!

@liyzcj
Copy link

liyzcj commented Mar 30, 2021

"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.

@skyward-luke
Copy link

I created ~/.prettierignore file, added *.yaml, *.yml to it, then updated vscode User setting "prettier.ignorePath": "~/.prettierignore".

@gcsfred2
Copy link

Pain in the neck.

@ben-walters
Copy link

ben-walters commented Aug 8, 2022

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,
      },
    },

@dimaqq
Copy link

dimaqq commented Sep 17, 2023

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.

@MurzNN
Copy link

MurzNN commented Apr 15, 2024

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!

@gszentesi
Copy link

+1

@jwilkicki
Copy link

jwilkicki commented Oct 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests