Skip to content

Is it possible to retain key order in an object? #391

Closed Answered by codablock
netthier asked this question in Q&A
Discussion options

You must be logged in to vote

The libraries Kluctl uses internally do not support this and they explicitly sort keys alphanumerically. I actually prefer this as it allows consistent compression, diffing and patching (which will get more important in future versions of Kluctl due to new features).

Your specific use case is however of an example where a list in config.yaml would have been the better choice as it would make the order very explicit. Example:

# config.yaml
config:
  env:
    - name: user
      value: foo
    - name: password
      value: hunter2
    - name: connection_template
      value: "$(user):$(password)@host"
# deployment/pod.yaml
# [snip]
env:
{% for e in config.env %}
  - name: "{{ e.name }}"
    v…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@netthier
Comment options

Answer selected by netthier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants