Sub topic 5
Turning dependencies on and off with condition and tags
This chapter assumes you know Helm 3 basics (install, upgrade, release), can read a Chart.yaml with a dependencies list, and can override values in values.yaml. You will learn how condition and tags decide which subcharts a release includes.
Why switch dependencies off
A parent chart often bundles optional parts. A web app might ship with a cache, a database, or a metrics exporter. In production you may already run a managed cache and want to skip the bundled one. Helm lets you decide this at install time, without editing the chart.
Helm evaluates two fields on each dependency in Chart.yaml:
conditionis a single values path that holdstrueorfalse.tagsis a list of labels. Atagsmap in the values file turns each label on or off for every dependency that carries it.
Using condition
Here is the dependency from the earlier chapters.
apiVersion: v2
name: webapp
description: Example web application chart
type: application
version: 0.1.0
appVersion: "1.0.0"
dependencies:
- name: cache
version: "~1.2.0"
repository: https://charts.example.com/stable
condition: cache.enabled
tags:
- backendThe condition value is a path into the parent's values. Here Helm reads cache.enabled. You set it like this:
cache:
enabled: true
replicaCount: 2If the path resolves to true, the subchart is included. If it resolves to false, Helm leaves the subchart's templates out of the release. If the path does not exist in the values, Helm ignores the condition and moves on to the tags.
You can also list several paths, separated by commas, such as cache.enabled,global.cache.enabled. Helm uses the first path that exists in the values and ignores the rest.
Using tags
Tags group dependencies. Give the same tag to several subcharts, then switch them together from the top-level tags map in the values file.
tags:
backend: false
frontend: trueWith this file, every dependency labelled backend is disabled. Every dependency labelled frontend stays enabled. Tags must be set at the top level of the parent's values. Helm does not read a tags map placed inside a subchart key.
How Helm decides
The order of evaluation matters when both fields are present.
- If a
conditionpath exists in the values, its value wins. Tags are ignored for that dependency. - If no condition path exists, Helm checks the tags. If any tag on the dependency is
true, the dependency is enabled. If tags are set and all arefalse, it is disabled. - If neither a condition path nor a matching tag is set, the dependency is enabled.
Checking the result
Use helm template to see what Helm renders. This command disables the cache from the command line:
helm template demo ./webapp --set cache.enabled=falseThe output should contain no resources from the cache subchart. You can also disable a tag group:
helm template demo ./webapp --set tags.backend=falseCommon errors
- The condition does nothing. Check the path spelling. A path like
cache.enabledoes not exist, so Helm falls back to the tags or enables the dependency. - Tags in the wrong place. The
tagsmap must be at the top level of the parent's values, not undercache:. - A condition overrides a tag. If
cache.enabledistrueandtags.backendisfalse, the cache is still enabled. The condition wins. - Values still appear for a disabled subchart. Helm still reads the values under
cache:, but it renders no templates from that subchart.
Exercise
A chart has a dependency with condition: cache.enabled and tags: [backend]. The values file sets cache.enabled: true and tags.backend: false. Is the cache subchart rendered, and why?
Show answer
Yes. The condition path cache.enabled exists in the values, so its value (true) decides, and the tag is ignored for this dependency.
Exercise
Write a helm template command that disables every dependency tagged backend for a release named demo using the chart in ./webapp.
Show answer
helm template demo ./webapp --set tags.backend=false