TExcelTAD

Chart Versioning

A chart has two versions, and mixing them up is the most common versioning mistake in Helm:

version appVersion
Describes the chart: templates, defaults, schema the application the chart deploys by default
Format SemVer 2, required free text (quote it)
Used by dependency ranges, --version constraints, registry tags, helm list (CHART column) the default image tag (.Chart.AppVersion), the APP VERSION column
Changes when anything in the chart changes a new application release becomes the default

A published chart version is immutable: once linkly-0.9.0 is in a registry, users and lock files rely on its exact content. Change anything, bump the version.

What major, minor and patch mean for a chart

SemVer is about the chart's interface, which is its values and the objects it creates:

Change Bump
rename or remove a values key, change a default in a way that breaks existing installs, rename objects (forces recreation), raise kubeVersion major
add a values key with a backwards-compatible default, add an optional object (an HTTPRoute behind httpRoute.enabled: false), bump appVersion to a new app minor minor
fix a template bug, tidy labels, bump appVersion for an app patch patch

Before 1.0.0 anything may change, which is why many charts stay at 0.x far too long: release 1.0.0 once other teams depend on the values.

Versioning in CI

The chart version in Git is often a placeholder; CI stamps the real one at package time with --version and --app-version, without editing Chart.yaml. The session packages several versions, including a pre-release and one with build metadata, and pushes them to the local registry:

