Documentation
¶
Overview ¶
Package target answers where a commit about a live object goes: the repository, branch and directory its file lives in (an edit), or where a new object in a namespace goes. A Resolver reads the GitOps objects on the cluster with the clients the caller passes in; it holds no credentials of its own, and the caller cannot name a repository.
Flux is the only implementation: NewFlux for objects on the cluster Flux runs on, NewFluxRemote for objects on a cluster Flux applies to through a Kustomization's spec.kubeConfig. Another GitOps tool can be added as another Resolver without a change in the callers.
Index ¶
Constants ¶
const ( LabelKustomizeName = "kustomize.toolkit.fluxcd.io/name" LabelKustomizeNamespace = "kustomize.toolkit.fluxcd.io/namespace" )
The labels kustomize-controller sets on every object a Kustomization applies.
Variables ¶
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 Flux resolver reads.
var ErrNotApplied = errors.New("not GitOps-applied")
ErrNotApplied is returned for an object, or a namespace, that no GitOps tool applies from a file: it has no target. The message says why.
var ErrTargetNamespace = errors.New("kustomization moves objects to another namespace")
ErrTargetNamespace is returned for a namespace whose applying Kustomization sets spec.targetNamespace to another namespace: a new object in its directory would land in that other namespace.
var ErrUnconfirmed = fmt.Errorf("%w: labels unconfirmed", ErrNotApplied)
ErrUnconfirmed is returned when an object's labels name a GitOps object that cannot confirm them: it is gone, it has recorded no inventory yet, or the object's inventory id is ambiguous. It is an ErrNotApplied: there is no target. A caller that refuses a live write on an object GitOps may still apply can tell it apart with errors.Is.
Functions ¶
This section is empty.
Types ¶
type Flux ¶
type Flux struct {
// contains filtered or unexported fields
}
Flux is the 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 ErrNotApplied, never another target. A Kustomization that is gone or has recorded no inventory yet cannot confirm the labels: ErrUnconfirmed, which is an ErrNotApplied. An object a HelmRelease renders has no file of its own and is not applied from a file either.
An inventory names no cluster, so the Kustomization must also apply to the cluster the object lives on, whatever its inventory lists. For NewFlux that is the cluster Flux runs on: a Kustomization that applies to another cluster (spec.kubeConfig) does not apply the object. For NewFluxRemote it is the cluster that the caller's kubeconfig Secret names: only a Kustomization that applies through that Secret does.
func NewFlux ¶
NewFlux returns the Flux resolver that reads the Namespace, the Kustomization and its GitRepository with client: the caller's own, on the cluster Flux runs on.
func NewFluxRemote ¶
func NewFluxRemote(kustomizations, objects dynamic.Interface, kubeConfig types.NamespacedName) *Flux
NewFluxRemote returns the Flux 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 are the caller's own clients.
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: ErrNotApplied. The key in the Secret (secretRef.key) is not compared: a Secret that holds the kubeconfigs of two clusters names both.
func (*Flux) ForNamespace ¶
ForNamespace implements Resolver: the target of the Namespace object itself, refused when its Kustomization moves objects to another namespace.
func (*Flux) ForObject ¶
func (f *Flux) ForObject(ctx context.Context, obj *unstructured.Unstructured) (Target, error)
ForObject implements Resolver.
type Resolver ¶
type Resolver interface {
// ForObject returns the target of obj, an object read from the cluster
// the resolver reads objects on: where its file lives. ErrNotApplied
// when no GitOps tool applies obj from a file.
ForObject(ctx context.Context, obj *unstructured.Unstructured) (Target, error)
// ForNamespace returns the target of a new object in namespace: the
// directory that applies the namespace. ErrNotApplied when no GitOps
// tool applies the namespace from a file.
ForNamespace(ctx context.Context, namespace string) (Target, error)
}
Resolver returns the commit target of a live object or of a new object.
type Target ¶
type Target struct {
// Location is the repository, branch and directory the files live in.
provenance.Location
// Kustomization is the Flux Kustomization that applies the directory.
Kustomization provenance.Kustomization
}
Target is where a commit goes and what lands it after the merge.