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

[Enhancement] Please clarify the use of double curly braces for jmesPath in external variables #1388

Open
jsalatiel opened this issue Oct 15, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@jsalatiel
Copy link

Description

It would be really nice if the docs could clearly explain the difference/possibility of using double curly braces in jmespath for external variables.
I tried to create a policy that would set a variable based in one optional annotation or fallback to another annotation ( mandatory ) , in this case prefixed by some path.

The only way that worked ( thanks to @realshuting ) was to mix part of the request without double curly brace and part of it with double curly brace like this.

    - name: mountpath
      variable:
        jmesPath: request.object.metadata.annotations.optional || '/etc/ssl/{{request.object.metadata.annotations.mandatory"}}'

It would be nice to have a better understanding of that in the docs. Is that only for concatenation? What else?

Thanks!

Slack discussion

https://kubernetes.slack.com/archives/CLGR9BJU9/p1728944204996649

@jsalatiel jsalatiel added the enhancement New feature or request label Oct 15, 2024
Copy link

welcome bot commented Oct 15, 2024

Thanks for opening your first issue here! Be sure to follow the issue template!

@realshuting
Copy link
Member

Adding working samples, playground.

@realshuting
Copy link
Member

By default for a plain JMESPath variable, no double curly brackets are needed in variable.jmesPath, for example:

    - name: mountpath
      variable:
        jmesPath: request.object.metadata.annotations.optional

Nested variables need to be wrapped with {{}}, for example:

    - name: mountpath
      variable:
        jmesPath: request.object.metadata.annotations.optional || '/custom/string/{{request.object.metadata.annotations.mandatory"}}'

@realshuting realshuting added the good first issue Good for newcomers label Oct 15, 2024
@A-5ingh
Copy link
Contributor

A-5ingh commented Oct 25, 2024

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Status: No status
Development

No branches or pull requests

3 participants