Open crandles opened 1 month ago
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: crandles Once this PR has been reviewed and has the lgtm label, please assign jpbetz for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Welcome @crandles!
It looks like this is your first PR to kubernetes-sigs/kubectl-validate 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.
You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.
You can also check if kubernetes-sigs/kubectl-validate has its own contribution guidelines.
You may want to refer to our testing guide if you run into trouble with your tests not passing.
If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to Kubernetes. :smiley:
Example usage with reviewdog:
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go install github.com/reviewdog/reviewdog/cmd/reviewdog@latest
kubectl validate path/to/yaml/* -o lint | $(go env GOPATH)/bin/reviewdog -f=golint -reporter=github-pr-check -fail-level=any -tee
Although I'd plan to craft an action for this, in the long run.
I really like the direction, I'm very sad that we have to add 14k lnes of code just to be able to print filename:line:col:error. On the other hand, I realize that the current go implementation of the yaml loader doesn't give us line numbers. So at the end of the day I think this goes in the right direction.
Definitely agree. It's probably worth another attempt at pulling the line numbers out of one of the currently vendor-ed decoders. Perhaps I can at least share my failed attempt, if nothing else. Let me know if that would be valuable.
Happy to spend a little effort to get this right.
An alternative might be to switch yaml decoders outright, but that seemed more than necessary.
gopkg.in/yaml.v3
, which is already imported, does support a way to decode yaml line numbers (see line/column fields): https://pkg.go.dev/gopkg.in/yaml.v3#Node, however it is not readily traversable.
There is no alternative for yaml.PathString
that I can find for the gopkg.in/yaml.v3
package, so that code would need to be implemented. Given the existence of yaml anchors, you'd need a multi-step or recursive process. I believe this is when I turned to the goccy package which provided both capabilities.
https://pkg.go.dev/github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath looks like the top alternative for easily traversing a yaml.Node
What type of PR is this?
/kind feature
What this PR does / why we need it:
This adds support for rendering validation errors into a simple "lint error format" (e.g. see errorformat), with the intention of piping the lint output to reviewdog to post PR comments pertaining to any validation errors.
Which issue(s) this PR fixes:
N/A
Special notes for your reviewer:
This does pull in a new import,
goccy/go-yaml
. (I see it used in some other kubernetes projects) I was unable to get the otherwise imported yaml packages to get accurate line numbers and have a way to search via field.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: