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.
FluxCD Builders
Low-level builder functions for FluxCD Kubernetes resources. Each resource type follows the Create*(name, namespace) + Set*()/Add*() pattern.
Each block on this page, except the one marked as an excerpt, is the body of an Example function
in example_test.go, which go test runs: it imports this package as fluxcd, the Flux APIs as
sourcev1 (github.com/fluxcd/source-controller/api/v1), kustv1
(github.com/fluxcd/kustomize-controller/api/v1), helmv2
(github.com/fluxcd/helm-controller/api/v2), meta and kustomize
(github.com/fluxcd/pkg/apis/meta, github.com/fluxcd/pkg/apis/kustomize),
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1", time, and fmt for the line that prints what
the example built.
Constructors
Every kind this package registers has a generated Create<Kind> wrapper in zz_generated_create.go, produced from the scheme by pkg/kubernetes/internal/gen (make gen-builders, checked by make check-builders in CI). A wrapper delegates to kubernetes.Create[T] and emits TypeMeta and identity only: no default, no label, no spec value. Namespaced kinds take (name, namespace), cluster-scoped kinds take (name). The upstream struct is the construction API; set spec fields directly or through the admissible Set*/Add* sugar below.
Twenty-four hand-written constructors for spec fragments remain (CreateGitSpec, CreatePostBuild, CreateInstallRemediation, CreateCrossNamespaceSourceReference and the rest). Their sub-types are not client.Object, so they get no generated wrapper, and Flux’s spec fragments are deep enough that assembling one by literal at every call site is the less readable option. They are not identity constructors and are not covered by the identity test — for anything they do not cover, a struct literal is the idiom.
The kinds this package registers, their scope, and what stated that scope are rows in the generated Supported kinds and field maturity tables. The sections below are worked examples, not the coverage list.
See the Kubernetes Builders page for the full builder contract: construction, sugar admission classes, purity and the release-1 migration ledger.
Source Controllers
GitRepository
Additional setters: SetGitRepositoryTimeout, SetGitRepositoryVerification,
SetGitRepositoryProxySecretRef, SetGitRepositoryIgnore, AddGitRepositoryInclude,
AddGitRepositorySparseCheckoutPath.
OCIRepository
Additional setters: SetOCIRepositoryLayerSelector, SetOCIRepositoryVerify,
SetOCIRepositoryCertSecretRef, SetOCIRepositoryProxySecretRef, SetOCIRepositoryTimeout,
SetOCIRepositoryIgnore.
The OIDC provider and plain-HTTP access are plain fields with no setter: assign them,
oci.Spec.Provider = "aws" and oci.Spec.Insecure = true. A setter for a single plain field
is outside the builder contract
.
HelmRepository
HTTP/HTTPS repository:
OCI registry:
Additional setters: SetHelmRepositoryCertSecretRef, SetHelmRepositoryAccessFrom.
HelmChart
Additional setters: AddHelmChartValuesFile, SetHelmChartVerify.
Note:
source-controller/apihas separate verification types for the two kinds.SetHelmChartVerifytakes*sourcev1.HelmChartVerificationandSetOCIRepositoryVerifytakes*sourcev1.OCIRepositoryVerification. Both kinds are v1.
Bucket
Additional setters: SetBucketSTS, SetBucketCertSecretRef, SetBucketProxySecretRef,
SetBucketTimeout, SetBucketIgnore.
Deployment Controllers
Kustomization
Additional setters: SetKustomizationRetryInterval, SetKustomizationKubeConfig,
AddKustomizationHealthCheck, AddKustomizationHealthCheckExpr, AddKustomizationComponent,
SetKustomizationTimeout, AddKustomizationImage, AddKustomizationPatch,
SetKustomizationCommonMetadata, SetKustomizationDecryption, SetKustomizationPostBuild.
HelmRelease
Chart template (chart + version + source reference):
SetHelmReleaseValuesFromMap panics rather than returning an error, because a
sugar helper cannot return one under the builder contract. Only a value that
encoding/json refuses outright — a channel, a function, a NaN or +Inf
float, a cyclic structure — reaches that panic. Decoded YAML can carry one:
gopkg.in/yaml.v3 decodes the legal YAML scalars .nan and .inf into a
float64 NaN or +Inf without error. sigs.k8s.io/yaml converts through JSON
and returns that error at decode time instead, so a map it produced always
marshals. When values come from a decoder that could produce such a value,
marshal them yourself and hand the result to SetHelmReleaseValues:
ChartRef mode (existing OCIRepository or HelmChart):
Drift detection and remediation:
Post-render:
Additional setters: SetHelmReleaseKubeConfig, AddHelmReleaseDependsOn, SetHelmReleaseTimeout,
SetHelmReleaseMaxHistory, SetHelmReleasePersistentClient, SetHelmReleaseInstall,
SetHelmReleaseUpgrade, SetHelmReleaseRollback, SetHelmReleaseUninstall, SetHelmReleaseTest,
SetHelmReleaseValues, SetHelmReleaseValuesFromMap, SetHelmReleaseCommonMetadata,
AddHelmReleaseHealthCheckExpr, SetHelmReleaseWaitStrategy.
Install flag setters: SetHelmReleaseInstallTimeout, SetHelmReleaseInstallCRDs,
SetHelmReleaseInstallCreateNamespace, SetHelmReleaseInstallDisableSchemaValidation,
SetHelmReleaseInstallDisableOpenAPIValidation, SetHelmReleaseInstallDisableHooks,
SetHelmReleaseInstallDisableWait, SetHelmReleaseInstallDisableWaitForJobs,
SetHelmReleaseInstallDisableTakeOwnership, SetHelmReleaseInstallReplace,
SetHelmReleaseInstallRemediation.
Upgrade flag setters: SetHelmReleaseUpgradeTimeout, SetHelmReleaseUpgradeCRDs,
SetHelmReleaseUpgradeDisableSchemaValidation, SetHelmReleaseUpgradeDisableOpenAPIValidation,
SetHelmReleaseUpgradeDisableHooks, SetHelmReleaseUpgradeDisableWait,
SetHelmReleaseUpgradeDisableWaitForJobs, SetHelmReleaseUpgradeDisableTakeOwnership,
SetHelmReleaseUpgradeForce, SetHelmReleaseUpgradePreserveValues,
SetHelmReleaseUpgradeCleanupOnFail, SetHelmReleaseUpgradeRemediation.
Notification Controllers
CreateProvider, CreateAlert and CreateReceiver all emit
notification.toolkit.fluxcd.io/v1. For Provider and Alert that requires Flux 2.10 or
newer on the target cluster: older releases serve them only at v1beta3 and reject a v1
object. The supported Flux range and its per-kind floors are in the
compatibility matrix
.
Migrating Provider and Alert to v1
Flux 2.10 promoted Provider and Alert to v1, the stored version. Kure follows:
CreateProviderandCreateAlertreturn*notificationv1.Providerand*notificationv1.Alert, and every Provider and Alert setter takes thev1type. A variable declared as thev1beta3type no longer compiles. A cluster on Flux older than 2.10 needs thev1beta3object, which kure still registers (sov1beta3manifests keep parsing) but no longer wraps. Build it with the generic constructor:kubernetes.Create[notificationv1beta3.Provider](name, namespace), withnotificationv1beta3importinggithub.com/fluxcd/notification-controller/api/v1beta3. Then assign its fields directly.SetProviderIntervalis removed. Thev1Provider has nospec.interval, andv1beta3already ignored it. Drop the call.v1drops fields, and the result is a compile error in one case and a runtime failure in the other:- A Go assignment to
Alert.Spec.SummaryorProvider.Spec.Proxyno longer compiles. UseAddAlertEventMetadata(alert, "summary", …)andProvider.Spec.ProxySecretRef. - Secret content compiles but fails at runtime. notification-controller v1.10 rejects a
proxykey in thespec.secretRefSecret: put the proxy URL under the keyaddressin a separate Secret, reference that Secret fromspec.proxySecretRef, and deleteproxyfrom thespec.secretRefSecret. A commit-status Provider (github,gitlab,gitea,bitbucket,bitbucketserver,azuredevops) rejects TLS data (ca.crt,tls.crt,tls.key, or the legacycaFile,certFile,keyFile) in thespec.secretRefSecret, and every other Provider type ignores it there: move it to a Secret referenced fromspec.certSecretRef. An Azure Event Hub Provider’s static JWTtokenis no longer accepted: remove it and authenticate withspec.serviceAccountName(object identity), or another method the upstream Provider documentation lists.
- A Go assignment to
- Changed Flux Go types around the source and chart template:
OCIRepositorySpec.Intervalis now*metav1.DurationandHelmChartTemplateSpec.SourceRefis now*helmv2.CrossNamespaceObjectReference: take the address when assigning.HelmChartTemplateSpecnow embedssourcev1.OCIRepositorySpec, which ownsIntervalandVerify. A composite literal namingIntervalorVerifydirectly no longer compiles: nest them asOCIRepositorySpec: sourcev1.OCIRepositorySpec{Interval: &d, Verify: …}, or assign the promoted field (chart.Spec.Interval = &d) after construction.helmv2.HelmChartTemplateVerificationis removed:Verifytakes*sourcev1.OCIRepositoryVerification.- Removed methods and their replacements:
HelmChartTemplate.GetInterval: useHelmRelease.GetTemplateInterval.HelmRelease.GetHelmChartNameandHelmChartTemplate.GetNamespace: use theNameandNamespaceofHelmRelease.GetHelmChartTemplateReference(). It returns nil when the release sets nospec.chart, so check it first.HelmRelease.GetHelmChartReferenceis not a replacement: it readsspec.chartRefonly.HelmReleaseStatus.GetHelmChart: useHelmReleaseStatus.GetHelmChartReference. It returns nil when the status names no chart.
- A
fluxv1.Dependencypassed toAddResourceSetDependencywithReadyExprset must also setReady: true. flux-operator v0.62’s CRD rejectsreadyExprwithoutready; before, the expression was simply not evaluated. Alternatively, dropReadyExpr. - A
meta.KubeConfigReferencewithConfigMapRef, passed toSetKustomizationKubeConfigorSetHelmReleaseKubeConfig, now authenticates through object identity. Rename the ConfigMap’saudienceskey tocredential.auth.fluxcd.io/audiences.
Example
Alert keeps three append helpers: AddAlertEventSource, AddAlertInclusion and
AddAlertExclusion. AddAlertEventMetadata is a map setter. It replaces the value of an existing
key.
Image Automation
The three kinds of image.toolkit.fluxcd.io/v1 each have a constructor:
CreateImageRepository and CreateImagePolicy (types from
github.com/fluxcd/image-reflector-controller/api) and CreateImageUpdateAutomation
(type from github.com/fluxcd/image-automation-controller/api). All three are
namespaced and carry identity only.
ImageRepository and ImagePolicy have no setters: every field of their specs is
assigned directly on the upstream type. ImageUpdateAutomation keeps the pointer
setters SetImageUpdateAutomationGitSpec, SetImageUpdateAutomationPolicySelector
and SetImageUpdateAutomationUpdateStrategy.
Flux Operator
Extended Resource Types
ExternalArtifact
Allows a Flux source artifact produced outside the cluster to be referenced by other Flux resources.
ArtifactGenerator
Provided by the optional source-watcher component. Assembles a new artifact by copying files from one or more source artifacts.
Related Packages
- stack/fluxcd — high-level Flux workflow engine
- stack — domain model that produces Flux resources