Helm / Basic: chart and rendering foundations / Lesson 7
Preserve false and zero in Helm values
Reason about Helm default semantics when false and zero are intentional chart inputs.
On this page
Lesson goals
- Explain how default treats empty values.
- Distinguish a missing value from intentional false or zero.
- Review rendered output and schema for the intended contract.
Start with the input contract
A chart may allow a caller to disable a feature with false or request zero replicas for a controlled scenario. The template must preserve those choices if they are valid according to the chart contract. Helmโs default function treats several values, including false and numeric zero, as empty. Therefore a fallback can replace an intentional value. These examples are fragments for review and are not executed.
Examine supplied values
The first record deliberately supplies false and zero. Their validity depends on the chart schema and operational constraints; zero replicas is not safe for every workload. State the expected render before reviewing the template and use synthetic lab values.
enabled: false
replicas: 0
Both fields are deliberately supplied; this fragment is not a complete chart.
Trace the fallback
The second fragment applies default to those inputs. Because false and zero are empty for this function, the fallback values true and 1 are selected. That may contradict the callerโs intention even though the output is syntactically valid YAML. Check the exact function semantics for the installed Helm version and avoid using default where a valid false or zero must survive.
{{ default true .Values.enabled }}
{{ default 1 .Values.replicas }}
These expressions demonstrate the fallback behavior; they are not a complete template.
Choose an explicit contract
One approach is to put the ordinary default in values.yaml and render the supplied value directly, with a schema that defines valid types and boundaries. If absence needs a distinct meaning, check key presence explicitly and test that branch. Review how values are merged and overridden before deciding which input the template receives. A schema does not replace operational review of replica capacity.
Verify representative cases
In an isolated chart lab, render missing, false, true, zero and positive values as appropriate. Compare exact output and types, including an invalid type that should fail schema validation. Do not apply resources; rendering does not establish readiness or capacity.
Common errors and fixes
False is replaced with true
- Why it happens
- The default function considers false empty.
- How to fix it
- Use an explicit input contract and render false directly when valid.
- Prevent it next time
- Test both boolean values and absence.
Zero replicas unexpectedly becomes one
- Why it happens
- Numeric zero triggers the fallback.
- How to fix it
- Preserve zero if the schema and workload allow it.
- Prevent it next time
- Test zero and positive counts.
A valid render is called a safe deployment
- Why it happens
- Rendering does not measure running capacity.
- How to fix it
- Review operational constraints and test in a lab.
- Prevent it next time
- Separate template and runtime acceptance checks.
2 practice exercises
1. The caller supplies enabled: false and the template uses default true. What is selected?
Show worked solution
The fallback true is selected because false is empty to default. Use a contract that preserves false if that choice is valid.
2. Why test both a missing value and zero?
Show worked solution
They may have different intended meanings even though default treats zero as empty. The chart must implement and document the desired distinction.
Key takeaways
- Default treats false and zero as empty.
- Use an explicit values contract and test presence separately.
- Rendering and workload safety require different evidence.