Saturday, March 18, 2023
HomeGolangHelmfile/go template questions - Getting Assist

Helmfile/go template questions – Getting Assist


I’m implementing some go templates for Helmfile and I’m going through two points:

  1. {{ $identify := Launch.identify }}
    I have to render $identify inside Values
    I’m making an attempt with:
    {{ .Values.$identify.one thing }}
    however it doesn’t work, identical for:
    {{ .Values.{{$identify}}.one thing }}

  2. I have to have:
    worth: myurlone,myurltwo,myurlthree

Values.components → one, two, three

Values file:
components:
one:
web site:
url: myurlone
two:
web site:
url: myurltwo
three:
web site:
url: myurlthree

I’m making an attempt one thing like:

{{ -range $key, $worth := .Values.components }}
{{ be a part of “,” .Values.$worth.web site.url }}
However with no success.

Any assist can be a lot appreciated.


outlined variable

{{- $url := .Values.url}}
{{ -range $key, $worth := .Values.components }}
{{ $url }}{{ $key }}{{ $worth }}
{{- finish }}

Which level are you answering right here? 1 or 2? And the way do you outline $url in case you don’t have a $worth initially?

Thanks, however I don’t see there a technique to parse a variable contained in the {{ .Values }} scope.

Hello, Stefano, welcome to the neighborhood!

  1. By “Helmfile,” do you imply this: GitHub – roboll/helmfile: Deploy Kubernetes Helm Charts?

  2. I’m unclear on what you’re making an attempt to do. It sounds such as you’re parsing YAML and also you wish to render it into a distinct YAML schema with the textual content/template package deal. Is that proper?

    In that case, why not use a Go package deal for processing YAML like yaml package deal – gopkg.in/yaml.v2 – Go Packages?

    If not, are you able to restate your enter and desired output?

P.S.: Additionally, it’s often simpler for us to learn code snippets (particularly these the place whitespace is essential, like YAML) when they’re wrapped in backticks ( ` ) for instance:

`inline code` turns into inline code

Or for a number of traces, put 3 backticks ( “` ), then a brand new line, then your code, then a brand new line, after which one other 3 again ticks. For instance:

“`
a number of
traces
of
code
“`

turns into:

a number of
traces
of
code

This manner we will see the precise YAML format of the enter (and output?) YAML.

Hello Skillian,
sure, so the second query is about acquiring:

worth: myurlone,myurltwo,myurlthree

From the next YAML file:

components:
  one:
    web site:
      url: myurlone
  two:
    web site:
      url: myurltwo
  three:
    web site:
      url: myurlthree

So I have to one way or the other loop into the weather and get a comma separeted checklist of the URLs

{{ -range $key, $worth := .Values.components }}
{{ -- not working be a part of “,” .Values.$worth.web site.url }}

Are you able to inform me why you’re making an attempt to generate YAML with the textual content/template package deal as an alternative of utilizing a package deal particularly for coping with YAML, such because the one I linked to (yaml package deal – gopkg.in/yaml.v2 – Go Packages)? How are you parsing the YAML within the first place to make use of it within the template?

My config is made from YAML recordsdata and I’m templating K8s object given these YAMLs.
So the command is

helmfile -f helmfile.yaml -l identify=service template > output.yaml
oc apply -f output.yaml

Are you able to present an instance of the way you’re deserializing the enter YAML? Figuring out what type that’s in will assist reply your query about the way to produce the output.

This subject was routinely closed 90 days after the final reply. New replies are not allowed.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments