How to Validate Manifests Before a GitOps Sync
kubeconform validates rendered manifests against Kubernetes API schemas, so a typo fails the PR check instead of a live sync.
In a pull_request job, build the manifests with kustomize build and pipe them to kubeconform -strict. A schema error fails the check before the change can merge and deploy.
Steps
- Render the overlay with
kustomize build. - Pipe the output into
kubeconform -strict. - Add CRD schema locations for custom resources.
- Run it on
pull_requestso it gates the merge.
Workflow
.github/workflows/validate.yml
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
curl -sSL https://github.com/yannh/kubeconform/releases/latest/download/kubeconform-linux-amd64.tar.gz \
| tar xz -C /usr/local/bin kubeconform
- run: |
kustomize build overlays/production |
kubeconform -strict -summary \
-schema-location default \
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'Gotchas
- Without a CRD schema location, custom resources are skipped; add the catalog URL to cover them.
-strictrejects unknown fields, catching the typos a plain apply would silently ignore.
Related guides
How to Render Manifests in CI Before CommitRender Helm or Kustomize output to plain YAML in CI and commit the result to a rendered branch, so GitOps app…
How to Diff a GitOps Change With Argo CDPreview what a GitOps change will do by running argocd app diff against a branch in a pull request job, surfa…