Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm `toYaml` does not retain the order

Trying to get log4j2 section form values.yml using toYaml but it does not retain the order.

log4j2.yml: |-
{{ toYaml .Values.log4j2 | indent 4 }}

output-

log4j2:
  Configuration:
    Appenders:
      Console:
        Filters:
          DuplicateLogFilter:
            ttlInSeconds: 60
          MarkerFilter:
            marker: TRACE
            onMatch: ACCEPT
            onMismatch: NEUTRAL
        PatternLayout:
          pattern: '%-5p | %d{yyyy-MM-dd HH:mm:ss,SSS} | [%t] [%X{AD.requestGUID}] [%X{trace.id}]
          %x %c{1.}:%L - %m%n'
        name: CONSOLE
        target: SYSTEM_OUT
    monitorInterval: 300
    shutdownHook: disable

Expected output-

log4j2:
  Configuration:
    monitorInterval: 300
    shutdownHook: disable
    Appenders:
      Console:
        name: CONSOLE
        target: SYSTEM_OUT
        Filters:
          MarkerFilter:
            marker: TRACE
            onMatch: ACCEPT
            onMismatch: NEUTRAL
          DuplicateLogFilter:
            ttlInSeconds: 60
        PatternLayout:
          pattern: "%-5p | %d{yyyy-MM-dd HH:mm:ss,SSS} | [%t] [%X{AD.requestGUID}] [%X{trace.id}] %x %c{1.}:%L - %m%n"
like image 928
Sivangi Singh Avatar asked Sep 16 '25 06:09

Sivangi Singh


1 Answers

Values files are parsed to a map (or dictionary if you will), and map structures in general are not required to preserve the field order. So your issue is not a problem of the toYaml function as such, but of placing log4j configuration inside values.yaml.

What you could do is moving your log4j configuration in to a separate log4j2.yml file (in the root of your chart), and including it as a raw file:

log4j2.yml: |-
  {{- .Files.Get "log4j2.yml" | nindent 10 }}

(adjust the indent accordingly)

like image 76
Mafor Avatar answered Sep 20 '25 14:09

Mafor