kapicorp / kapitan

Generic templated configuration management for Kubernetes, Terraform and other things
https://kapitan.dev
Apache License 2.0
1.83k stars 199 forks source link

ability to unindent nested lists in YAML output. #497

Open joulaud opened 4 years ago

joulaud commented 4 years ago

Describe the bug/feature I would like kapitan to output unindented sequences. At the moment it generates

mylist:
  - item1
  - item2

and I want

mylist:
- item1
- item2

The current behaviour seems deliberate (https://github.com/deepmind/kapitan/blob/25f4ebaca159a748e44683a45875e74be73c1570/kapitan/utils.py#L163-L170 ) but I would like to be able to deactivate it.

Some more options of formatting for the YAML dump could also be useful.

Additional context https://kubernetes.slack.com/archives/C981W2HD3/p1588000744140800?thread_ts=1587994132.137100&cid=C981W2HD3

uberspot commented 4 years ago

Since this might require adding yet another config argument, it might be worth thinking about passing kapitan config parameters with something like this methodology https://tech.preferred.jp/en/blog/working-with-configuration-in-python/ to simplify function declarations and only pass a single config around (?). Just an idea.

adrianchifor commented 4 years ago

The way we output sequences is the correct way to do it according to the latest YAML spec. We try to keep most outputs in-line with the spec as most consumers (such as kubectl) have certain expectations and don't have to apply transformations.

joulaud commented 4 years ago

@adrianchifor Previous versions of the spec explicitly authorized what I want. https://yaml.org/spec/1.1/#id931893

New version of the spec have a (for me) cryptic comment /* For some fixed auto-detected m > 0 */ which can be interpreted the way you do.

I cannot find the rational for this change between YAML 1.1 and YAML 1.2. All YAML parser I use support both syntax without problem and several serializers output it my way by default (including PyYaml).

I don't ask for modifiying the default YAML output but I would like to be able to configure it.

joulaud commented 4 years ago

As a point of data kubectl does not overindent sequences on its output. My main objective here is to be able to compare kubectl output and kapitan generated files with the less post-processing possible.

Extract from a kubectl get pods -o yaml mypod (version 1.17 of kubectl)

status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2020-04-25T14:16:35Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2020-04-25T14:16:38Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2020-04-25T14:16:38Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2020-04-25T14:16:35Z"
    status: "True"
    type: PodScheduled
github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 1 year with no activity. Remove the stale label or comment if this issue is still relevant for you. If not, please close it yourself.