Documentation
¶
Overview ¶
Package flux resolves the commit target of an object a Flux Kustomization applies from a GitRepository, and holds the Flux objects and names the resolution reads. Resolver implements target.Resolver: NewResolver for objects on the cluster Flux runs on, NewRemoteResolver for objects on a cluster Flux applies to through a Kustomization's spec.kubeConfig.
Index ¶
Constants ¶
const ( LabelName = "kustomize.toolkit.fluxcd.io/name" LabelNamespace = "kustomize.toolkit.fluxcd.io/namespace" )
The labels kustomize-controller sets on every object a Kustomization applies.
const ( LabelHelmReleaseName = "helm.toolkit.fluxcd.io/name" LabelHelmReleaseNamespace = "helm.toolkit.fluxcd.io/namespace" )
The labels helm-controller sets on every object a HelmRelease renders.
const KindGitRepository = "GitRepository"
KindGitRepository is the only Flux source kind a commit can target.
Variables ¶
var ( // ErrNotFound is returned when the named Kustomization or the // GitRepository it references is not among the Flux objects. ErrNotFound = errors.New("flux object not found") // ErrNotGit is returned when a Kustomization builds from a source that is // not a GitRepository; there is no repository to commit to. ErrNotGit = errors.New("kustomization source is not a GitRepository") )
var ( KustomizationGVR = schema.GroupVersionResource{Group: "kustomize.toolkit.fluxcd.io", Version: "v1", Resource: "kustomizations"} GitRepositoryGVR = schema.GroupVersionResource{Group: "source.toolkit.fluxcd.io", Version: "v1", Resource: "gitrepositories"} )
The Flux and core resources the resolver reads.
var ErrUnknownObject = errors.New("not a flux kustomization or git repository")
ErrUnknownObject is returned by Add for an object that is neither a Flux Kustomization nor a Flux GitRepository, and by KustomizationOf for a controller that is not a Flux Kustomization.
Functions ¶
This section is empty.
Types ¶
type Decryption ¶
Decryption holds the provider, key Secret reference and KMS identity from a Kustomization's spec.decryption.
type GitRepository ¶
type GitRepository struct {
Name string
Namespace string
URL string
// Branch is spec.ref.branch; empty when the source follows something else.
Branch string
}
GitRepository is the part of a Flux GitRepository the resolution reads.
type Kustomization ¶
type Kustomization struct {
Name string
Namespace string
SourceRef SourceRef
// Path is spec.path as Flux carries it ("./management-clusters/x").
Path string
// ServiceAccountName, Interval and Timeout are spec.serviceAccountName,
// spec.interval and spec.timeout as Flux carries them ("1m"); empty when
// unset.
ServiceAccountName string
Interval string
Timeout string
// Prune is spec.prune: whether Flux removes what leaves the directory.
Prune bool
// Decryption is spec.decryption, nil when no decryption provider is set.
Decryption *Decryption
}
Kustomization is the part of a Flux Kustomization the resolution reads.
func KustomizationOf ¶
func KustomizationOf(controller target.Controller) (Kustomization, error)
KustomizationOf returns the Flux Kustomization a target's controller is, as a Resolver from this package read it. ErrUnknownObject when the controller is not a Flux Kustomization.
type Objects ¶
type Objects struct {
Kustomizations []Kustomization
GitRepositories []GitRepository
}
Objects is a cluster's Flux objects as the caller read them.
func (*Objects) Add ¶
Add records one decoded Kubernetes object (the shape of `kubectl get -o json`, or an unstructured object's content) as a Kustomization or GitRepository. Any other apiVersion/kind is an error: the caller hands over the Flux objects it read, nothing else.
func (Objects) FindKustomization ¶
func (f Objects) FindKustomization(namespace, name string) (Kustomization, bool)
FindKustomization returns the Kustomization namespace/name, and whether the Flux objects hold it.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver is the target.Resolver for objects a Flux Kustomization applies from a GitRepository.
Labels can be set by whoever may write an object, so they alone are no proof. An object counts as applied, and its labels as its target, only when the Kustomization the labels name lists the object in its inventory (status.inventory): forged labels yield target.ErrNotApplied, never another target. A Kustomization that is gone (target.ErrControllerNotFound) or has recorded no inventory yet cannot confirm the labels: target.ErrUnconfirmed, which is a target.ErrNotApplied. A Kustomization that does not list the object and does not prune it, by spec.prune or the object's kustomize.toolkit.fluxcd.io/prune: disabled, kept it on the cluster: target.ErrNotPruned. An object a HelmRelease renders has no file of its own: target.ErrRendered.
An inventory names no cluster, so the Kustomization must also apply to the cluster the object lives on, whatever its inventory lists. For NewResolver that is the cluster Flux runs on: a Kustomization that applies to another cluster (spec.kubeConfig) does not apply the object. For NewRemoteResolver it is the cluster that the caller's kubeconfig Secret names: only a Kustomization that applies through that Secret does.
func NewRemoteResolver ¶
func NewRemoteResolver(kustomizations, objects dynamic.Interface, kubeConfig types.NamespacedName) *Resolver
NewRemoteResolver returns the resolver for objects on another cluster, which Flux applies to through a Kustomization's spec.kubeConfig. It reads the Kustomization and its GitRepository with kustomizations, on the cluster Flux runs on, and the Namespace of ForNamespace with objects, on the objects' cluster; both normally use the manager's ServiceAccount.
kubeConfig names the objects' cluster as the Kustomizations name it: the kubeconfig Secret, by namespace and name. A Kustomization counts only when it lives in that namespace and its spec.kubeConfig.secretRef names that Secret. One without spec.kubeConfig, or one that names another Secret or a ConfigMap (spec.kubeConfig.configMapRef), does not apply the object: target.ErrNotApplied. The key in the Secret (secretRef.key) is not compared: a Secret that holds the kubeconfigs of two clusters names both.
func NewResolver ¶
NewResolver returns the resolver that reads the Namespace, the Kustomization and its GitRepository with client: the manager's ServiceAccount, on the cluster Flux runs on.
func (*Resolver) ForNamespace ¶
ForNamespace implements Resolver: the target of the Namespace object itself, refused when its Kustomization moves objects to another namespace.
func (*Resolver) ForObject ¶
func (f *Resolver) ForObject(ctx context.Context, obj *unstructured.Unstructured) (target.Target, error)
ForObject implements target.Resolver.