Search code examples
yamlkubernetes-helmgo-templatessprig-template-functions

How to call toYaml and exclude particular key?


Inside the template I have a fragment like this:

props: {{- toYaml .Values.myApp.container.props }}

currently props contains 4 children:

...
    container:
      props:
        a: ...
        b: ...
        c: ...
        d: ...

But I want to exclude c on the fly. Is there way to do it ?


Solution

  • Try:

    {{ $myProps := .Values.myApp.container.props }}
    {{ $_ := unset $myProps "c" }}
    

    Then you can use it, for example:

    props: {{ $myProps | toYaml | nindent 2 }}
    

    which leads to:

    props: 
      a: 1
      b: 2
      d: 4