Skip to content

fix: use compact indent for sequences #1062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

bewinsnw
Copy link
Contributor

@bewinsnw bewinsnw commented Mar 12, 2025

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:

mapping:
 - list item

Instead of:

mapping:
- list item

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.

We had some grumbles from developers after the goyaml.v3 upgrade that
this changed the 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:

    mapping:
     - list item

Instead of:

    mapping:
    - list item

This meant I couldn't get the "guess indentation" code to work, so
I've removed that and its test to avoid raising a fault expectation.

Signed-off-by: Brian Ewins <bewins@nerdwallet.com>
@bewinsnw bewinsnw force-pushed the bewins/goyaml-fork branch from 988467b to 402b0bd Compare March 12, 2025 16:53
@codecov-commenter
Copy link

codecov-commenter commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 63.49%. Comparing base (3448312) to head (402b0bd).

Files with missing lines Patch % Lines
pkg/argocd/update.go 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1062      +/-   ##
==========================================
- Coverage   63.63%   63.49%   -0.14%     
==========================================
  Files          15       15              
  Lines        2343     2326      -17     
==========================================
- Hits         1491     1477      -14     
+ Misses        760      758       -2     
+ Partials       92       91       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chengfang
Copy link
Collaborator

This is a follow-up to previous PR #1055

@chengfang chengfang merged commit 7e4c52a into argoproj-labs:master Mar 14, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants