Implementing Values Schema Validation
1. Creating values.schema.json File
Example: Minimal schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Values",
"type": "object",
"required": ["image"],
"properties": {
"replicaCount": { "type": "integer", "minimum": 1, "default": 1 },
"image": {
"type": "object",
"required": ["repository"],
"properties": {
"repository": { "type": "string" },
"tag": { "type": "string" },
"pullPolicy": { "type": "string", "enum": ["Always", "IfNotPresent", "Never"] }
}
}
}
}
2. Defining Schema Properties
| Keyword | Use |
|---|---|
type | One of string, integer, number, boolean, array, object, null |
properties | Map of field → sub-schema |
additionalProperties | false rejects unknown keys |
items | Schema applied to array elements |
3. Setting Required Fields
Example: Multiple required keys
{
"type": "object",
"required": ["image", "service"],
"properties": {
"image": { "type": "object" },
"service": { "type": "object" }
}
}
4. Defining Value Types
| Type | Example value |
|---|---|
string | "nginx" |
integer | 3 |
number | 0.5 |
boolean | true |
array | ["a","b"] |
object | { "k": "v" } |
["string","null"] | Nullable string |
5. Adding Property Constraints
| Constraint | Applies to | Example |
|---|---|---|
minimum / maximum | number/integer | "minimum": 1 |
minLength / maxLength | string | "maxLength": 63 |
pattern | string (regex) | "^[a-z0-9-]+$" |
minItems / maxItems / uniqueItems | array | "uniqueItems": true |
format | string | "uri", "email", "date-time" |
6. Using Enum Values
Example: Restrict allowed strings
"service": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["ClusterIP", "NodePort", "LoadBalancer"],
"default": "ClusterIP"
}
}
}
7. Setting Default Values
| Keyword | Effect in Helm |
|---|---|
"default" | Documentation hint only — Helm does NOT inject schema defaults |
| Actual defaults | Must live in values.yaml |
8. Adding Schema Descriptions
Example: Self-documenting schema
"replicaCount": {
"type": "integer",
"minimum": 1,
"description": "Number of pod replicas",
"examples": [1, 3, 5]
}
9. Validating Nested Objects
Example: Deep schema
"resources": {
"type": "object",
"properties": {
"requests": {
"type": "object",
"properties": {
"cpu": { "type": "string", "pattern": "^[0-9]+m?$" },
"memory": { "type": "string", "pattern": "^[0-9]+(Mi|Gi)$" }
}
}
}
}
10. Testing Schema Validation
| Command | Behavior |
|---|---|
helm install x ./chart --dry-run | Fails with schema violation message if invalid |
helm lint ./chart | Runs schema validation against values.yaml |
helm template ./chart -f bad.yaml | Fails before rendering on validation error |