kube-score icon indicating copy to clipboard operation
kube-score copied to clipboard

[Feature Request] Add a `pre-commit` hook for running kube-score

Open erNail opened this issue 10 months ago • 2 comments

Feature Request

Motivation / Problem

I'd like to run kube-score as part of my pre-commit setup.

pre-commit is a popular tool for bundling the execution of multiple linters. pre-commit can then be run via Git Hooks, manually via pre-commit run, or in CI/CD Pipelines.

A lot of popular linters like golangci-lint, yamllint or kube-linter provide pre-commit hooks in their repos, configured via a .pre-commit-hooks.yaml

Proposed solution

Adding pre-commit hooks is fairly simple. All you need is a .pre-commit-hooks.yaml in your repository. For a go application, it could look like this:

---
- id: "kube-score"
  name: "Run kube-score"
  description:
    "This hook installs and runs `kube-score` to perform static code analysis of your Kubernetes object definitions"
  language: "golang"
  types:
    - "yaml"
  entry: "kube-score score"

- id: "kube-score-system"
  name: "Run kube-score from system"
  description:
    "This hook runs `kube-score` from your system to perform static code analysis of your Kubernetes object definitions"
  language: "system"
  entry: "kube-score score"
  types:
    - "yaml"

- id: "kube-score-docker"
  name: "Run kube-score via container"
  description:
    "This hook runs `kube-score` via container to perform static code analysis of your Kubernetes object definitions"
  language: "docker_image"
  types:
    - "yaml"
  entry: "zegl/kube-score:latest score"
...

Additional information

I've created a Pull Request: #659

erNail avatar Jun 05 '25 12:06 erNail

Would appreciate that too

chainmywallet avatar Jun 06 '25 08:06 chainmywallet

+1 for this as well. This is the workaround that I am using forkubeconform as it also does not have a pre-commit hook.

    # See: https://pre-commit.com/#repository-local-hooks
    - repo: local
      # There is no existing pre-commit hook for kubeconform so we just run it here
      hooks:
          - id: kubeconform
            name: kubeconform
            description: Lint k8s manifests
            # Note: this will require that `kubeconform` be in $PATH
            entry: kubeconform -schema-location default ...
            language: system

The exact same approach would work for kube-score, too.

kquinsland avatar Jul 01 '25 23:07 kquinsland