TExcelTAD
Home › GitOps: Argo CD & Flux › Declarative State in Git

Declarative State in Git

"Put the desired state in Git" sounds simple until you ask which state. A Helm chart plus a values file is a recipe, not a state: the objects only exist after rendering. This lesson is about what belongs in the repository, what the agent does with it, and the habits that keep the rendered result stable.

Source, render, apply

text
Git commit ──> render ──────────────────────────> plain objects ──> diff with cluster ──> apply
               (Argo CD repo-server or Flux        Deployments, Services,
                kustomize/helm controller:          HTTPRoutes ...
                kustomize build / helm template)

Both agents render inside the cluster with the same engines you run locally:

Source type Argo CD renders with Flux renders with
plain YAML directory read as is (optionally recursively) kustomize build (a kustomization.yaml is generated if missing)
Kustomize kustomize build kustomize build (kustomize-controller)
Helm chart helm template, then applies the result itself; no Helm release Secret is created a real Helm install/upgrade (helm-controller), with release history

That difference in the Helm row matters later: under Argo CD a chart's lookup calls return nothing and Helm hooks are mapped onto Argo CD hooks; under Flux the chart behaves as with helm upgrade. Both are covered in Helm & Kustomize Sources and The Helm Controller.

Render locally, every time

Because rendering is deterministic (or should be), you can reproduce exactly what the agent will apply. This session renders a Kustomize overlay the way both tools would and validates it:

bash · try it yourself
mkdir -p base overlays/staging && cd overlays/staging
cat > ../../base/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: linkly}
spec:
  replicas: 2
  selector: {matchLabels: {app.kubernetes.io/name: linkly}}
  template:
    metadata: {labels: {app.kubernetes.io/name: linkly}}
    spec:
      containers: [{name: linkly, image: ghcr.io/acme/linkly:1.4.0}]
EOF
printf 'resources: [deployment.yaml]\n' > ../../base/kustomization.yaml
cat > kustomization.yaml <<'EOF'
namespace: linkly-staging
resources: [../../base]
images:
  - name: ghcr.io/acme/linkly
    newTag: 1.5.0-rc.1
replicas:
  - name: linkly
    count: 1
EOF
kustomize build . | tee ../../rendered.yaml | yq '.metadata.namespace, .spec.replicas, .spec.template.spec.containers[0].image'
kubeconform -strict -summary ../../rendered.yaml
linkly-staging
1
ghcr.io/acme/linkly:1.5.0-rc.1
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0

Non-determinism means permanent drift

If the render changes every time it runs, the agent sees a difference on every pass and the app never stays Synced (or, with auto-sync, redeploys forever). The usual culprits are template functions that generate values:

bash · try it yourself
mkdir -p chart/templates
printf 'apiVersion: v2\nname: demo\nversion: 0.1.0\n' > chart/Chart.yaml
cat > chart/templates/secret.yaml <<'EOF'
apiVersion: v1
kind: Secret
metadata: {name: demo-session}
stringData:
  key: {{ randAlphaNum 16 | quote }}
EOF
helm template demo chart > first.yaml
helm template demo chart > second.yaml
diff -q first.yaml second.yaml && echo "stable" || echo "renders differ: the agent would report OutOfSync on every pass"
Files first.yaml and second.yaml differ
renders differ: the agent would report OutOfSync on every pass

The same goes for now, uuidv4, genCA/genSelfSignedCert, and for checksums of generated content. Under plain Helm, charts often combine randAlphaNum with lookup to keep an existing value; lookup returns nothing during helm template, so the trick doesn't work under Argo CD. Generate such values once, outside the render (a SOPS-encrypted file, a Secret from an external store, a generator in the cluster), as the secrets lesson shows.

What belongs in the repository

Put in Git Keep out of Git
chart versions and values per environment, Kustomize overlays, plain manifests rendered output of every chart, unless you deliberately use the "rendered manifests" pattern (below)
the agent's own objects (Applications, Kustomizations) plain-text Secrets, kubeconfigs, tokens
CRDs you install, Namespaces, RBAC, policies objects that controllers generate (Pods, ReplicaSets, Endpoints, certificate Secrets)
image tags or digests that are deployed latest and other moving tags: the commit would no longer pin what runs

Pin everything that can move. A Deployment that says image: linkly:latest is declarative but not versioned: the same commit can mean different code tomorrow. Pin image tags (or digests), chart versions and Git revisions of remote bases (?ref=v1.2.0).

The rendered-manifests pattern

Some teams have CI render every environment and commit the plain output to a branch or folder that the agent reads (helm template … > rendered/production/linkly.yaml). Pros: reviews show the exact objects that will change, and the agent does no templating. Cons: more commits and a CI step that must never be skipped. Argo CD's Source Hydrator feature (newer and not yet marked stable: check its status in the docs for your version) automates this: it renders a "dry" source and pushes the "hydrated" manifests to another branch. Whichever you choose, put a rendered diff in every pull request so reviewers see objects, not template changes.

Test yourself

A chart template uses randAlphaNum 16 to generate a password. What does a GitOps agent see?

  1. Nothing unusual
  2. A different render on every pass, so the object is permanently OutOfSync or rewritten
  3. An error during rendering
  4. The same value, because the agent caches it

Why is image: ghcr.io/acme/linkly:latest a problem in a GitOps repo?

  1. Kubernetes rejects it
  2. The same commit can deploy different code over time, so Git no longer pins what runs
  3. Argo CD can't parse it
  4. It disables pruning

How does Argo CD deploy a Helm chart?

  1. It runs helm upgrade --install and keeps Helm release history
  2. It renders the chart with helm template and applies the objects itself
  3. It converts it to Kustomize first
  4. It can't deploy Helm charts