Skip to content

Enforce pre-commit to be running in github actions#9459

Open
mtrqq wants to merge 9 commits intokubernetes:masterfrom
mtrqq:enforce-precommit
Open

Enforce pre-commit to be running in github actions#9459
mtrqq wants to merge 9 commits intokubernetes:masterfrom
mtrqq:enforce-precommit

Conversation

@mtrqq
Copy link
Copy Markdown
Contributor

@mtrqq mtrqq commented Apr 7, 2026

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This PR configures a github action to periodically run pre-commit on branch push and PR to validate hook states, minimal set of hooks is selected to avoid slowing down development flow. Biggest sources of generated files are explicitly excluded from the config, but not all of them - other entries should be populated as we go

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. area/addon-resizer area/balancer area/cluster-autoscaler area/helm-charts area/provider/alicloud Issues or PRs related to the AliCloud cloud provider implementation area/provider/aws Issues or PRs related to aws provider area/provider/azure Issues or PRs related to azure provider area/provider/coreweave area/provider/digitalocean Issues or PRs related to digitalocean provider and removed do-not-merge/needs-area labels Apr 7, 2026
@k8s-ci-robot k8s-ci-robot added area/provider/gce area/provider/hetzner Issues or PRs related to Hetzner provider area/provider/huaweicloud size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/provider/ionoscloud area/provider/kwok Issues or PRs related to the kwok cloud provider for Cluster Autoscaler area/provider/linode Issues or PRs related to linode provider area/provider/magnum Issues or PRs related to the Magnum cloud provider for Cluster Autoscaler area/provider/oci Issues or PRs related to oci provider area/provider/rancher area/provider/utho Issues or PRs related to Utho provider labels Apr 7, 2026
Currently we have pre-commit configuration which is not enforced which prevents from using it whatsoever, this PR brings it into github actions to verify whether PR/commit passes the validation. Along the way it adds 3 more hooks to the list: go files formatting (go-fmt), avoiding mixed line endings and enforce single format (mixed-line-ending), check for large files added into repo like binaries (check-added-large-files). All the hooks seem to be easy to follow and non-controvertial between different autoscaling subprojects.
@adrianmoisey
Copy link
Copy Markdown
Member

I'm not a fan of this, I think we should get rid of pre-commit in this repo.

There is a lot of generated or vendored content in this repo, which I don't believe pre-commit should be touching.
I also don't think we should be formatting the entire repo with a single version of a single tool (ie: go fmt). Each project within this repo could have different standards

@mtrqq mtrqq force-pushed the enforce-precommit branch from a7c66c5 to 86f477a Compare April 7, 2026 11:50
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 7, 2026
@mtrqq
Copy link
Copy Markdown
Contributor Author

mtrqq commented Apr 8, 2026

I'm not a fan of this, I think we should get rid of pre-commit in this repo.

There is a lot of generated or vendored content in this repo, which I don't believe pre-commit should be touching. I also don't think we should be formatting the entire repo with a single version of a single tool (ie: go fmt). Each project within this repo could have different standards

I completely agree with your take, generated content shouldn't be managed/verified by pre-commit and this is easily controlled by excluded files/folders in the configuration file, I've added couple initial entries referring to vendor folders in the repository I know about and API docs of vertical pod autoscaler which conflicts due to controller-gen adding extra spaces for markdown renderer.

As for the go fmt selection, my reasoning was that it's defacto a standard and it found 0 issues in the repository as there's an existing script used in CI with pretty much same verification: https://github.com/kubernetes/autoscaler/blob/master/hack/verify-gofmt.sh. We may control target files and exclusions on the per-hook basis so if we want to exclude some project area from it - it's more than doable.

Considering all above I think pre-commit may still be useful for development flow, I personally found myself messing up the formatting of the golang file right before the commit so that it causes verification CI build to fail - this change essentially enforces automatic tool which does that for you.

@mtrqq mtrqq marked this pull request as ready for review April 8, 2026 09:10
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 8, 2026
@omerap12
Copy link
Copy Markdown
Member

