Skip to main content
Work in Progress

You are viewing development documentation built from the latest commit on main (last tag v0.2.0-rc.2, source commit 25e1a892). APIs and features are subject to change.

Flux Defaults

This package is a workflow layer above pkg/kubernetes, so unlike the builders it may hold opinions — but only as declared inputs with names a consumer can read, compare against and override. Every fallback this package applies is one of the exported identifiers in defaults.go, or comes from layout.DefaultLayoutRules() where the value belongs to pkg/stack/layout; grep for the identifier to find every place its value can reach emitted YAML.

IdentifierValueApplies whenOverride by
DefaultInterval60mthe caller names no interval (a non-empty Bundle.Interval that does not parse is a validation error, not a fallback; see Durations for the values Flux does not take)assigning .DefaultInterval on either generator
DefaultNamespaceflux-systemgenerated resources need a namespaceassigning .DefaultNamespace on either generator
DefaultModelayout.KustomizationExplicitinformational: the listing mode the layout writers use for a layout with no Mode of its ownsetting ManifestLayout.Mode (or Config.KustomizationMode for WriteManifest)
DefaultBootstrapNameflux-systemnaming the gotk bootstrap Kustomization without SyncNameassigning BootstrapGenerator.BootstrapName, or setting BootstrapConfig.SyncName with a SourceURL
FluxInstanceNamefluxnaming the FluxInstance in flux-operator modenot overrideable; the CRD admits no other name (see below)
DefaultSourceNameflux-systemthe root node has no name and SyncName is unsetnaming the root stack.Node, or setting BootstrapConfig.SyncName
DefaultFluxModeflux-operatorBootstrapConfig.FluxMode is emptysetting BootstrapConfig.FluxMode
DefaultSourceKindOCIRepositoryBootstrapConfig.SourceKind does not name GitRepository, the empty string includedsetting BootstrapConfig.SourceKind
DefaultFluxDirNameflux-systema separate Flux layout needs a directorynot overrideable
DefaultSourceReflatestan OCI source, or an OCI FluxInstance sync, has no SourceRefsetting BootstrapConfig.SourceRef
DefaultSyncPath./the bootstrap applies the root of the source (no root node, no ClusterName)not overrideable; it is the prefix a sync path is built from

Three of these — DefaultInterval, DefaultNamespace and DefaultBootstrapName — are copied into exported generator fields by NewResourceGenerator / NewBootstrapGenerator, and a field assigned afterwards is never overridden. The rest are applied where they are used and are overridden by naming the corresponding input, as the last column says. Two defaults have no override at all and say so, rather than being listed as though they had one; FluxInstanceName is the third row without one, and is not a default at all (next but one paragraph).

An empty BootstrapGenerator.BootstrapName resolves back to DefaultBootstrapName at emission. A generator built as a struct literal rather than through NewBootstrapGenerator leaves the field zero, and a Kustomization with no metadata.name is invalid — the field is an override, not a way to remove the name.

FluxInstanceName is in the table but is not a default: it is the one value the flux-operator CRD accepts. The CRD requires metadata.name: flux and rejects any other name at admission (x-kubernetes-validations: self.metadata.name == 'flux', in the vendored install bundle), so BootstrapName does not reach the FluxInstance and nothing else does either. It used to — both objects took bootstrapName() — so a flux-operator bundle with the default BootstrapName, or any override other than flux, was refused with the only accepted name for a FluxInstance is 'flux'. A test compares the constant against the vendored CRD’s rule, so an operator bump that changes the rule fails in this package rather than at apply.

DefaultNamespace governs the whole gotk bundle, not just the objects this package constructs itself. The bootstrap bundle has three producers — the root Kustomization, the root source, and the toolkit components generated by install.Generate — and the third takes its namespace from an upstream option whose own default is also flux-system. That option is set from BootstrapGenerator.DefaultNamespace, so overriding the field moves the controllers’ Deployments, ServiceAccounts, Services, NetworkPolicies and ResourceQuota along with everything else. The cluster-scoped objects follow without further work — install.Generate derives the emitted Namespace’s name and the ClusterRoleBinding names and subjects from the same option, while CRDs and ClusterRoles carry no namespace to correct. Before this was wired up the field half-applied: a non-default value left the components in flux-system while the objects depending on them moved. That split still reconciles, because the components default to WatchAllNamespaces: true — so it surfaces only when someone narrows the controllers to their own namespace, at which point reconciliation stops with no error. WatchAllNamespaces is deliberately left at the upstream default and is not currently derived from any field here.

In flux-operator mode — the default — the field reaches only the FluxInstance. That bundle’s other objects come from the vendored upstream install manifest, appended unmodified, so its Namespace, ServiceAccount, Service and Deployment stay at the upstream flux-system whatever this field says. Relocating the operator itself is not something this package offers.

The wiring is guarded on the field being non-empty, which matters only for a struct-literal generator. install.Generate uses the option as the emitted Namespace’s name, so assigning it unconditionally would make a generator with a zero DefaultNamespace fail the whole bundle — missing metadata.name in object {{v1 Namespace}} — rather than fall back. Guarded, that generator keeps the upstream flux-system for the components.

