$ show fluxcd/flux2
Flux2 is a CLI tool (the `flux` command) for implementing GitOps workflows on Kubernetes. It manages the lifecycle of Flux-specific Kubernetes resources (GitRepository, HelmRepository, OCIRepository, Kustomization, HelmRelease, ImageRepository, etc.) by generating manifests, applying them via server-side apply, and monitoring reconciliation status. The CLI is built with Cobra and provides subcommands for bootstrap, install, create, get, reconcile, suspend, resume, export, delete, diff, build, push, pull, tag, trace, tree, events, logs, check, migrate, uninstall, and plugin management. It supports multiple Git providers (GitHub, GitLab, Gitea, Bitbucket Server), OCI registries, Helm repositories, and cloud authentication (AWS, Azure, GCP). The architecture follows an adapter pattern where each resource type implements a common interface, enabling generic command implementations. Key data flows include: (1) bootstrap: clone a Git repository, generate manifests, push sync config, wait for readiness; (2) install: deploy Flux controllers and CRDs onto a cluster; (3) reconcile: fetch desired state from a source (Git, OCI, Helm), compute diff, apply via Kubernetes API, wait for convergence; (4) artifact management: build tarballs from manifests and push to OCI registries with metadata. External dependencies include Kubernetes controller-runtime, go-containerregistry, go-git, and various cloud SDKs. The repository also serves as the distribution hub for Flux controller manifests and includes a GitHub Action for installing the CLI in CI pipelines.
The LLM identified 5 files worth highlighting for reuse:
Implements a StatusChecker that polls Kubernetes resources until they reach a desired state. Provides `isObjectReadyConditionFunc` and `isStaticObjectReadyConditionFunc` which return `wait.ConditionWithContextFunc` for use with `wait.PollUntilContextTimeout`. This is a reusable pattern for any Kubernetes CLI that needs to wait for resource convergence after create/update operations. It is self-contained, depends only on standard Kubernetes client libraries, and can be extracted with minimal modification.
Provides a systematic uninstall orchestration for Flux components, finalizers, CRDs, and namespace. Supports dry-run mode and aggregates errors across all removal steps. The functions (`Components`, `Finalizers`, `CustomResourceDefinitions`, `Namespace`) are independent and can be reused in any Kubernetes cleanup tool. The pattern of collecting errors and continuing despite failures is a robust design for destructive operations.
Implements plugin discovery by scanning a directory (`~/.fluxcd/plugins/`) for executables matching the `flux-<name>` pattern. Uses injected dependencies (`ReadDir`, `Stat`, `GetEnv`, `HomeDir`) for testability. The discovery logic is isolated and can be extracted to build plugin systems for other CLI tools. The design demonstrates clean separation of concerns and testability through dependency injection.
Implements a two-phase server-side apply for Kubernetes manifests: first applies CRDs and namespaces, then applies all other resources. This ensures dependencies are created before dependent resources. The function handles errors gracefully and returns a list of applied objects. This pattern is reusable for any Kubernetes CLI that needs to apply manifests with ordering constraints. It is self-contained and depends only on standard Kubernetes client interfaces.
Provides a template-based manifest generation engine used by the install and bootstrap commands. It uses Go templates to generate Kubernetes manifests from parameterized inputs. The template system is self-contained and can be extracted for any project that needs to generate YAML/JSON manifests from templates. The design supports variable substitution and conditional logic, making it a flexible alternative to more heavyweight template engines.