agentleFS
fluxcdfluxcd/flux2/AGENTS.md

flux2

AGENTS.md8.5k starsChanged 5 years agoApache-2.0View on GitHub

Guidance for AI coding assistants working in fluxcd/flux2. Read this file before making changes. These rules come from fluxcd/flux2/CONTRIBUTING.md and apply to every Flux repository. The -s flag adds the human's Signed-off-by from their git config — do not remove it. - Commit message format: Subject in imperative mood ("Add feature X" instead of "Adding feature X"), capitalized, no trailing period, ≤50 characters. Body wrapped at 72 columns, explaining what and why. No @mentions or #123 issue references in the…

  • Installs packages

Trending

Less talk lately.about the whole repository

Dec 2025: 1 mentionJan 2026: 0 mentionsFeb 2026: 2 mentionsMar 2026: 2 mentionsApr 2026: 1 mentionMay 2026: 2 mentionsJun 2026: 3 mentionsJul 2026: 2 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 1 mentionNov 2026: 1 mention
Dec 2025Jun 2026Nov 2026
Mentions a month of the fluxcd/flux2 repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about fluxcd/flux2

The biggest 5 of 48 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 48

Talked about on GitHub, Stack Overflow, Bluesky and Hacker News (48 times).

On GitHub · 38

33 more on GitHub

On Hacker News · 1

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 31,439 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