omerap12 commented Apr 8, 2026

TBH,I agree with Adrian here. I think we should get rid of pre-commit entirely in this repo.

Considering all above I think pre-commit may still be useful for development flow, I personally found myself messing up the formatting of the golang file right before the commit so that it causes verification CI build to fail - this change essentially enforces automatic tool which does that for you.

IMO, we should stick with how k/k do things - each sub-repo should have a verify-gofmt.sh script which can verify whatever each sub repo wants.
Also, in this PR there are many changes that seemed unnecessary to me.

@adrianmoisey
Copy link
Copy Markdown
Member

TBH,I agree with Adrian here. I think we should get rid of pre-commit entirely in this repo.

To be clear, Omer and I only really speak for the VPA section. If the other projects in this repo want pre-commit, they're welcome to have it

@mtrqq
Copy link
Copy Markdown
Contributor Author

mtrqq commented Apr 8, 2026

IMO, we should stick with how k/k do things - each sub-repo should have a verify-gofmt.sh script which can verify whatever each sub repo wants.

Contributors may not install pre-commit and it'll also work just fine as long as the validation passes so the contributor flow doesn't alter significantly, while improving developer productivity for those who decide to opt-in into installing hooks locally. Validation requirements on the CI are quite minimal and in my opinion non controversial, but I am absolutely open to dropping specific checks if some of them feel excessive.

Also, in this PR there are many changes that seemed unnecessary to me.

As for the large number of changes in this PR, I ran all the hooks across the repo intentionally. The goal was to consolidate all baseline formatting updates into a single PR so we don't pollute future feature PRs with unrelated formatting noise. Alternatively we may incrementally do them once the file is getting changed for one or another reason, but to my mind it's more intrusive option in the long term

@adrianmoisey
Copy link
Copy Markdown
Member

Validation requirements on the CI are quite minimal and in my opinion non controversial, but I am absolutely open to dropping specific checks if some of them feel excessive.

I think the entire vertical-pod-autoscaler directory can be excluded, since we don't want to use pre-commit on it

@mtrqq
Copy link
Copy Markdown
Contributor Author

mtrqq commented Apr 8, 2026

@adrianmoisey I've excluded VPA from the pre-commit configuration, it won't be checked in CI and hooks will ignore the folder completely, do you want me to revert all the changes done to VPA folder in this PR like line endings and new lines at the end of the file?

@mtrqq
Copy link
Copy Markdown
Contributor Author

mtrqq commented Apr 8, 2026

@elmiko @jackfrancis Can you review this PR from cluster autoscaler perspective as you've recently reviewed the PR connected to pre-commit configuration?

Ref: #9129

@adrianmoisey
Copy link
Copy Markdown
Member

do you want me to revert all the changes done to VPA folder in this PR like line endings and new lines at the end of the file?

Yup, please do, those don't bother us.

@mtrqq mtrqq force-pushed the enforce-precommit branch from 277c354 to c39037b Compare April 8, 2026 12:27
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mtrqq
Once this PR has been reviewed and has the lgtm label, please assign towca for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 8, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@mtrqq: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-autoscaling-e2e-gci-gce-ca-test c39037b link false /test pull-autoscaling-e2e-gci-gce-ca-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/addon-resizer area/balancer area/cluster-autoscaler area/helm-charts area/provider/alicloud Issues or PRs related to the AliCloud cloud provider implementation area/provider/aws Issues or PRs related to aws provider area/provider/azure Issues or PRs related to azure provider area/provider/coreweave area/provider/digitalocean Issues or PRs related to digitalocean provider area/provider/gce area/provider/hetzner Issues or PRs related to Hetzner provider area/provider/huaweicloud area/provider/ionoscloud area/provider/kwok Issues or PRs related to the kwok cloud provider for Cluster Autoscaler area/provider/linode Issues or PRs related to linode provider area/provider/magnum Issues or PRs related to the Magnum cloud provider for Cluster Autoscaler area/provider/oci Issues or PRs related to oci provider area/provider/rancher area/provider/utho Issues or PRs related to Utho provider area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants