helm-schema

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 allowed

How it works#

  1. helm-schema reads the chart’s templates, and those of its dependencies under charts/, and finds every .Values path they use.
  2. It follows each value through if, with, range and default into the resource field it renders, and types it from the Kubernetes or CRD schema of that field.
  3. It writes one Draft-07 schema. Saved as values.schema.json beside values.yaml, it is what Helm checks values against on install, upgrade, lint and template.

Get started#

In the chart’s parent directory:

helm-schema ./web \
  -o web/values.schema.json

Then:

Esc

Type # for headings only ↑↓ move ↵ open Ctrl ↵ new tab Ctrl U/D scroll preview

Keyboard shortcuts

/ ⌘ K Ctrl K
Search
← →
Previous or next page
?
Show these shortcuts