16 rules. About 1 is common, 1 is distinctive, and 14 are very specific to this project.

  • ≈1

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Rebase, don't merge: Never merge main into the feature branch.

    line 17
  2. Very specific:

    Copyright: All new .go files must begin with the header from cmd/flux/main.go (Apache 2.0).

    line 20
  3. Distinctive:

    Before submitting code, review your changes for the following:

    line 25
  4. Common:

    No secrets in logs or output: Never surface auth tokens, passwords, deploy keys, or credential URLs in error messages, log lines, or CLI …

    line 27
  5. Very specific:

    No command injection: Do not shell out via os/exec for git, helm, or kustomize operations.

    line 30
  6. Very specific:

    Resource cleanup: Ensure temporary files and directories (manifest staging, downloaded tarballs) are cleaned up on all code paths (success …

    line 33
  7. Very specific:

    No panics: Never use panic in runtime code paths.

    line 34
  8. Very specific:

    Minimal surface: Keep new exported APIs in pkg/ to the minimum needed.

    line 36
  9. Very specific:

    When modifying manifests/, always run make build and verify the generated output before committing.

    line 85
  10. Very specific:

    All targets in the root Makefile.

    line 89
  11. Very specific:

    Run a single test: make test TEST_ARGS='-run TestCreate -v'.

    line 101
  12. Very specific:

    Check go.mod and the Makefile for current dependency and tool versions.

    line 105
  13. Very specific:

    Command pattern: follow the existing group-parent + per-resource-child cobra structure.

    line 121
  14. Very specific:

    SSA apply: always use internal/utils.Apply() (two-phase: CRDs/Namespaces first, then rest).

    line 124
  15. Very specific:

    Flags: use internal/flags/ custom pflag.Value types for enum flags (providers, algorithms, sources).

    line 127
  16. Very specific:

    Run a single unit test: make test TEST_ARGS='-run TestInstall -v'.

    line 139

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

Guidance for AI coding assistants working in fluxcd/flux2. Read this file before making changes.

Contribution workflow for AI agents

These rules come from fluxcd/flux2/CONTRIBUTING.md and apply to every Flux repository.

  • Do not add Signed-off-by or Co-authored-by trailers with your agent name. Only a human can legally certify the DCO.
  • Disclose AI assistance with an Assisted-by trailer naming your agent and model:
    git commit -s -m "Add support for X" --trailer "Assisted-by: <agent-name>/<model-id>"
    The -s flag adds the human's Signed-off-by from their git config — do not remove it.
  • Commit message format: Subject in imperative mood ("Add feature X" instead of "Adding feature X"), capitalized, no trailing period, ≤50 characters. Body wrapped at 72 columns, explaining what and why. No @mentions or #123 issue references in the commit — put those in the PR description.
  • Trim verbiage: in PR descriptions, commit messages, and code comments. No marketing prose, no restating the diff, no emojis.
  • Rebase, don't merge: Never merge main into the feature branch; rebase onto the latest main and push with --force-with-lease. Squash before merge when asked.
  • Pre-PR gate: make tidy fmt vet && make test must pass and the working tree must be clean.
  • Flux is GA: Backward compatibility is mandatory. Breaking changes to CLI flags, output format, or behavior will be rejected. Design additive changes.
  • Copyright: All new .go files must begin with the header from cmd/flux/main.go (Apache 2.0). Update the year to the current year when copying.
  • Tests: New features, improvements and fixes must have test coverage. Add unit tests in cmd/flux/*_test.go tagged //go:build unit. Follow the existing cmdTestCase + golden file patterns. Run tests locally before pushing.

Code quality

Before submitting code, review your changes for the following:

  • No secrets in logs or output. Never surface auth tokens, passwords, deploy keys, or credential URLs in error messages, log lines, or CLI output. Bootstrap and source-secret commands handle sensitive material — take extra care.
  • No unchecked I/O. Close HTTP response bodies, file handles, and tar readers in defer statements. Check and propagate errors from I/O operations.
  • No path traversal. Validate and sanitize file paths extracted from archives or user input. Never filepath.Join with untrusted components without validation.
  • No command injection. Do not shell out via os/exec for git, helm, or kustomize operations. Use the Go libraries already in use (fluxcd/pkg/git, fluxcd/pkg/kustomize, fluxcd/pkg/ssa).
  • No hardcoded defaults for security settings. TLS verification must remain enabled by default. Git auth settings come from user-provided secrets.
  • Error handling. Wrap errors with %w for chain inspection. Do not swallow errors silently. CLI errors must be actionable — tell the user what went wrong and how to fix it without leaking internal state.
  • Resource cleanup. Ensure temporary files and directories (manifest staging, downloaded tarballs) are cleaned up on all code paths (success and error). Use defer and t.TempDir() in tests.
  • No panics. Never use panic in runtime code paths. Return errors and let the CLI handle them gracefully.
  • Output discipline. Machine-readable data (tables, YAML, JSON) goes to stdout via rootCmd.OutOrStdout(). Human-readable status messages go to stderr via the stderrLogger.
  • Minimal surface. Keep new exported APIs in pkg/ to the minimum needed. Every export is a backward-compatibility commitment.

Project overview

flux2 is the Flux CLI (flux command) and distribution repository. It is not a controller — it consumes CRD APIs from six independent controller repos (source-controller, kustomize-controller, helm-controller, notification-controller, image-reflector-controller, image-automation-controller). It serves two purposes:

  1. CLI tool — a Cobra-based binary that installs Flux onto Kubernetes clusters, bootstraps GitOps pipelines, and manages all Flux CRD objects (create, get, export, reconcile, suspend, resume, delete, diff, build, etc.).
  2. Distribution hub — it bundles the Kustomize manifests for all Flux controllers and releases them as manifests.tar.gz on GitHub. Those manifests are also compiled into the binary itself via //go:embed.

Repository layout

  • cmd/flux/ — all CLI source. Single main package with one file per command or resource type. main.go defines the root cobra command with global flags. manifests.embed.go embeds the generated controller manifests via //go:embed.
  • internal/build/ — flux build kustomization logic (kustomize-based diff/build, SOPS secret masking).
  • internal/flags/ — custom pflag.Value types providing enum validation (e.g. LogLevel, ECDSACurve, RSAKeyBits, PublicKeyAlgorithm, DecryptionProvider).
  • internal/tree/ — tree-printing helper for flux tree kustomization.
  • internal/utils/ — shared helpers: KubeClient, KubeConfig, NewScheme (registers all controller API groups), Apply (SSA-based two-phase apply), ExecKubectlCommand, ValidateComponents.
  • pkg/bootstrap/ — bootstrap orchestration: Run(), PlainGitBootstrapper, ProviderBootstrapper. provider/ has the git provider factory (GitHub, GitLab, Gitea, Bitbucket).
  • pkg/log/ — Logger interface (Actionf, Generatef, Waitingf, Successf, Warningf, Failuref).
  • pkg/manifestgen/ — manifest generation for install, sync, kustomization, and source secrets.
  • pkg/printers/ — specialized printers TablePrinter and DyffPrinter.
  • pkg/status/ — StatusChecker using fluxcd/cli-utils kstatus polling.
  • pkg/uninstall/ — flux uninstall logic.
  • manifests/ — Kustomize bases per controller, RBAC, network policies, CRD references, and scripts/bundle.sh which runs kustomize build to generate cmd/flux/manifests/.
  • tests/integration/ — cloud e2e tests (Azure/GCP) with their own go.mod and Terraform infrastructure.
  • rfcs/ — Request for Comments documents for major design proposals and changes.

CLI architecture

Commands are Cobra-based, organized as parent + per-resource children:

  • Group files (create.go, get.go, reconcile.go, etc.) register the parent subcommand.
  • Per-resource files (create_kustomization.go, get_helmrelease.go, etc.) register children.

Core interfaces in cmd/flux/ enable generic command implementations:

  • adapter / copyable / listAdapter — wrap controller API types for generic CRUD.
  • reconcilable — annotate-and-poll pattern for triggering reconciliation.
  • summarisable — generic table output for get commands.

Each resource type (e.g. kustomizationAdapter in kustomization.go) wraps the controller API type and implements these interfaces. Follow this pattern when adding new resource support.

Commands interact with the Kubernetes API via internal/utils.KubeClient() → client.WithWatch. internal/utils.NewScheme() registers all six controller API groups plus core k8s types. internal/utils.Apply() implements SSA-based two-phase apply (CRDs/Namespaces first, then remaining objects).

Manifest pipeline

  1. manifests/bases/<controller>/ contains a Kustomize base per controller referencing the controller's GitHub release for CRDs and deployment manifests.
  2. manifests/install/kustomization.yaml assembles all bases plus RBAC and policies.
  3. manifests/scripts/bundle.sh runs kustomize build on each base, writing output to cmd/flux/manifests/ (not checked in — generated).
  4. The Makefile $(EMBEDDED_MANIFESTS_TARGET) runs bundle.sh and creates a sentinel file cmd/flux/.manifests.done.
  5. cmd/flux/manifests.embed.go uses //go:embed manifests/*.yaml to compile everything into the binary.

When modifying manifests/, always run make build and verify the generated output before committing. Never hand-edit files under cmd/flux/manifests/.

Build, test, lint

All targets in the root Makefile. Go version tracks go.mod.

  • make tidy — tidy the root module and tests/integration/.
  • make fmt / make vet — run in the root module.
  • make build — builds bin/flux (CGO disabled, version injected via ldflags). Depends on embedded manifests being generated.
  • make build-dev — builds with DEV_VERSION.
  • make install / make install-dev — go install or copy to /usr/local/bin.
  • make test — unit tests with envtest: runs tidy fmt vet install-envtest, then go test ./... -coverprofile cover.out --tags=unit $(TEST_ARGS).
  • make e2e — e2e tests against a live cluster: go test ./cmd/flux/... --tags=e2e -v -failfast.
  • make test-with-kind — sets up a kind cluster, runs e2e, tears it down.
  • make install-envtest — downloads setup-envtest and fetches k8s binaries into testbin/.

Run a single test: make test TEST_ARGS='-run TestCreate -v'.

Codegen and generated files

Check go.mod and the Makefile for current dependency and tool versions. The main codegen pipeline is the manifest bundle:

./manifests/scripts/bundle.sh

Generated files (never hand-edit):

  • cmd/flux/manifests/*.yaml — generated by bundle.sh from manifests/ sources.
  • cmd/flux/.manifests.done — sentinel file tracking bundle state.

Bump fluxcd/pkg/* and controller api modules as a set. Run make tidy after any bump.

Conventions

  • Standard gofmt. All exported names need doc comments.
  • Command pattern: follow the existing group-parent + per-resource-child cobra structure. New resources need an adapter type implementing adapter, copyable, and the relevant command interfaces (reconcilable, summarisable, etc.).
  • Output: stderr for human status messages via stderrLogger (Unicode symbols: ► action, ✔ success, ✗ failure, ◎ waiting, ⚠️ warning, ✚ generate). Stdout for machine-readable data (tables, YAML, JSON) via rootCmd.OutOrStdout().
  • Global flags: kubeconfig flags come from k8s.io/cli-runtime/pkg/genericclioptions.ConfigFlags. Client tuning comes from fluxcd/pkg/runtime/client.Options. FLUX_SYSTEM_NAMESPACE env var overrides the default namespace.
  • SSA apply: always use internal/utils.Apply() (two-phase: CRDs/Namespaces first, then rest). Do not apply manifests directly via the k8s client.
  • Reconcile triggering: patch meta.ReconcileRequestAnnotation with a timestamp, then poll with kstatus.Compute() until ready. See reconcile.go.
  • Error handling: return errors from RunE. Use *RequestError with exit codes for actionable CLI errors. Exit code 1 = warning, anything else = failure.
  • Flags: use internal/flags/ custom pflag.Value types for enum flags (providers, algorithms, sources). Add new enum types there.

Testing

Three test suites with build tags:

  • Unit (//go:build unit): lives in cmd/flux/*_test.go. Uses controller-runtime/envtest for an in-process fake k8s API. CRDs are loaded from cmd/flux/manifests/ (embedded manifests). Pattern: cmdTestCase{args: "...", assert: assertGoldenFile("testdata/...")}. The executeCommand() helper captures stdout.
  • E2e (//go:build e2e): lives in cmd/flux/*_test.go. Requires a live cluster via TEST_KUBECONFIG. TestMain runs flux install for setup and teardown.
  • Integration (//go:build integration): lives in tests/integration/ with its own go.mod. Uses Terraform-provisioned cloud clusters.

Golden files live in cmd/flux/testdata/. Update them with go test ./cmd/flux/... --tags=unit -update.

Run a single unit test: make test TEST_ARGS='-run TestInstall -v'.

Gotchas and non-obvious rules

  • The cmd/flux/manifests/ directory is generated, not checked in. It is created by manifests/scripts/bundle.sh and embedded into the binary. make build and make test both trigger the bundle if the sentinel file is stale.
  • kustomize must be on PATH for bundle.sh to work. If you see "command not found" errors during build, install kustomize.
  • internal/utils.NewScheme() registers all six controller API groups. Adding support for a new CRD type means updating the scheme registration there.
  • The VERSION constant is injected via -ldflags at build time. In dev builds it defaults to 0.0.0-dev.0. The embedded manifest version check (isEmbeddedVersion) determines whether flux install uses compiled-in manifests or downloads from GitHub.
  • resetCmdArgs() in tests is critical — Cobra persists flag state between test runs. Every test case must reset to avoid pollution.
  • executeCommand() captures stdout only. Stderr output (from stderrLogger) is not captured in test assertions. If your command's output goes to the wrong stream, tests will silently pass with empty golden files.
  • The adapter / listAdapter interfaces use type assertions internally. If you add a new resource type and forget to implement an interface method, you'll get a runtime panic in the generic command handler, not a compile error. Add interface compliance checks (var _ reconcilable = ...).
  • Bootstrap commands create real Git commits and push to real repos. E2e tests for bootstrap need careful cleanup. Do not add bootstrap e2e tests without a corresponding teardown.
  • pkg/ packages are importable by external consumers (e.g. Terraform provider, other tools). Treat their exported surface as public API.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.