-
Notifications
You must be signed in to change notification settings - Fork 257
Feat/add alphabetical order check #1042
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
Feat/add alphabetical order check #1042
Conversation
…d YAML keys Signed-off-by: Ayush Kumar <[email protected]>
…st cases for various Kubernetes resources
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1042 +/- ##
===========================================
- Coverage 62.36% 26.50% -35.86%
===========================================
Files 197 233 +36
Lines 4854 7326 +2472
===========================================
- Hits 3027 1942 -1085
- Misses 1439 5230 +3791
+ Partials 388 154 -234
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @rhybrillou, @rukletsov , can I get a review on this Thanks! I stumbled across this while looking for |
|
Hi @janisz, could you please take a look at this PR when you get a chance? It seems things have been a bit quiet on the Slack channels lately. |
|
I'll take a deeper look tomorrow. So far I wonder if there's a yaml linter that we could embed and maybe get this for free and some additional features like trailing spaces, tabs/spaces etc. I only know https://github.com/adrienverge/yamllint Another thing that we need to test is how anchors, aliases, and overrides are handled. I agree slack is silent and I do not look at it. I was thinking about migration to GitHub issues or discussions to keep everything in a single place or maybe a channel on k8s slack/discord https://www.kubernetes.dev/blog/2025/06/16/changes-to-kubernetes-slack-2025/ |
…idation in YAML files
…ve key extraction logic
|
@janisz the test changes are implemented could you take a look. Thanks! |
|
LGTM @roguepikachu Thank you 🎉 |
This PR implements a new optional check called
sorted-keysthat validates whether YAML keys in Kubernetes manifests are sorted in alphabetical order, helping improve consistency and readability.Fixes #451
How It Works
The check uses
gopkg.in/yaml.v3to parse raw YAML bytes and preserve the original key ordering. It recursively traverses the YAML tree, extracts keys from each mapping node, compares them with their alphabetically sorted version, and reports violations with the exact path location.spec.template.spec.containers[0])Why Raw YAML? Go structs don't preserve field order. The check requires access to original YAML bytes via
object.Metadata.Rawto accurately detect key ordering.Usage
Since this check is disabled by default, users must explicitly enable it:
Or via configuration file:
Note
This check is disabled by default, users must explicitly enable it