Documentation
¶
Overview ¶
Package commit plans Kubernetes object changes and opens pull requests in their GitOps repositories with the caller's identity.
A Committer resolves where each object's file lives (target.Resolver), asks the cluster whether it accepts the change from the caller (dryrun.Check), renders and plans the files in the writer's directory (layout), and opens a pull request after checking for branch-prefix conflicts (forge.OpenOne). Refusals are *Error; transport and resolver failures preserve their causes.
Index ¶
Constants ¶
const ( // ReasonNotGitOpsApplied: the object's source is unconfirmed or rendered // by a release, or no GitOps location was found or supplied. ReasonNotGitOpsApplied metav1.StatusReason = "NotGitOpsApplied" // ReasonLocationConflict: the location the request names is not the one // the object's controller applies, or the parts land in two repositories // or branches. ReasonLocationConflict metav1.StatusReason = "LocationConflict" // ReasonObjectFileMismatch: the object is applied from another file, or // the expected file does not hold one explicitly matching object. ReasonObjectFileMismatch metav1.StatusReason = "ObjectFileMismatch" // ReasonKeptByController: the object's file left Git and its controller // does not prune it; no commit removes it from the cluster. ReasonKeptByController metav1.StatusReason = "KeptByController" // ReasonRepositoryUnreadable: the caller's identity cannot read the // repository on the Git host. ReasonRepositoryUnreadable metav1.StatusReason = "RepositoryUnreadable" // ReasonPullRequestOpen: the branch prefix already has an open pull request; // nothing was written. ReasonPullRequestOpen metav1.StatusReason = "PullRequestOpen" // ReasonPullRequestClosed: an older pull request for the branch prefix // competed with this call's pull request, which was successfully closed. ReasonPullRequestClosed metav1.StatusReason = "PullRequestClosed" // ReasonPullRequestCloseFailed: closing this call's competing pull request // failed. Its state must be checked before opening another one. ReasonPullRequestCloseFailed metav1.StatusReason = "PullRequestCloseFailed" )
Custom GitOps refusal reasons supplement metav1.StatusReason values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Committer ¶ added in v0.14.0
type Committer struct {
// contains filtered or unexported fields
}
Committer plans and opens pull requests for Kubernetes object changes.
func (*Committer) Commit ¶ added in v0.14.0
Commit commits request: it resolves every part's location, refuses parts that do not land in one repository and branch, checks that the caller can read the repository, dry-runs every part on the cluster as the caller, plans the files and refuses a plan that would change what the writer does not own, then opens the pull request.
A part's location is the one the resolver finds; the named Location only when nothing applies the object (target.ErrNotApplied, a controller that is not found, or a namespace moved by spec.targetNamespace). An object the resolver cannot confirm, or one a release renders, is refused even with a named location.
Refusals are *Error. On an error after the pull request was opened, the Result carries it.
type Config ¶ added in v0.14.0
type Config struct {
// Resolver finds where each object's file lives.
Resolver target.Resolver
// Cluster is the caller's dynamic client of the cluster the objects live
// on, and Mapper maps their kinds to resources.
Cluster dynamic.Interface
Mapper meta.RESTMapper
// Forge is the Git host with the caller's identity.
Forge Forge
// FieldManager names the dry run's server-side apply.
FieldManager string
}
Config supplies a Committer's clients, resolver and apply field manager.
Cluster and Forge must act as the same caller: the dry run proves that the cluster accepts the change from the identity Cluster carries, and says nothing about a commit made with another one. Resolver normally reads with the manager's own ServiceAccount (target/flux).
type Error ¶ added in v0.14.0
type Error struct {
ErrStatus metav1.Status
// PullRequest is the existing open pull request for ReasonPullRequestOpen,
// ReasonPullRequestClosed and ReasonPullRequestCloseFailed.
PullRequest forge.PullRequest
Err error
}
Error is a refusal of Commit, as a Kubernetes API status: apierrors.ReasonForError and apierrors.IsForbidden read it. It unwraps to its cause: forge.AuthError for a Git host's refusal, dryrun.ErrRefused for the cluster's.
type Forge ¶ added in v0.14.0
type Forge interface {
forge.OneRemote
forge.Reader
forge.HeadReader
forge.RepositoryAccess
}
Forge is the Git host used to read, plan and open a pull request.
type Part ¶ added in v0.14.0
type Part struct {
// Object is the live object the part changes, read from the cluster:
// its file is where the commit goes. Namespace is set instead for new
// objects: the directory that applies the namespace.
Object *unstructured.Unstructured
Namespace string
// Location is where the commit goes when no GitOps controller applies
// Object or Namespace from a file; zero when the caller names none. It
// is refused when a controller applies them from another location.
// A named fallback must be trusted configuration for a controller that
// does not transform submitted objects.
Location provenance.Location
// Directory is the writer's directory name under the location, one path
// segment ("agent-manager").
Directory string
// Change is the objects to write and remove. Its Prune is set from the
// resolved controller.
Change manifest.Change
// FileName returns one path segment before the kind-specific suffix;
// nil uses the object's name. It must be stable for each object.
FileName func(*unstructured.Unstructured) string
}
Part groups manifest changes under one resolved target and writer directory.
type PartResult ¶ added in v0.14.0
type PartResult struct {
// Target is where the part goes; its Controller is zero when the
// request named the location.
Target target.Target
Plan *layout.Plan
}
PartResult is one part's location and plan.
type Request ¶
type Request struct {
Parts []Part
// BranchPrefix is the stable branch-name prefix without underscores used
// to find competing pull requests. Requests that must not overlap must
// use the same prefix.
BranchPrefix string
Title string
Body string
// DryRun resolves, checks and plans everything and writes nothing to
// Git. The repository must be readable all the same.
DryRun bool
}
Request groups parts for one pull request against one repository and branch.
type Result ¶ added in v0.14.0
type Result struct {
// Parts are the request's parts in order.
Parts []PartResult
// PullRequest is the opened or existing pull request; zero on a dry run
// and when no part changes a file. After a competing creation, it is this
// call's pull request; Error.PullRequest identifies the older competitor.
PullRequest forge.PullRequest
}
Result contains the planned files and any pull request opened or found.