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

KeywordUse
typeOne of string, integer, number, boolean, array, object, null
propertiesMap of field → sub-schema
additionalPropertiesfalse rejects unknown keys
itemsSchema 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

TypeExample value
string"nginx"
integer3
number0.5
booleantrue
array["a","b"]
object{ "k": "v" }
["string","null"]Nullable string

5. Adding Property Constraints

ConstraintApplies toExample
minimum / maximumnumber/integer"minimum": 1
minLength / maxLengthstring"maxLength": 63
patternstring (regex)"^[a-z0-9-]+$"
minItems / maxItems / uniqueItemsarray"uniqueItems": true
formatstring"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

KeywordEffect in Helm
"default"Documentation hint only — Helm does NOT inject schema defaults
Actual defaultsMust 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

CommandBehavior
helm install x ./chart --dry-runFails with schema violation message if invalid
helm lint ./chartRuns schema validation against values.yaml
helm template ./chart -f bad.yamlFails before rendering on validation error