TExcelTAD
Home › GitOps: Argo CD & Flux › Helm & Kustomize Sources

Helm & Kustomize Sources

So far the linkly Applications pointed at a chart folder inside linkly-deploy. In practice the chart is built and versioned in the app repo and published to a registry, and the deploy repo only says which chart version with which values. This lesson covers how Argo CD consumes Helm charts and Kustomize overlays, including the multi-source pattern that connects the two. The chart-writing side is in Kubernetes Packaging.

Helm options on a source

yaml
source:
  repoURL: ghcr.io/acme/charts         # an OCI registry (no oci:// prefix here), or https://charts.example.com
  chart: linkly                        # chart name: for Helm/OCI repos instead of `path`
  targetRevision: 0.3.0                # the chart VERSION (a semver range like 0.3.* also works)
  helm:
    releaseName: linkly                # default: the Application name
    valuesObject:                      # inline values, as YAML (preferred over the string field `values`)
      replicaCount: 3
    parameters:                        # like --set
      - {name: image.tag, value: 1.5.0}
    ignoreMissingValueFiles: true
    skipCrds: false

Remember that Argo CD renders with helm template and applies the objects itself: lookup returns nothing, helm list shows no release, and the Helm hooks become Argo CD hooks (Sync Waves & Hooks). .Capabilities reflects the target cluster's API versions, which Argo CD passes to helm template.

What the repo-server does, by hand

To reproduce Argo CD's render of a chart from an OCI registry, package and push the chart, then template it from the registry with the environment's values. The session uses the image's local registry on localhost:5000:

bash · try it yourself
mkdir -p linkly/templates
printf 'apiVersion: v2\nname: linkly\nversion: 0.3.0\nappVersion: "1.4.0"\n' > linkly/Chart.yaml
printf 'replicaCount: 2\nimage: {repository: ghcr.io/acme/linkly, tag: ""}\n' > linkly/values.yaml
cat > linkly/templates/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: {{ .Release.Name }}}
spec:
  replicas: {{ .Values.replicaCount }}
  selector: {matchLabels: {app.kubernetes.io/name: linkly}}
  template:
    metadata: {labels: {app.kubernetes.io/name: linkly}}
    spec:
      containers:
        - name: linkly
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
EOF
helm package linkly >/dev/null
helm push linkly-0.3.0.tgz oci://localhost:5000/charts --plain-http 2>&1 | grep -v Digest
mkdir -p linkly-deploy/apps/linkly/production
printf 'replicaCount: 3\nimage: {tag: 1.4.1}\n' > linkly-deploy/apps/linkly/production/values.yaml
helm template linkly oci://localhost:5000/charts/linkly --version 0.3.0 --plain-http \
  -f linkly-deploy/apps/linkly/production/values.yaml 2>/dev/null | grep -E 'replicas|image:'
Pushed: localhost:5000/charts/linkly:0.3.0
  replicas: 3
          image: "ghcr.io/acme/linkly:1.4.1"

Chart from a registry, values from Git: multiple sources

The chart lives in the registry, the values in linkly-deploy. An Application can combine both with sources (plural): one source carries ref: values and doesn't deploy anything itself; the other refers to its files as $values/…:

bash · try it yourself
cat > linkly-production.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: {name: linkly-production, namespace: argocd}
spec:
  project: linkly
  sources:
    - repoURL: ghcr.io/acme/charts
      chart: linkly
      targetRevision: 0.3.0
      helm:
        releaseName: linkly
        valueFiles: [$values/apps/linkly/production/values.yaml]
    - repoURL: https://github.com/acme/linkly-deploy.git
      targetRevision: main
      ref: values
  destination: {server: https://kubernetes.default.svc, namespace: linkly-prod}
  syncPolicy:
    automated: {prune: true, selfHeal: true}
EOF
kubeconform -strict -summary linkly-production.yaml
yq '.spec.sources[] | (.chart // "(values only)") + " @ " + .targetRevision' linkly-production.yaml
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
linkly @ 0.3.0
(values only) @ main

Now a release is two independent decisions, each one commit in linkly-deploy: bump the chart version (targetRevision: 0.3.0 → 0.4.0) or bump the image tag in the values file. A change in either source makes the app OutOfSync. Many teams keep the chart version in the values repo too, by generating Applications from a file (ApplicationSets).

Kustomize sources

A path with a kustomization.yaml is built with kustomize build. The Application can add a few Kustomize settings without a new overlay, handy for generated apps:

yaml
source:
  repoURL: https://github.com/acme/linkly-deploy.git
  targetRevision: main
  path: apps/production
  kustomize:
    images: [ghcr.io/acme/linkly:1.4.1]       # like `kustomize edit set image`
    namePrefix: blue-
    commonLabels: {team: links}
    patches:
      - target: {kind: Deployment, name: linkly}
        patch: |-
          - {op: replace, path: /spec/replicas, value: 4}

Prefer committing these to the overlay itself: settings on the Application are less visible to someone reading the repo.

Helm inside Kustomize (the helmCharts: field, see Helm Rendered Through Kustomize) needs --enable-helm. Argo CD only passes it if the instance allows it: kustomize.buildOptions: --enable-helm in argocd-cm. Without it the render fails with a message about --enable-helm.

Config Management Plugins

Anything else (SOPS decryption, jsonnet with custom libraries, cdk8s, rendering with a tool Argo CD doesn't ship) goes through a Config Management Plugin: a sidecar container on the repo-server that runs your command and prints manifests. Plugins are powerful and a security boundary at the same time (they run arbitrary commands on repository content), so prefer built-in sources and pre-rendered manifests where you can.

Test yourself

In a multi-source Application, what does ref: values on a Git source do?

  1. Deploys the Git folder as a second app
  2. Makes the source's files available to other sources as $values/... without deploying it
  3. Pins the Git revision
  4. Converts YAML to Helm values

For a chart from a Helm or OCI repository, what does targetRevision mean?

  1. A Git branch
  2. The chart version
  3. The image tag
  4. The Helm release revision

A Kustomize overlay uses helmCharts: and fails in Argo CD but builds locally with kustomize build --enable-helm. What is missing?

  1. A Helm repo Secret
  2. kustomize.buildOptions: --enable-helm in argocd-cm
  3. ServerSideApply=true
  4. A newer chart