That generator is nonetheless inconsistent, and the guard does not fix it: the root Kustomization and the root source read the same empty value and emit no namespace at all, so the components sit in flux-system while the objects referencing them are unnamespaced. This predates the namespace wiring and is a property of struct-literal construction across this package rather than of one option. Construct through NewBootstrapGenerator, which populates the field; a struct literal is not a supported way to get a coherent bundle.

defaults.go also declares ModeGotk = "gotk", which is not a default: nothing falls back to it. It is named so that the bootstrap mode set has one authority. DefaultFluxMode is both the fallback for an empty BootstrapConfig.FluxMode and the mode GenerateBootstrap dispatches on, and SupportedBootstrapModes() reports exactly those two — the validation error for an unrecognised mode reads its list from that method rather than restating the names.

DefaultFluxDirName shares DefaultNamespace’s value and is deliberately a separate identifier: one is a path segment and the other a Kubernetes namespace, and renaming the namespace must not silently rename the directory.

Three defaults are not declared here because this package does not own them. The separate Flux layout’s file granularity and the fallback for an unset FluxPlacement both come from layout.DefaultLayoutRules(), which is where pkg/stack/layout declares them and where its own walker reads them from. A constant here would be a second copy of a value that can change independently.

The third is that layout’s own Mode, left unset. The layout writer resolves an unset mode to KustomizationExplicit, and the separate Flux layout never has children, so the mode selects nothing there.

One resolved source kind, not three

resolvedSourceKind is the only place the source kind is decided. Three sites need it — the source object itself, the bootstrap Kustomization’s spec.sourceRef.Kind, and the FluxInstance sync block — and they used to decide it separately, with the sourceRef testing for OCIRepository while the other two tested for GitRepository. The three agreed only when SourceKind named a kind exactly; an empty or unrecognised SourceKind emitted an OCIRepository under a sourceRef naming a GitRepository that was never created.

One resolved source ref, on both bootstrap paths

For an OCI tag, an empty ref or a bare Git branch name, BootstrapConfig.SourceRef selects the same revision in both modes. The gotk source reads it as an OCI tag, falling back to DefaultSourceRef, or as a Git branch. flux-operator renders the FluxInstance’s spec.sync.ref as the source’s ref.tag for OCI and as ref.name for Git, and ref.name takes a full Git reference. resolvedSyncRef bridges the two: an empty OCI ref becomes DefaultSourceRef, a Git branch name becomes refs/heads/<name>, and an empty Git ref stays empty. A Git ref that already starts with refs/ — a tag, say — passes through unchanged in flux-operator mode only: the gotk source still puts any Git SourceRef into ref.branch, so there a full reference is not equivalent. Before this, spec.sync.ref was SourceRef verbatim: an empty OCI tag where the gotk source used latest, and a bare branch name where Flux needs a full reference. A SourceSemVer range takes the tag’s place in both modes, as Semver source ref describes.

prune and wait are inputs, not policy

Bundle.Prune and Bundle.Wait are *bool and are passed through untouched. BootstrapConfig.Prune does the same for the gotk bootstrap Kustomization. In flux-operator mode a set Prune becomes a patch on the operator’s sync Kustomization, and unset keeps the operator’s prune: true (see Prune , go-kure/kure#1088). ResourceGenerator.Prune is passed through untouched for a Kustomization generated from a layout.ManifestLayout where neither the layout nor the bundle that holds its application sets one. A layout carries both settings, ManifestLayout.Prune and ManifestLayout.Wait, unset meaning that bundle’s (see Per-layout settings ).

The two fields resolve differently because their upstream tags differ:

  • KustomizationSpec.Prune is +required with no omitempty, so an unset input cannot leave the key out. Unset emits prune: false — garbage collection off. An unset tri-state previously collapsed onto prune: true, enabling destructive garbage collection for a caller who never asked for it.
  • KustomizationSpec.Wait is +optional with omitempty, so unset and false produce the same YAML: the key is absent and Flux’s own default, false, applies.

The one exception is ResourceGenerator.UmbrellasDoNotWait: under it an unset Wait on a Kustomization that applies no Flux Kustomization resolves to true, and an umbrella gets no wait (see With UmbrellasDoNotWait ).

Sources (GitRepository, OCIRepository) and the FluxInstance are built the way the builder contract prescribes: the pkg/kubernetes/fluxcd Create<Kind> constructor returns a typed object, and the generator assigns the plain fields directly.

gr := pubfluxcd.CreateGitRepository(ref.Name, namespace)
gr.Spec.URL = ref.URL
gr.Spec.Interval = metav1.Duration{Duration: g.DefaultInterval}

Only writes that the contract admits as sugar keep a helper — appending to a slice field, or assigning a pointer field through a constructed value, as with SetGitRepositoryReference. See Kubernetes Builders for the admission rules.