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

Escaping template strings not working #3989

Closed
hnicke opened this issue Mar 23, 2023 · 3 comments · Fixed by #5680 or #6408
Closed

Escaping template strings not working #3989

hnicke opened this issue Mar 23, 2023 · 3 comments · Fixed by #5680 or #6408
Labels
bug devex Developer experience and ease of use. feat/templating Templating in variables and configs triage/accepted

Comments

@hnicke
Copy link
Contributor

hnicke commented Mar 23, 2023

Bug

Current Behavior

I need the literal value ${foo} in a resulting k8s template of a garden kubernetes module.
The garden docs describe how this should be done: Using $${} instead of ${}.

...
command: [ bash ]
args:
  - c
  - |
    ....
    -d '$${foo}'

However, it ends up literally like this after rendering:

...
command: [ bash ]
args:
  - c
  - |
    ....
    -d '$${foo}'

I.e., no interpolation at all happened.

Garden doesn't eat the dollar. Maybe this only happens in the free tier 😆

Expected behavior

I expect this to be the result of the template rendering:

...
command: [ bash ]
args:
  - c
  - |
    ....
    -d '${foo}'

Additional idea

@worldofgeese pointed me to the docs, which I haven't found on my own.
I suggest moving the whole Escaping template strings paragraph from Module Templates to Variables and Templating. My understanding is that the Module Templates page only holds information in regards to the kind: Module; type: templated modules. The interpolation escape mechanism however is a globally available feature, right?

Your environment

  • OS: arch linux
  • How I'm running Kubernetes: GKE

garden version
v0.12.53

@hnicke hnicke changed the title Escaping template strings to working Escaping template strings not working Mar 23, 2023
@vvagaytsev vvagaytsev added bug triage/accepted devex Developer experience and ease of use. labels Mar 30, 2023
@vvagaytsev vvagaytsev moved this to Candidate in Core Weekly Jun 23, 2023
@vvagaytsev vvagaytsev moved this from Candidate to Todo in Core Weekly Jun 26, 2023
@vvagaytsev vvagaytsev assigned vvagaytsev and TimBeyer and unassigned vvagaytsev Jun 26, 2023
@orymate
Copy link

orymate commented Aug 10, 2023

We've workarounded this by rearranging the manifest templates in a way that all variable substitutions come before the parts that need escaping, and adding a comment like # hack: $${} between the two. No variable substitutions are done in the second part of the manifest, at least in 0.12.60.

...
spec:
  loggingRef: ${environment.namespace}-demo  # TODO garden fails to expand this variable after the first escape, keeping this line before that
  # hack: $${}
  filters:
    - parser:
        metrics-probe:
          key: "probe"
          labels:
            namespace: "${json#kubernetes#namespace_name}"  # the manifests contain these exact label templates that use similar variable expansion syntax as garden
            pod: "${json#kubernetes#pod_name}"

@vvagaytsev
Copy link
Collaborator

@orymate thanks for sharing the workaround!

@vvagaytsev
Copy link
Collaborator

@orymate we have fixed this in 0.13.39. Feel free to try it out!

Please note, that the workaround cannot be used along with 0.13.39.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug devex Developer experience and ease of use. feat/templating Templating in variables and configs triage/accepted
Projects
None yet
5 participants