helm-schema
Generate a JSON Schema for a Helm chart’s values.yaml by analyzing the chart’s templates, so Helm rejects a mistyped value before it renders a broken manifest.
Homebrew
brew install --cask romnn/tap/helm-schema
mise
mise use github:romnn/helm-schema
Cargo
cargo install --locked helm-schema-cli
templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: {{ .Values.replicaCount }}From that template, helm-schema writes:
values.schema.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"global": {},
"replicaCount": {
"anyOf": [
{
"description": "Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.",
"format": "int32",
"type": "integer"
},
{
"pattern": "^(([+-]_*)?(0|[1-9][0-9_]{0,17}|0[xX][0-9a-fA-F]{1,15}|0[bB][01]{1,62}|0[oO][0-7]{1,20}|0[0-7]{1,20})|[+-]_*0[0-7]{0,8}[89][0-9]{0,8})$",
"type": "string"
}
]
}
},
"required": [
"replicaCount"
],
"type": "object",
"x-helm-schema-generated": true,
"x-helm-schema-policy": {
"annotation-format-version": 1,
"authoring": {
"declared-types": "assert",
"root": "closed"
},
"modifiers": {
"overrides": {
"count": 0,
"digest": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945"
},
"reference-mode": "fully-inlined"
},
"narrowing": [],
"policy-fingerprint": "8a5e8a392fff0994ab4c850bc117a320c0dfe56736e845b27be81a7404a4384f",
"policy-vocabulary-version": 2,
"requested-profile": "full",
"resolved": {
"kind-partitions": true,
"local-conditionals": true,
"root-anchored-conditionals": true,
"terminal-clauses": true
}
}
}replicaCount reaches a Deployment’s spec.replicas, so the schema gives it that field’s int32
type and Kubernetes’ own description, though values.yaml only sets replicaCount: 1.
With that schema, Helm rejects a misspelled key before it renders:
$ helm template ./web --set replicaCont=3
Error: values don't meet the specifications of the schema(s) in the following chart(s):
web:
- at '': additional properties 'replicaCont' not allowedHow it works#
helm-schemareads the chart’s templates, and those of its dependencies undercharts/, and finds every.Valuespath they use.- It follows each value through
if,with,rangeanddefaultinto the resource field it renders, and types it from the Kubernetes or CRD schema of that field. - It writes one Draft-07 schema. Saved as
values.schema.jsonbesidevalues.yaml, it is what Helm checks values against oninstall,upgrade,lintandtemplate.
Get started#
In the chart’s parent directory:
helm-schema ./web \
-o web/values.schema.jsonThen:
- Getting started: a worked example, from installing to the error Helm prints.
- Continuous integration: keep the committed schema in sync with the chart.
- Schema overrides: fill in what the templates do not say.