fix: use compact indent for sequences #1062
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We had some grumbles from developers after the goyaml.v3 upgrade that this changed the compact sequence indent used by kustomize, kubectl etc.
There was a whole thread about this when the goyaml.v3 upgrade happened in kustomize itself: kubernetes-sigs/kustomize#3946 and the result was that kubesigs forked goyaml.
In order to more closely match what the kubernetes tools do, this commit switches to the forked version, which has a compact option on the encoder:
https://github.com/kubernetes-sigs/yaml/blob/56d672052dcff7362af5b66f6424976539cddd78/goyaml.v3/patch.go#L25-L28
When I first tried this I also changed the code to guess if compact was the preferred style from the yaml. However, it turns out that the yaml formatter misbehaves when told to use "compact" and an indent other than 2; if set to 3 and compact it produces code like this:
Instead of:
This meant I couldn't get the "guess indentation" code to work, so I've removed that and its test to avoid raising a false expectation.