Documentation
¶
Overview ¶
Package layout is where a writer's files go in a GitOps repository and what one write changes there: every writer (a manager, a CLI) owns one directory under the directory a Flux Kustomization builds from, holding one file per object and a Kustomize file that lists them. A parent Kustomize file lists the writer's directory when present; otherwise Flux generates one. All three Kustomize filenames are recognized.
Build decides a write against the base branch — which files are added, updated, removed or already there — encrypts new secret files for the repository's .sops.yaml recipients and never re-encrypts one that exists, unless the caller asks for it by path (ReplaceSecrets). A secret file another party encrypted lands as given once checked against the repository's recipients for its path (Encrypted). The plan's Change is what forge.Open lands with the caller's identity.
Index ¶
- Constants
- Variables
- func CheckObjectFile(content []byte, obj *unstructured.Unstructured) error
- func DefiningFiles(ctx context.Context, r RevisionReader, repo provenance.Repository, ...) ([]string, error)
- func ObjectFiles(dir Directory, change manifest.Change, ...) (write map[string][]byte, remove []string, err error)
- func Resources(raw []byte) ([]string, error)
- func WithResources(raw []byte, resources []string) ([]byte, error)
- type Action
- type Cluster
- type ClusterPlan
- type ClusterReader
- type Directory
- type File
- type Option
- type Plan
- type RevisionReader
- type SecretError
Constants ¶
const ( // OrganizationsDirectory holds the organizations under a root. OrganizationsDirectory = "organizations" // WorkloadClustersDirectory holds an organization's clusters. WorkloadClustersDirectory = "workload-clusters" )
const KustomizationFile = "kustomization.yaml"
KustomizationFile is the default filename for newly created Kustomize files.
const SOPSConfigFile = ".sops.yaml"
SOPSConfigFile is the repository's encryption rules, read at its root.
Variables ¶
var ErrDuplicateFile = errors.New("two objects map to one file")
ErrDuplicateFile is returned when two objects of a change map to the same file.
var ErrEncryptedFile = errors.New("encrypted file does not fit its path")
ErrEncryptedFile refuses a ready-encrypted file that does not fit its path: its age recipients are not exactly those the repository's .sops.yaml names for the path, or its Secret is not the one the path is named after.
var ErrMultipleKustomizationFiles = errors.New("multiple kustomization files")
ErrMultipleKustomizationFiles indicates an ambiguous Kustomize directory.
var ErrNoOrganization = errors.New("no organization directory")
ErrNoOrganization: the root has no directory for the organization.
var ErrNotSecret = errors.New("only v1 Secrets may be written to a secret file")
ErrNotSecret refuses a written file at a secret file's path that holds anything but v1 Secrets: it would be encrypted, and since Build leaves an existing secret file as it is, never updated again.
var ErrObjectFileMismatch = errors.New("the file does not hold one matching object")
ErrObjectFileMismatch refuses a file without one explicitly matching object.
var ErrUnsupportedKustomization = errors.New("Kustomization settings are unsupported for direct-object authorization")
ErrUnsupportedKustomization refuses settings outside the resource-only Kustomization subset supported by direct-object authorization.
Functions ¶
func CheckObjectFile ¶ added in v0.14.0
func CheckObjectFile(content []byte, obj *unstructured.Unstructured) error
CheckObjectFile requires one document with obj's API group, kind, name and namespace. An encrypted, substituted or incomplete identity is refused.
func DefiningFiles ¶ added in v0.14.0
func DefiningFiles(ctx context.Context, r RevisionReader, repo provenance.Repository, ref, dir string, obj *unstructured.Unstructured) ([]string, error)
DefiningFiles returns the files under dir at ref that define obj or may define it, sorted by path; none when no file does. Pass a commit SHA as ref (forge.HeadReader) so the list and every read see one revision. It is the check before an object is deleted once the change removing its file merged: Flux applies the object again while any of these files is there.
A file defines obj when one of its YAML or JSON documents, or an item of a List, has obj's API group, kind and name, and obj's namespace or none (a kustomization or the GitOps controller can set it). A document whose apiVersion, kind, name or namespace is SOPS-encrypted or holds a ${substitution} may define it. A kustomization file may define it when it renames, patches or generates objects, loads entries from outside dir, or does not parse. Every other file that does not parse defines nothing, as kustomize cannot build it.
func ObjectFiles ¶ added in v0.14.0
func ObjectFiles(dir Directory, change manifest.Change, name func(*unstructured.Unstructured) string) (write map[string][]byte, remove []string, err error)
ObjectFiles turns change into the files Build takes: write holds each object of change.Apply as manifest.Desired renders it, at its file in dir, and remove holds the file of each object of change.Remove. name returns the name an object's file is named after, which dir.ObjectFile turns into the path (so a Secret still lands in a secret file); nil names each file after its object's name.
func Resources ¶
Resources is the resources list of a kustomization.yaml, as Kustomize reads it: the last resources key where the file repeats it. nil content, an empty file and a file without the list have none.
func WithResources ¶
WithResources is the kustomization.yaml with its resources list replaced by resources, every other key and comment kept; an entry that stays keeps its node and so its comments; a new file for nil content. Where the file repeats the resources key, the last one, which Kustomize reads, is replaced and the others stay as they are.
Types ¶
type Cluster ¶ added in v0.11.0
type Cluster struct {
// Location is the root: the repository, branch and directory the
// Organization's Kustomization builds from.
provenance.Location
// Owner is the Organization's Kustomization; the cluster's Kustomization
// takes its source, service account, interval, timeout and keys.
Owner flux.Kustomization
// Installation names the cluster's Kustomization,
// <installation>-clusters-<cluster>.
Installation string
Organization string
Name string
}
Cluster is a new workload cluster's place in the repository that owns its Organization.
func NewCluster ¶ added in v0.11.0
NewCluster places the cluster name of organization on installation, under owner: the target of the Organization object, as a flux.Resolver resolves it. A target whose controller is not a Flux Kustomization is refused with flux.ErrUnknownObject.
func (Cluster) Directory ¶ added in v0.11.0
Directory is the cluster's own directory, <cluster>/ under the organization's workload-clusters/; its ObjectFile names the object files.
func (Cluster) Kustomization ¶ added in v0.11.0
Kustomization is the cluster's Flux Kustomization, namespace/name, next to the Organization's.
func (Cluster) KustomizationPath ¶ added in v0.11.0
KustomizationPath is the file of the cluster's Flux Kustomization.
func (Cluster) OrganizationPath ¶ added in v0.11.0
OrganizationPath is the organization's directory, repository-relative.
type ClusterPlan ¶ added in v0.11.0
type ClusterPlan struct {
*Plan
// Kustomization is the cluster's Flux Kustomization, namespace/name.
Kustomization string
// Prune is the Organization's Kustomization's spec.prune. Without it a
// removal's merge leaves the cluster's Kustomization on the installation:
// deleting it is the live step, and Flux then removes the cluster.
Prune bool
}
ClusterPlan is the change set of a cluster's add or removal.
func BuildCluster ¶ added in v0.11.0
func BuildCluster(ctx context.Context, r ClusterReader, c Cluster, write map[string][]byte) (*ClusterPlan, error)
BuildCluster decides a new cluster's files against the base branch: the objects in write (paths inside Directory, named by its ObjectFile, a new secret file encrypted as Build does), the directory's kustomization.yaml, the cluster's Flux Kustomization and its entry in the organization's workload-clusters/kustomization.yaml, created when absent. A root without the organization's directory is ErrNoOrganization, naming the path looked for. A re-run whose files are on the base changes nothing.
func RemoveCluster ¶ added in v0.11.0
func RemoveCluster(ctx context.Context, r ClusterReader, c Cluster) (*ClusterPlan, error)
RemoveCluster decides a cluster's removal against the base branch: every file under its directory, its Flux Kustomization and the entry in the organization's workload-clusters/kustomization.yaml; what the base does not carry is no change.
type ClusterReader ¶ added in v0.11.0
ClusterReader is what a cluster's plan reads of the base branch: files, and the files under a directory.
type Directory ¶
type Directory struct {
provenance.Location
// Name is the writer's directory name, one path segment
// ("cluster-manager", "model-manager").
Name string
}
Directory is a writer's directory: Name under the directory of Location, on its repository and branch.
func (Directory) FileOf ¶ added in v0.14.0
func (d Directory) FileOf(obj *unstructured.Unstructured, name func(*unstructured.Unstructured) string) (string, error)
FileOf is the path of obj's file in the directory, as ObjectFiles names it: dir.ObjectFile of obj's kind and the name name returns, obj's own name when name is nil.
func (Directory) ObjectFile ¶
ObjectFile is the path of an object's file in the directory: named after the object, a Secret in a secret file of its own (sopsenc's naming convention), so it is encrypted and never written in plaintext.
type File ¶
File is one file of a plan. Content is the new content of an added or updated plain file, for a dry run to show; a secret file's content is never carried.
type Option ¶ added in v0.12.0
type Option func(*options)
Option changes how Build decides a write.
func Encrypted ¶ added in v0.12.0
Encrypted makes Build take the named files as already encrypted, by a party that held the value when the caller does not: each is one SOPS-encrypted v1 Secret (sopsenc.InspectSecret) at a secret file named after it (Directory.ObjectFile), encrypted for exactly the recipients of the repository's .sops.yaml for its path. It lands byte for byte, never re-encrypted. Like any secret file it is left as it is where the base carries it, unless ReplaceSecrets names it too.
func ReplaceSecrets ¶ added in v0.12.0
ReplaceSecrets makes Build replace the named secret files where the base carries them: the written content is encrypted for the recipients of the repository's .sops.yaml under the same path and lands as an Update, the old encrypted content gone. Without it an existing secret file is left as it is. Every path must be one of the written files and a secret file. A replaced file is always an Update: its old content is never decrypted to compare.
func WithoutTransformations ¶ added in v0.14.0
func WithoutTransformations() Option
WithoutTransformations requires both the writer's and parent's Kustomization to contain only resource entries and document metadata.
type Plan ¶
type Plan struct {
Directory Directory
// Files are every file the write decided on, sorted by path — unchanged
// ones included, so a dry run shows the whole directory the write owns.
Files []File
// contains filtered or unexported fields
}
Plan is the change set of one write in a directory.
func Build ¶
func Build(ctx context.Context, r forge.Reader, dir Directory, write map[string][]byte, remove []string, opts ...Option) (*Plan, error)
Build decides a write in dir against the base branch: write are the files to land by path, remove the paths to take away (a path the base does not carry is no change, reported as Missing); every path lies inside the directory. A plain file is added, updated or unchanged; a new secret file is encrypted for the recipients of the repository's .sops.yaml, one that exists is left as it is unless ReplaceSecrets names it. The directory's kustomization file lists every file it keeps and is removed with the last one; the parent's kustomization file, where there is one, lists the directory while it has files. A kustomization file is read as Kustomize reads it: where it repeats the resources key, the last one counts and is the one edited, and the parent's deprecated bases list counts as well. Both are edited on their YAML nodes: comments and every other key stay. Read errors from r are returned as they are (forge.AuthError included).
type RevisionReader ¶ added in v0.14.0
RevisionReader lists and reads a repository's files at one revision.
type SecretError ¶
SecretError refuses secret files the repository cannot take encrypted: no .sops.yaml, one that does not parse, or no creation rule with recipients for their paths. They are never written in plaintext; the caller names its way out.
func (*SecretError) Error ¶
func (e *SecretError) Error() string