Documentation
¶
Overview ¶
Package commit lands Kubernetes object changes in the GitOps repository that applies them, as a pull request 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 one pull request per object (forge.OpenOne). Domain refusals are *Error; transport and resolver failures preserve their causes.
Index ¶
Constants ¶
const ( // ReasonNotGitOpsApplied: no GitOps controller applies the object from a // file, or none can confirm that it does, and the request names no // location. 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" // ReasonOutsideDirectory: the object is applied from a file outside the // writer's directory, or its file does not hold one explicitly matching object. ReasonOutsideDirectory metav1.StatusReason = "OutsideDirectory" // 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" // ReasonRepositoryUnreachable: the caller's identity cannot read the // repository on the Git host. ReasonRepositoryUnreachable metav1.StatusReason = "RepositoryUnreachable" // ReasonPullRequestOpen: the object already has an open pull request; // nothing was written. ReasonPullRequestOpen metav1.StatusReason = "PullRequestOpen" // ReasonPullRequestClosed: a pull request for the object opened while // this one was, so this one was closed again. ReasonPullRequestClosed metav1.StatusReason = "PullRequestClosed" )
The reasons of the refusals Commit returns besides the API server's own (metav1.StatusReasonForbidden, StatusReasonInvalid, ...) and metav1.StatusReasonUnauthorized, StatusReasonForbidden for a Git host that refuses the caller's identity, StatusReasonAlreadyExists for a file that landed on the base since it was read, and StatusReasonInvalid for a request that cannot be committed as it is.
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 is what a Committer acts with.
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 object's open pull request, for
// ReasonPullRequestOpen and ReasonPullRequestClosed.
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 as a Committer uses it: github.Remote and forgetest.Remote implement it.
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 is the change to one object, or to new objects in one namespace, in the writer's directory of the location that applies it.
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 identifies the object the pull request is about, as
// forge.OpenOne takes it: a stable branch-name prefix without
// underscores. The object gets one open pull request at a time.
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 is one commit: its parts, which land in one repository and branch, and its pull request.
type Result ¶ added in v0.14.0
type Result struct {
// Parts are the request's parts in order.
Parts []PartResult
// PullRequest is the opened pull request; zero on a dry run and when no
// part changes a file.
PullRequest forge.PullRequest
}
Result is what Commit decided and opened.