bash · try it yourself
mkdir -p linkly/templates
printf 'apiVersion: v2\nname: linkly\nversion: 0.0.0-dev\nappVersion: "0.0.0-dev"\n' > linkly/Chart.yaml
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: x\n' > linkly/templates/cm.yaml
helm package linkly --version 1.0.0 --app-version 1.4.0 -d dist
helm package linkly --version 1.1.0 --app-version 1.4.1 -d dist >/dev/null
helm package linkly --version 1.1.1+git.3f9c2e1 --app-version 1.4.1 -d dist >/dev/null
helm package linkly --version 1.2.0-rc.1 --app-version 1.5.0-rc.1 -d dist >/dev/null
helm package linkly --version 2.0.0 --app-version 1.5.0 -d dist >/dev/null
ls dist
for f in dist/*.tgz; do helm push "$f" oci://localhost:5000/charts --plain-http 2>&1 | head -1; done
Successfully packaged chart and saved it to: dist/linkly-1.0.0.tgz
linkly-1.0.0.tgz
linkly-1.1.0.tgz
linkly-1.1.1+git.3f9c2e1.tgz
linkly-1.2.0-rc.1.tgz
linkly-2.0.0.tgz
Pushed: localhost:5000/charts/linkly:1.0.0
Pushed: localhost:5000/charts/linkly:1.1.0
Pushed: localhost:5000/charts/linkly:1.1.1_git.3f9c2e1
Pushed: localhost:5000/charts/linkly:1.2.0-rc.1
Pushed: localhost:5000/charts/linkly:2.0.0

The version with build metadata was pushed as 1.1.1_git.3f9c2e1: OCI tags can't contain +, so Helm writes _ in the tag and turns it back into + when pulling.

Version constraints

Consumers ask for a range: --version on install/pull/show, version: in a dependency. Helm picks the highest version that matches, and ignores pre-releases unless the constraint itself mentions one:

bash · try it yourself
mkdir -p linkly/templates
printf 'apiVersion: v2\nname: linkly\nversion: 0.0.0\n' > linkly/Chart.yaml
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: x\n' > linkly/templates/cm.yaml
for v in 1.0.0 1.1.0 1.1.1 1.2.0-rc.1 2.0.0; do
  helm package linkly --version $v -d dist >/dev/null
  helm push dist/linkly-$v.tgz oci://localhost:5000/charts --plain-http >/dev/null 2>&1
done
for c in "1.1.0" "~1.1.0" "^1.0.0" ">=1.0.0 <2.0.0" "*"; do
  printf '%-16s -> ' "$c"
  helm show chart oci://localhost:5000/charts/linkly --version "$c" --plain-http 2>/dev/null | grep '^version'
done
printf '%-16s -> ' "^1.0.0 --devel"
helm show chart oci://localhost:5000/charts/linkly --version "^1.0.0" --devel --plain-http 2>/dev/null | grep '^version'
printf '%-16s -> ' "^1.0.0-0"
helm show chart oci://localhost:5000/charts/linkly --version "^1.0.0-0" --plain-http 2>/dev/null | grep '^version'
printf '%-16s -> ' "(none)"
helm show chart oci://localhost:5000/charts/linkly --plain-http 2>/dev/null | grep '^version'
1.1.0            -> version: 1.1.0
~1.1.0           -> version: 1.1.1
^1.0.0           -> version: 1.1.1
>=1.0.0 <2.0.0   -> version: 1.1.1
*                -> version: 2.0.0
^1.0.0 --devel   -> version: 1.1.1
^1.0.0-0         -> version: 1.2.0-rc.1
(none)           -> version: 2.0.0
Constraint Means
1.1.0 exactly 1.1.0
~1.1.0 >= 1.1.0, < 1.2.0: patch updates only
^1.0.0 >= 1.0.0, < 2.0.0: no new major (for ^0.x, no new minor)
>=1.0.0 <2.0.0 an explicit range (space = AND, || = OR)
* or no --version the highest stable version
^1.0.0-0, >=1.2.0-0 <2.0.0 a -0 in the constraint lets pre-releases match
--devel without --version: the highest version including pre-releases (>0.0.0-0); ignored when --version is set

For dependencies, a ~ range plus a committed Chart.lock gives you patch fixes when you choose to run helm dependency update, and reproducible builds otherwise.

Choosing a SemVer comparison by hand

Helm uses the Masterminds SemVer library. A small model of the rules it applies, for intuition (and for the Exercises):

python · try it yourself
def parse(v):
    core, _, pre = v.split("+")[0].partition("-")
    nums = tuple(int(x) for x in core.split("."))
    ids = tuple((0, int(i), "") if i.isdigit() else (1, 0, i) for i in pre.split(".")) if pre else ()
    return nums, ids

def key(v):
    nums, ids = parse(v)
    return (nums, 0 if ids else 1, ids)   # a pre-release sorts before its release

def matches(v, c):
    nums, ids = parse(v)
    lo, lo_ids = parse(c[1:])
    if ids and not lo_ids:
        return False                      # pre-releases match only a "-0"-style constraint
    if c[0] == "~":
        hi = (lo[0], lo[1] + 1, 0)
    else:                                 # "^"
        hi = (lo[0] + 1, 0, 0) if lo[0] > 0 else (0, lo[1] + 1, 0)
    return lo <= nums < hi

available = ["1.0.0", "1.1.0", "1.1.1", "1.2.0-rc.1", "2.0.0", "0.9.3", "0.10.0"]
for c in ["~1.1.0", "^1.0.0", "^1.0.0-0", "^0.9.0"]:
    best = max((v for v in available if matches(v, c)), key=key, default=None)
    print(f"{c:9} -> {best}")
~1.1.0    -> 1.1.1
^1.0.0    -> 1.1.1
^1.0.0-0  -> 1.2.0-rc.1
^0.9.0    -> 0.9.3

Test yourself

You rename the values key image.name to image.repository. Which part of the chart version do you bump?

  1. patch
  2. minor
  3. major
  4. appVersion

Which version does --version "^1.0.0" pick from 1.1.1, 1.2.0-rc.1 and 2.0.0?

  1. 1.1.1
  2. 1.2.0-rc.1
  3. 2.0.0
  4. none

How is chart version 1.1.1+git.3f9c2e1 stored in an OCI registry?

  1. As tag 1.1.1+git.3f9c2e1
  2. As tag 1.1.1_git.3f9c2e1
  3. As tag 1.1.1
  4. It can't be pushed