{"modulePath":"github.com/giantswarm/gitops-commit","version":"v0.11.10","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package layout\n\nPackage 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 its own kustomization.yaml that lists them, and the parent's kustomization.yaml, where there is one, lists the directory. Flux then builds the directory whether the parent has a kustomization.yaml (the entry is added there) or not (Flux generates one that includes every directory with a kustomization.yaml).\n\nBuild 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. The plan's Change is what commit.Open lands as the person.\n\n## Constants\n\n```go\nconst (\n\t// OrganizationsDirectory holds the organizations under a root.\n\tOrganizationsDirectory = \"organizations\"\n\t// WorkloadClustersDirectory holds an organization's clusters.\n\tWorkloadClustersDirectory = \"workload-clusters\"\n)\n```\n\n```go\nconst KustomizationFile = \"kustomization.yaml\"\n```\nKustomizationFile lists a directory's files for kustomize.\n\n```go\nconst SOPSConfigFile = \".sops.yaml\"\n```\nSOPSConfigFile is the repository's encryption rules, read at its root.\n\n## Variables\n\n```go\nvar (\n\t// ErrNotReconciled: the Organization carries no Flux Kustomization, so\n\t// no repository owns it.\n\tErrNotReconciled = errors.New(\"not reconciled by a Flux Kustomization\")\n\t// ErrNoOrganization: the root has no directory for the organization.\n\tErrNoOrganization = errors.New(\"no organization directory\")\n)\n```\n\n## Functions\n\n```go\nfunc Resources(raw []byte) ([]string, error)\n```\nResources is the resources list of a kustomization.yaml; nil content, an empty file and a file without the list have none.\n\n```go\nfunc WithResources(raw []byte, resources []string) ([]byte, error)\n```\nWithResources 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.\n\n## Types\n\n```go\ntype Action string\n```\nAction is what a write does to one file.\n\n```go\nconst (\n\tAdd       Action = \"add\"\n\tUpdate    Action = \"update\"\n\tRemove    Action = \"remove\"\n\tUnchanged Action = \"unchanged\"\n)\n```\nThe actions of a plan's files.\n\n```go\ntype Cluster struct {\n\t// Location is the root: the repository, branch and directory the\n\t// Organization's Kustomization builds from.\n\tprovenance.Location\n\t// Owner is the Organization's Kustomization; the cluster's Kustomization\n\t// takes its source, service account, interval, timeout and keys.\n\tOwner provenance.Kustomization\n\t// Installation names the cluster's Kustomization,\n\t// \u003cinstallation\u003e-clusters-\u003ccluster\u003e.\n\tInstallation string\n\tOrganization string\n\tName         string\n}\n```\nCluster is a new workload cluster's place in the repository that owns its Organization.\n\n```go\nfunc NewCluster(flux provenance.Flux, ownerNamespace, ownerName, installation, organization, name string) (Cluster, error)\n```\nNewCluster places the cluster name of organization on installation: the Organization is reconciled by the Kustomization ownerNamespace/ownerName (its kustomize.toolkit.fluxcd.io labels) among the Flux objects. An Organization without one is ErrNotReconciled; one whose Kustomization does not build from a GitHub branch is refused with Resolve's error.\n\n```go\nfunc (c Cluster) Directory() Directory\n```\nDirectory is the cluster's own directory, \\\u003ccluster\u003e/ under the organization's workload-clusters/; its ObjectFile names the object files.\n\n```go\nfunc (c Cluster) Kustomization() string\n```\nKustomization is the cluster's Flux Kustomization, namespace/name, next to the Organization's.\n\n```go\nfunc (c Cluster) KustomizationPath() string\n```\nKustomizationPath is the file of the cluster's Flux Kustomization.\n\n```go\nfunc (c Cluster) OrganizationPath() string\n```\nOrganizationPath is the organization's directory, repository-relative.\n\n```go\ntype ClusterPlan struct {\n\t*Plan\n\t// Kustomization is the cluster's Flux Kustomization, namespace/name.\n\tKustomization string\n\t// Prune is the Organization's Kustomization's spec.prune. Without it a\n\t// removal's merge leaves the cluster's Kustomization on the installation:\n\t// deleting it is the live step, and Flux then removes the cluster.\n\tPrune bool\n}\n```\nClusterPlan is the change set of a cluster's add or removal.\n\n```go\nfunc BuildCluster(ctx context.Context, r ClusterReader, c Cluster, write map[string][]byte) (*ClusterPlan, error)\n```\nBuildCluster 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.\n\n```go\nfunc RemoveCluster(ctx context.Context, r ClusterReader, c Cluster) (*ClusterPlan, error)\n```\nRemoveCluster 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.\n\n```go\ntype ClusterReader interface {\n\tcommit.Reader\n\tcommit.Lister\n}\n```\nClusterReader is what a cluster's plan reads of the base branch: files, and the files under a directory.\n\n```go\ntype Directory struct {\n\tprovenance.Location\n\t// Name is the writer's directory name, one path segment\n\t// (\"cluster-manager\", \"model-manager\").\n\tName string\n}\n```\nDirectory is a writer's directory: Name under the directory of Location, on its repository and branch.\n\n```go\nfunc (d Directory) ObjectFile(kind, name string) string\n```\nObjectFile 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.\n\n```go\nfunc (d Directory) Path() string\n```\nPath is the directory, repository-relative.\n\n```go\ntype File struct {\n\tPath    string\n\tAction  Action\n\tContent []byte\n}\n```\nFile 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.\n\n```go\ntype Plan struct {\n\tDirectory Directory\n\t// Files are every file the write decided on, sorted by path — unchanged\n\t// ones included, so a dry run shows the whole directory the write owns.\n\tFiles []File\n\t// contains filtered or unexported fields\n}\n```\nPlan is the change set of one write in a directory.\n\n```go\nfunc Build(ctx context.Context, r commit.Reader, dir Directory, write map[string][]byte, remove []string) (*Plan, error)\n```\nBuild 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); 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. The directory's kustomization.yaml lists every file it keeps and is removed with the last one; the parent's kustomization.yaml, where there is one, lists the directory while it has files. Both are edited on their YAML nodes: comments and every other key stay. Read errors from r are returned as they are (commit.AuthError included).\n\n```go\nfunc (p *Plan) Change() commit.Change\n```\nChange is the plan as commit.Open takes it: the written files with their content, the removed ones nil.\n\n```go\nfunc (p *Plan) Changed() bool\n```\nChanged reports whether the plan writes or removes anything.\n\n```go\ntype SecretError struct {\n\tPaths  []string\n\tReason string\n}\n```\nSecretError 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.\n\n```go\nfunc (e *SecretError) Error() string\n```\n\n","path":"github.com/giantswarm/gitops-commit/layout","name":"layout","synopsis":"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 its own kustomization.yaml that lists them, and the parent's kustomization.yaml, where there is one, lists the directory.","isRedistributable":true}
