All jobs

Add Image Update Automation to a Flux Repository

Yes. An agent adds Flux's image reflector and automation controllers, an ImageRepository, ImagePolicy and ImageUpdateAutomation for your image tags, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads what Flux already manages before it automates anything. In a GitOps repository like fluxcd/flux2-kustomize-helm-example, apps/base/podinfo/release.yaml is a HelmRelease for podinfo from the HelmRepository at stefanprodan.github.io/podinfo with interval: 50m, RetryOnFailure strategies and values that pin redis.repository: public.ecr.aws/docker/library/redis and redis.tag: 8.6.2; the apps/staging and apps/production overlays patch the chart version to >=1.0.0-alpha and >=1.0.0, so the chart floats on semver but the Redis tag is a string nobody bumps. clusters/staging/artifacts.yaml is an ArtifactGenerator that copies apps/base and apps/staging into an ExternalArtifact, and clusters/staging/apps.yaml reconciles it with prune and wait. clusters/staging/flux-system/gotk-components.yaml holds no image-reflector-controller or image-automation-controller, and .github/workflows/e2e.yaml installs Flux on kind with flux install --components-extra source-watcher, creates the flux-system GitRepository with the workflow's GITHUB_TOKEN and --ignore-paths for clusters/**/flux-system/, then waits on the infra-controllers and apps Kustomizations. test.yaml validates every manifest with flux-schema against .fluxschema.yml and fails if flux migrate -f . would change an API version.

The image API is image.toolkit.fluxcd.io/v1, so the agent writes three objects in the flux-system namespace, because an ImageUpdateAutomation must share a namespace with the GitRepository it pushes to and reads the ImagePolicy objects of that namespace. clusters/staging/image-automation.yaml holds an ImageRepository named redis scanning public.ecr.aws/docker/library/redis on an interval, an ImagePolicy named redis with imageRepositoryRef: {name: redis} and policy: {semver: {range: 8.6.x}} so only patch releases are picked, and an ImageUpdateAutomation with sourceRef: {kind: GitRepository, name: flux-system}, update: {path: ./apps/base, strategy: Setters}, a commit author of fluxcdbot, a messageTemplate that prints {{ .Changed.Summary }} and push: {branch: main}. The file lives under clusters/staging only, so one cluster writes to git and production reads the result. The marker goes next to the value in apps/base/podinfo/release.yaml: tag: 8.6.2 # {"$imagepolicy": "flux-system:redis:tag"}, which is the setter the automation rewrites.

Two things outside the manifests make it work, and the agent says both plainly. The controllers are not in gotk-components.yaml, and that file is written by flux bootstrap, so the agent does not hand-edit it: the pull request tells the operator to rerun bootstrap with --components-extra=source-watcher,image-reflector-controller,image-automation-controller, and the e2e workflow's flux install line gets the same list so CI exercises the CRDs. The GitRepository credentials must be allowed to push: the workflow's GITHUB_TOKEN needs contents: write, and a real cluster needs a deploy key or token with write access in the flux-system secret. Until the controllers exist, the new file would make the flux-system Kustomization report a missing ImageRepository kind, so the description orders the steps: bootstrap with the extra components first, then merge.

Validation runs without a cluster. The agent installs the Flux CLI with the script from fluxcd.io/install.sh and the flux-schema plugin, runs scripts/validate.sh the way test.yaml does, renders kustomize build apps/staging and apps/production to show the marker survives the overlay patch, and runs flux migrate -f . to show the v1 objects need no migration. README.md gains a section on the automation, the marker syntax and how to add a second policy. The chart version ranges, the HelmRepository and the infrastructure controllers are untouched.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add Flux image update automation to this GitOps repository. Read the apps, clusters and infrastructure directories, the gotk-components files and both workflows first. Find container image tags that are pinned as plain strings in Helm values or manifests. For each, add an ImageRepository, an ImagePolicy with a semver range that allows only patch releases, and a setter marker next to the value, and add one ImageUpdateAutomation in the namespace of the flux-system GitRepository that commits to the main branch with a summary message template, placed in one cluster directory only. Use the v1 image API. Do not edit gotk-components.yaml; instead say which --components-extra the bootstrap needs and update the e2e workflow's flux install line to match. State what credentials the GitRepository needs to push and the order of bootstrap and merge. Validate with flux-schema and the validate script, render the overlays with kustomize to show the marker survives, run flux migrate, and include the output. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that adds clusters/staging/image-automation.yaml, changes apps/base/podinfo/release.yaml (the one-line marker), .github/workflows/e2e.yaml (the --components-extra list and contents: write) and README.md. gotk-components.yaml, the overlays and the infrastructure directory are unchanged.

The description names the image, the semver range and the setter path, quotes the flux-schema and validate.sh results, the rendered overlay lines that still carry the marker, the flux migrate output, and gives the two prerequisites in order: bootstrap with the extra controllers, then merge; and a push-capable credential on the flux-system source. The commands and full output are in the transcript at GET /o/{org}/sessions/{id}/messages.

Before merging, a reviewer decides whether the automation should push to main or to a branch that opens a pull request, whether a patch-only range is right for every image, and which cluster owns the write. A follow-up message to the same session can add a second policy for the podinfo chart's own image, or switch the push to a branch.

Run it on every GitOps repository with hand-pinned image tags

A platform team starts one run per repository with one POST /o/{org}/sessions each, the repository in resources and this prompt as input. Each run reads its own tags, so a repository with six services gets six policies and one automation, and one that already runs the controllers gets only the objects and markers.

Send a request_id, a UUID v5 of the repository's full name, so a retried call returns the run it already started. The key's webhook_url reports when each run the key starts finishes, with the run's final answer in result.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The objects are short; the mistakes are structural: the automation in the wrong namespace, a marker that the overlay patch drops, controllers the bootstrap never installed, a source that cannot push. The agent reads the cluster layout and the workflows, renders the overlays to prove the marker survives, validates against the published schemas in a sandbox of its own and keeps every command's output.

The pull request carries the manifests, the validation and the two prerequisites in order, so review is a diff and two decisions rather than a kind cluster on a laptop. Several repositories can be done at once, each in its own sandbox with its own pull request.

Frequently asked questions

Does this change what runs in the cluster today?

Not by itself. The policy only selects a tag inside 8.6.x, and the first commit the automation writes is the first time anything moves. Until the controllers are installed the objects are not reconciled at all, which is why the description orders bootstrap before merge.

Can it open a pull request instead of pushing to main?

Yes. Set push.branch to a branch of its own and let your existing review flow open the pull request from it; say so in the prompt and the agent writes that branch and a note on how to set up the PR step. The controller itself does not open pull requests.

Why is the automation in only one cluster directory?

Both clusters sync the same repository. Two automations would both scan and both try to commit the same change, racing on the push. One cluster writes, the other reads the result on its next sync.

What about images on a private registry?

An ImageRepository takes a secretRef to a registry credential, or uses the node's provider auth on GKE, EKS and AKS with provider set. Say which registry in the prompt and the agent adds the reference and documents the secret, without creating it.

More Flux jobs

More jobs like this: Hand off a long task

Keep reading