The Source Controller
In Flux, fetching and applying are separate jobs. The source-controller watches repositories and registries, and whenever it sees a new revision it downloads it, verifies it, packs it into an artifact (a tarball plus a revision string like main@sha1:33a7838…) and records it in the source object's status. kustomize-controller and helm-controller then consume that artifact. One source can feed many Kustomizations, and a source can be shared across environments while each environment applies a different path.
Source kinds
| Kind | Fetches | Typical use |
|---|---|---|
GitRepository |
a branch, tag, semver range of tags, or commit | the GitOps repo itself |
OCIRepository |
an OCI artifact by tag, semver or digest | manifests or Helm charts pushed to a registry |
HelmRepository |
a classic HTTP Helm repo index (or type: oci) |
third-party charts |
HelmChart |
one chart from a HelmRepository, GitRepository or Bucket | usually created for you by a HelmRelease |
Bucket |
an S3-compatible bucket | air-gapped or non-Git setups |
GitRepository options
flux create … --export writes the object without needing a cluster, so you can generate correct YAML and commit it. This session builds three GitRepository variants and validates them:
flux create source git linkly-deploy \
--url=https://github.com/acme/linkly-deploy --branch=main --interval=1m --export > branch.yaml
flux create source git linkly-deploy-releases \
--url=https://github.com/acme/linkly-deploy --tag-semver=">=1.0.0 <2.0.0" --interval=5m --export > semver.yaml
flux create source git linkly-deploy-private \
--url=ssh://git@github.com/acme/linkly-deploy --branch=main --secret-ref=linkly-deploy-ssh \
--ignore-paths="/docs/,*.md" --interval=1m --export > private.yaml
for f in branch semver private; do
printf '%-8s ref: %s\n' "$f" "$(yq -o json -I0 '.spec.ref' $f.yaml)"
done
yq '.spec.ignore' private.yaml
kubeconform -strict -summary branch.yaml semver.yaml private.yamlbranch ref: {"branch":"main"}
semver ref: {"semver":">=1.0.0 <2.0.0"}
private ref: {"branch":"main"}
/docs/
*.md
Summary: 3 resources found in 3 files - Valid: 3, Invalid: 0, Errors: 0, Skipped: 0
Points worth knowing:
intervalis how often the controller polls; aReceiverwebhook (notification-controller) triggers an immediate fetch on push.ignoreuses.gitignoresyntax to keep files out of the artifact, so a README change doesn't produce a new revision for the appliers.spec.verifychecks Git commit or tag signatures (OpenPGP, and SSH signatures in recent versions) before producing an artifact: unsigned commits never reach the cluster.- Credentials live in a Secret named by
secretRef(SSH key withknown_hosts, or HTTPS basic auth/token).flux create secret gitgenerates it.
OCI artifacts: Git without Git in the cluster
Flux can also reconcile from an OCI registry. CI pushes the manifests folder as an OCI artifact, tagged with the Git commit, and clusters pull from the registry instead of Git. Clusters need no Git credentials at all, registries are easy to mirror into air-gapped environments, and artifacts can be signed with cosign. The flux push/tag/list artifact commands work against any registry; this session uses the local one on localhost:5000:
git init -q linkly-deploy && cd linkly-deploy
mkdir -p apps/staging
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata: {name: linkly-config}\ndata: {LOG_LEVEL: debug}\n' > apps/staging/config.yaml
git add . && git commit -qm "staging config"
sha=$(git rev-parse --short HEAD)
flux build artifact --path=./apps --output=../linkly.tgz >/dev/null && tar -tzf ../linkly.tgz # what gets packed
flux push artifact oci://localhost:5000/linkly-manifests:$sha --path=./apps \
--source=https://github.com/acme/linkly-deploy --revision="main@sha1:$(git rev-parse HEAD)" \
--insecure-registry
flux tag artifact oci://localhost:5000/linkly-manifests:$sha --tag staging
flux list artifacts oci://localhost:5000/linkly-manifests --insecure-registry | awk '{print $1, $4}'► building artifact from ./apps
✔ artifact created at ../linkly.tgz
.
staging
staging/config.yaml
► pushing artifact to localhost:5000/linkly-manifests:9444520
✔ artifact successfully pushed to localhost:5000/linkly-manifests@sha256:e496a8963964d9e80fb2879df8c00d00d176e49c507fc295fdd0780deb63fd13
► tagging artifact
✔ artifact tagged as localhost:5000/linkly-manifests:staging
ARTIFACT REVISION
localhost:5000/linkly-manifests:staging main@sha1:944452033afc6f9b2902f420b445eb030bd73f4a
localhost:5000/linkly-manifests:9444520 main@sha1:944452033afc6f9b2902f420b445eb030bd73f4a
The staging tag works like a pointer: retagging another commit's artifact as staging (or production) is a promotion, without a Git commit in the cluster's path. The cluster side is an OCIRepository that follows the tag:
flux create source oci linkly-manifests --url=oci://ghcr.io/acme/linkly-manifests \
--tag=production --interval=5m --export > oci.yaml
cat oci.yaml
kubeconform -strict -summary oci.yaml---
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
name: linkly-manifests
namespace: flux-system
spec:
interval: 5m0s
provider: generic
ref:
tag: production
url: oci://ghcr.io/acme/linkly-manifests
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
To pin instead of follow, use --digest (or spec.ref.digest); to follow releases, --tag-semver. Add spec.verify with provider: cosign to accept only artifacts signed by your CI.
Reading source status (sample session)
flux get sources git
flux get sources ociNAME REVISION SUSPENDED READY MESSAGE
flux-system main@sha1:40b2f3e1 False True stored artifact for revision 'main@sha1:40b2f3e1'
linkly-deploy main@sha1:40b2f3e1 False True stored artifact for revision 'main@sha1:40b2f3e1'
NAME REVISION SUSPENDED READY MESSAGE
linkly-manifests production@sha256:0ddafb78 False True stored artifact for digest 'production@sha256:0ddafb78'When a source is not ready (wrong credentials, a deleted branch), every Kustomization that uses it keeps the last good artifact applied and reports the source failure: the cluster doesn't change, it just stops following.
Test yourself
What does the source-controller hand to kustomize-controller?
- A Git clone on a shared volume
- An artifact: a tarball of the fetched revision plus its revision string, served over HTTP
- Rendered manifests
- A Helm release
Why would a team reconcile from an OCIRepository instead of a GitRepository?
- OCI is faster to type
- Clusters need no Git credentials, registries mirror easily into air-gapped networks and artifacts can be cosign-signed
- Flux can't read Git
- Kustomize only reads OCI
A GitRepository's credentials expire. What happens to the workloads it feeds?
- They are deleted
- They keep running the last successfully fetched revision while the source reports not ready
- Flux rolls them back
- Flux applies an empty revision