Documentation
¶
Overview ¶
Package merge is the gate's logic on devctl pr merge: which lane a merge queues in, what holds it, whose turn it is, and when a lane's installation has rolled the previous merge.
Index ¶
- Constants
- Variables
- func AcceptRed(argv []string, checks []string) []string
- func AttachRanges(hrs []HelmRelease, raw []byte) error
- func Bare(v string) string
- func BaseRef(doc []byte) string
- func Blocking(st *state.State, now time.Time, repo string, pr int, lane config.Lane) (state.Hold, bool)
- func BlockingFor(st *state.State, now time.Time, session, repo string, pr int, lane config.Lane) (state.Hold, bool)
- func CITimeout(argv []string, d time.Duration) []string
- func ClassicProtection(doc []byte) string
- func Fail(st *state.State, f state.Failed)
- func FailedChecks(doc []byte) []string
- func FixWindow(st *state.State, now time.Time, repo string, pr int, lane config.Lane) (state.Hold, bool)
- func Hung(p github.Pull, now time.Time, after time.Duration) bool
- func InResetWindow(m state.Merge, now time.Time, window time.Duration) bool
- func InfraLine(log string) (signature, line string, ok bool)
- func InfraNote(infra []Infra) string
- func Installed(h state.Hold, v string) bool
- func Keys(ms []state.Merge) string
- func Lost(st *state.State, now time.Time, alive func(pid int) bool) []state.Merge
- func MergeCommit(raw []byte) string
- func Merged(m *state.Merge, at time.Time)
- func NeedsJudging(ok bool, rc int) bool
- func NoReleaseWait(argv []string) []string
- func ParseArgs(argv []string) (repo string, pr int, ok bool)
- func ParseCapped(argv []string) bool
- func ParseOwned(argv []string) bool
- func ParsePromote(argv []string) (repo, version string, ok bool)
- func ParsePromoteCandidate(raw []byte) (candidate string, ok bool)
- func PreRelease(release string) bool
- func Preempts(st *state.State, now time.Time, m state.Merge, lane config.Lane) (state.Hold, bool)
- func Present(m state.Merge, now time.Time, ttl time.Duration, alive func(pid int) bool) bool
- func Prune(st *state.State, now time.Time, ttl, seedTTL time.Duration, ...)
- func Ready(lane config.Lane, hrs []HelmRelease, settling *state.Merge, now time.Time, ...) (bool, string)
- func Rebase(argv []string) bool
- func Red(doc []byte) bool
- func ResetAhead(st *state.State, me state.Merge, now time.Time, window time.Duration, ...) []state.Merge
- func ResetFirst(st *state.State, now time.Time, window time.Duration, alive func(pid int) bool) []state.Merge
- func ResetFirstUntil(first []state.Merge, window time.Duration) time.Time
- func Retry(st *state.State, repo string, pr int)
- func RollSet(hrs []HelmRelease, repo string) []string
- func Runs(m state.Merge, alive func(pid int) bool) bool
- func SecurityScan(name string) bool
- func ServerError(doc []byte) bool
- func SessionTurn(st *state.State, me state.Merge, most int, present func(state.Merge) bool, ...) (running []state.Merge, first *state.Merge, ok bool)
- func StripDetach(argv []string) (out, stripped []string)
- func StripPair(argv []string) (out []string, pair string, set bool)
- func ToolReleased(h state.Hold) bool
- func Transient(err error) bool
- func Unheld(st *state.State, now time.Time, lane config.Lane, ...) func(state.Merge) bool
- type Accepted
- type HelmRelease
- type Infra
- type InfraSignature
- type Lane
- func (q Lane) Ahead(repo string, pr int, present func(state.Merge) bool) (state.Merge, bool)
- func (q Lane) Passed(repo string, pr int) string
- func (q Lane) Position(repo string, pr int) int
- func (q Lane) SettlingKeys() string
- func (q Lane) Stalled(now time.Time, after time.Duration, present func(state.Merge) bool, ...) (Stall, bool)
- type Outcome
- type RedJudgement
- type Stall
Constants ¶
const ( // AllMerges holds every merge but the hold's Except. AllMerges = "merges" // LanePrefix prefixes a lane's name in a hold target. LanePrefix = "lane:" // ToolRepo is the merge tool's own repository: its merge opens the // tool-release window. ToolRepo = "giantswarm/devctl" // Tool is the merge tool's binary. Tool = "devctl" )
Hold targets besides owner/repo and github.
const AcceptRedFlag = "--accept-red"
AcceptRedFlag lets a named red check through devctl pr merge.
const PairFlag = "--pair"
PairFlag is the gate's flag on devctl pr merge naming the merge it lands with, owner/repo#n; the gate takes it off before devctl runs.
Variables ¶
var InfraSignatures = []InfraSignature{ {"Go module proxy", regexp.MustCompile(`(?:proxy|sum)\.golang\.org.*(?:stream error|INTERNAL_ERROR|connection reset|i/o timeout|TLS handshake timeout|unexpected EOF|: EOF\b|\b50[234]\b|Bad Gateway|Service Unavailable|Gateway Timeout)`)}, {"container registry", regexp.MustCompile(`(?i)toomanyrequests|(?:registry|docker\.io|ghcr\.io|azurecr\.io|quay\.io|gcr\.io|pkg\.dev).*(?:\b50[234]\b|Bad Gateway|Service Unavailable|Gateway Timeout|i/o timeout|connection reset|TLS handshake timeout|unexpected EOF)`)}, {"git checkout", regexp.MustCompile(`fatal: unable to access 'https://github\.com/[^']*': (?:The requested URL returned error: 5\d\d|Could not resolve host|Failed to connect)|error: RPC failed|fetch-pack: unexpected disconnect|remote: Internal Server Error`)}, {"package registry", regexp.MustCompile(`npm (?:ERR!|error) (?:code|errno) (?:ECONNRESET|ETIMEDOUT|EAI_AGAIN|E50[234])`)}, {"network", regexp.MustCompile(`Could not resolve host|Temporary failure in name resolution|TLS handshake timeout|dial tcp: lookup \S+ on \S+: (?:server misbehaving|i/o timeout)`)}, {"runner", regexp.MustCompile(`The runner has received a shutdown signal|lost communication with the server|The hosted runner encountered an error`)}, }
InfraSignatures are the transient infrastructure failures the gate knows: module proxies, registries, checkouts, the network and the runner.
Functions ¶
func AcceptRed ¶ added in v0.135.4
AcceptRed is a devctl pr merge argument vector that lets the named red checks through: argv with --accept-red <check> for each after its subcommand.
func AttachRanges ¶ added in v0.45.1
func AttachRanges(hrs []HelmRelease, raw []byte) error
AttachRanges sets the Range of each HelmRelease with an OCIRepository source from `kubectl get ocirepositories -A -o json`: the ref's semver range, or its tag as the one version it follows. A digest ref or a source that is not listed leaves the range unknown.
func Bare ¶ added in v0.113.0
Bare is a version without a leading v and without build metadata: a tag v1.2.3 and a chart version 1.2.3+1c161d9d name the same release.
func Blocking ¶
func Blocking(st *state.State, now time.Time, repo string, pr int, lane config.Lane) (state.Hold, bool)
Blocking is the active hold that stops a merge of repo#pr in lane: the repository's, the lane's, github's or one on all merges, unless the hold lets that repository or pull request through, else an upgrade running on the lane's installation. pr 0 is the repository's promote, which a hold waiting on the repository's own release lets through (AwaitsOwnRelease): held, the release could never come. A tool-release window stops the other merges only once its release is coming (ToolReleased): until then the installed tool is the latest release and runs, and only from the release on does every new run of it refuse until it is updated.
func BlockingFor ¶ added in v0.157.0
func BlockingFor(st *state.State, now time.Time, session, repo string, pr int, lane config.Lane) (state.Hold, bool)
BlockingFor is Blocking for a merge or promote session runs: a hold that admits session (hold set --except-session) lets it through.
func CITimeout ¶ added in v0.109.0
CITimeout is a devctl pr merge argument vector whose CI wait is bounded by d: argv with --timeout d after its subcommand, unless it names its own --timeout or d is zero.
func ClassicProtection ¶ added in v0.149.0
ClassicProtection is the gate's one line for a merge devctl declined on classic branch protection (exit 3): the cause and the fix, the repository aligned through giantswarm/github, whose devctl ruleset grants the owning team and the repository admins their bypass: no token the gate runs with may lift enforce_admins (HTTP 403). "" for any other document.
func Fail ¶ added in v0.123.0
Fail records f, a merge's run that merged nothing, in place of the pull request's earlier failed attempt, and drops the attempts older than failedFor.
func FailedChecks ¶ added in v0.123.0
FailedChecks are the names of the checks and CircleCI workflows devctl's document reports failed, in its order, each once (an Actions run's failed jobs are checks of their own).
func FixWindow ¶ added in v0.31.3
func FixWindow(st *state.State, now time.Time, repo string, pr int, lane config.Lane) (state.Hold, bool)
FixWindow is the active hold on lane that lets exactly repo#pr through (hold set --lane <lane> --except <repo>#<pr>): a declared fix window, in which that pull request merges without the lane's installation Ready or its previous merge rolled, the conditions a broken rollout only the fix itself can restore.
func Hung ¶ added in v0.82.0
Hung says whether a running merge whose devctl still runs has outlived its pull request p at now: closed without a merge, or merged more than after ago. devctl confirms a merge's release within its --timeout, so one running on past it holds its lane for nothing.
func InResetWindow ¶ added in v0.145.1
InResetWindow says whether m was queued under the GitHub budget floor for a reset that came less than window ago.
func InfraLine ¶ added in v0.139.2
InfraLine is the first line of log's tail that matches a signature, and the signature's name; ok false when none does.
func InfraNote ¶ added in v0.139.2
InfraNote is the attribution of every infra-red check, "" for none.
func Installed ¶ added in v0.101.2
Installed says whether the merge tool reporting version v ends the tool-release window h: a window whose merge released waits for the tool to report that release or a later one, any other for a version other than the one it opened on.
func Lost ¶ added in v0.25.2
Lost turns each running merge whose gate process and devctl are gone (killed, or lost with the machine) into a settling one and returns them: whether it merged is unknown, so the lane settles by the settle rule from now.
func MergeCommit ¶ added in v0.148.0
MergeCommit is the merge commit a merge's document (ParseDocument) names, "" when none.
func Merged ¶ added in v0.8.0
Merged turns an outside merge that GitHub reports merged at into its lane's settling merge. Its release is unknown: the lane settles by the settle rule from the merge on.
func NeedsJudging ¶ added in v0.27.1
NeedsJudging says whether a run's outcome is GitHub's to decide: devctl printed no document (ok false) or a signal ended it.
func NoReleaseWait ¶ added in v0.107.1
NoReleaseWait is a devctl pr merge argument vector that ends at the merge: argv with --no-release-wait after its subcommand, unless it has it.
func ParseArgs ¶
ParseArgs finds the repository and number in a devctl pr merge argument vector; ok is false for anything else (--help, a missing number).
func ParseCapped ¶ added in v0.150.0
ParseCapped reports whether argv is devctl pr merge or release promote, not a help call or a dry run: a run that counts against merge.cap.
func ParseOwned ¶ added in v0.49.0
ParseOwned reports whether argv is devctl pr merge, pr wait, release wait or rollout wait, not a help call.
func ParsePromote ¶ added in v0.52.0
ParsePromote finds the one repository of a devctl release promote argument vector and the candidate its --version pins, "" when it promotes whatever candidate is newest; ok is false for anything else (several repositories, --team, --dry-run, --help), which runs ungated.
func ParsePromoteCandidate ¶ added in v0.107.1
ParsePromoteCandidate reads the candidate of devctl release promote --dry-run's JSON document for one repository: the release candidate a promotion would dispatch now, "" when there is none. ok is false when the document names no single repository.
func PreRelease ¶ added in v0.137.1
PreRelease says whether release is a semver pre-release, a release candidate: an installation on a stable range never runs it.
func Preempts ¶ added in v0.136.0
Preempts is the hold that takes the running merge m back out of lane before its devctl merges: a hold set after m started that lets another pull request through (--except owner/repo#n), an order that pull request goes first in. A hold without such an exception stops new merges only.
func Present ¶ added in v0.13.2
Present says whether a waiting merge holds its place against the arrived merges behind it: a merge run outside the gate, one whose devctl pr merge is in the gate, or was within ttl (a rerun after exit 76, the retry of a failed attempt). A seeded place whose merge has not arrived, or left more than ttl ago, is absent.
func Prune ¶
Prune drops the waiting merges whose gate is gone: a place a run that ended left behind (Finished set, as an older release kept one for the retry) at once, any other once its gate left more than ttl ago (seedTTL for a seeded place), and settles the lost ones (Lost).
func Ready ¶
func Ready(lane config.Lane, hrs []HelmRelease, settling *state.Merge, now time.Time, settle time.Duration) (bool, string)
Ready says whether the lane is free for its next merge: every HelmRelease of its charts Ready and the settling merge rolled. A settling merge with a known release has rolled when each HelmRelease of its roll set reports that release or a later one (reached), or follows a range that never admits it (a release candidate under a stable range); one whose release is unknown (merged without a confirmed release, or its run lost) has settled once settle has passed since it ended; one whose release failed rolls nothing and has settled at once. why says what the lane waits for; on a free lane it names why the merge settled without a roll, "" when it rolled.
func Rebase ¶ added in v0.113.0
Rebase says whether a devctl pr merge argument vector is a rebase merge: --rebase (or --rebase=true) among its flags, before any --.
func Red ¶ added in v0.135.4
Red says whether devctl's document is a red verdict (exit 1): a failed check, status, run or workflow.
func ResetAhead ¶ added in v0.145.1
func ResetAhead(st *state.State, me state.Merge, now time.Time, window time.Duration, present func(state.Merge) bool, alive func(pid int) bool) []state.Merge
ResetAhead are the merges of ResetFirst queued before me that are free to start (their lane's next, nothing running or settling in it): each takes a devctl slot before me.
func ResetFirst ¶ added in v0.145.1
func ResetFirst(st *state.State, now time.Time, window time.Duration, alive func(pid int) bool) []state.Merge
ResetFirst are the merges that go first at the GitHub budget's reset, oldest queued first: each waits in a live gate, queued under the floor for a reset that came less than window ago. The waits yield to them until they start or their window ends.
func ResetFirstUntil ¶ added in v0.145.1
ResetFirstUntil is when the last window of first ends.
func Retry ¶ added in v0.123.0
Retry drops repo#pr's failed attempt: its next attempt joins the lane.
func RollSet ¶
func RollSet(hrs []HelmRelease, repo string) []string
RollSet names the HelmReleases a merge of repo must roll: those of its chart on the newest version when the merge starts. One pinned to an older version does not follow releases and is not waited for.
func SecurityScan ¶ added in v0.135.4
SecurityScan says whether the named check is a security scan.
func ServerError ¶ added in v0.112.1
ServerError says whether devctl's document is a tooling failure (exit 7) for a 5xx on its merge or branch-update call: GitHub failed in transit, and the same merge sent again may well land.
func SessionTurn ¶ added in v0.119.0
func SessionTurn(st *state.State, me state.Merge, most int, present func(state.Merge) bool, alive func(pid int) bool) (running []state.Merge, first *state.Merge, ok bool)
SessionTurn says whether the waiting merge me, its lane's next, may start under the cap (most) on one party's running merges: each running devctl polls GitHub, a waiting place does not. It returns the party's running merges (gate or devctl alive) and, where me waits, the party's merge that takes the free slot first: one that joined before me, is present and is free to start (its lane's next, nothing running or settling in its lane), so the party's merges start in the order they queued. most 0 or less is no cap.
func StripDetach ¶ added in v0.103.0
StripDetach drops devctl pr merge's --detach and --on-done (with its command, either form) from argv: the gate runs every merge outside its caller already, and a detached devctl would leave the gate's unit and its lane accounting. stripped lists what went; argv of any other command comes back as it is.
func StripPair ¶ added in v0.156.0
StripPair takes devctl pr merge's --pair <owner/repo#n> (either form) off argv, the gate's own flag: pair is its value, set says the flag was there (an empty value too). argv of any other command comes back as it is.
func ToolReleased ¶ added in v0.148.0
ToolReleased says the tool-release window h waits for a release that is coming: its pull request merged, or it is a promotion's, which dispatches one.
func Transient ¶ added in v0.145.4
Transient reports whether err is a read that failed in transit and may answer when sent again: a timeout, a resolver error, a refused or reset connection, an EOF mid-answer or a gateway's 5xx. An answer that refuses (no login, no access, a parse error) is not.
func Unheld ¶ added in v0.136.0
func Unheld(st *state.State, now time.Time, lane config.Lane, present func(state.Merge) bool) func(state.Merge) bool
Unheld is present for a lane's places that no hold blocks: a waiting merge a hold keeps out of the lane holds no place against the merges behind it, so the one merge the hold lets through enters first, and the held place keeps its turn for after the hold.
Types ¶
type HelmRelease ¶
type HelmRelease struct {
Key string // namespace/name
Chart string
Version string // the chart version without build metadata
Ready bool
Message string
// Source is the namespace/name of the OCIRepository the chart comes
// from (spec.chartRef), "" for any other source.
Source string
// Range is the semver range the HelmRelease follows: its OCIRepository's
// ref (semver, or a tag as an exact version) or its chart template's
// version. "" is unknown: every release counts as followed.
Range string
}
HelmRelease is the part of a Flux HelmRelease the lane's readiness reads.
func ParseHelmReleases ¶
func ParseHelmReleases(raw []byte) ([]HelmRelease, error)
ParseHelmReleases reads `kubectl get helmreleases -A -o json`.
type Infra ¶ added in v0.139.2
type Infra struct {
Check string `json:"check"`
Repo string `json:"repo"`
Run int64 `json:"run"`
Job int64 `json:"job"`
Signature string `json:"signature"`
Line string `json:"line"`
}
Infra is a red check whose job died on a transient infrastructure failure: the matched signature and log line, and the job to rerun.
func InfraReds ¶ added in v0.139.2
InfraReds are the red checks of devctl's document that are GitHub Actions jobs whose log tail shows a transient infrastructure failure (InfraSignatures). A log GitHub does not hand over, a CircleCI job and a workflow are attributed as before.
type InfraSignature ¶ added in v0.139.2
InfraSignature is a transient infrastructure failure a failed job's log shows: a line matching Pattern is no change's fault, the job run again may pass.
type Lane ¶
type Lane struct {
Name string `json:"name"`
Running *state.Merge `json:"running,omitempty"`
// Settling is the latest of the lane's settling merges, AllSettling all
// of them, oldest first: a merge outside the gate can settle while a
// gated one does.
Settling *state.Merge `json:"settling,omitempty"`
AllSettling []*state.Merge `json:"allSettling,omitempty"`
Waiting []state.Merge `json:"waiting"`
// Failed are the lane's merges whose last run merged nothing, oldest
// first, until their next attempt.
Failed []state.Failed `json:"failed,omitempty"`
}
Lane is one lane's queue.
func Queue ¶
Queue returns the lane's running and settling merges and the waiting ones in turn order: a settled outside merge first, then in join order.
func (Lane) Ahead ¶ added in v0.13.2
Ahead is the waiting merge repo#pr waits behind, false when repo#pr is the lane's next: the first merge before it that is present, or, for a seeded place, an absent seed before it, as seeds keep their order, unless that seed is a later pull request of the same session and repository, which cannot arrive first. A free lane runs the first arrived merge.
func (Lane) Passed ¶ added in v0.13.2
Passed names the absent merges before repo#pr that it runs ahead of.
func (Lane) Position ¶
Position is the 1-based turn of repo#pr among the lane's waiting merges, 0 when it is not waiting.
func (Lane) SettlingKeys ¶ added in v0.8.0
SettlingKeys names the lane's settling merges, oldest first.
func (Lane) Stalled ¶ added in v0.15.0
func (q Lane) Stalled(now time.Time, after time.Duration, present func(state.Merge) bool, alive func(pid int) bool, arrived func(pid int) (time.Time, bool)) (Stall, bool)
Stalled reports the lane's stall: no merge runs, the first waiting merge whose gate call is in the gate (alive) is held up only by places whose merges are not, none of them run outside the gate, and it has waited so for longer than after. arrived is when a gate call's process started.
type Outcome ¶
type Outcome struct {
// Merged is true when the document names a merge commit.
Merged bool
// Release is the tag the merge released and devctl confirmed pullable,
// empty when none or unknown.
Release string
// NoRelease is true when the merge warranted no release: nothing rolls.
NoRelease bool
// ReleaseFailed is true when the merge's release failed (devctl exit 6,
// verdict ci_failed): nothing rolls. Release is its tag when it was cut.
ReleaseFailed bool
// Unconfirmed is true when GitHub, not the document, reports the merge:
// devctl ended before it confirmed the release.
Unconfirmed bool
// State is a promotion's state in devctl release promote's document
// (dispatched, nothing_to_promote, not_built, …), empty for a merge.
State string
}
Outcome is what devctl's document says about the merge.
func Judged ¶ added in v0.27.1
Judged is the outcome of a run that ended without its document or by a signal (exit 128+n): GitHub's state of the pull request decides whether it merged, never the exit code, and a merge's release is unconfirmed.
func ParseDocument ¶
ParseDocument reads devctl pr merge's JSON document (docs/pr-merge.md in giantswarm/devctl): its release object carries the verdict and the tag side by side. The tag counts only with the verdict available, a release devctl confirmed pullable; any other tag is unknown and the lane settles by the settle rule. A failed release (ci_failed) keeps its tag, if any, and rolls nothing. ok is false when it is none.
func ParsePromoteDocument ¶ added in v0.52.0
ParsePromoteDocument reads devctl release promote's JSON document: a dispatched candidate (vX.Y.Z-rc.N) is a merge whose release is its stable version (vX.Y.Z), a repository with nothing to promote warrants no release. ok is false when it is none.
func ParseReleaseWait ¶ added in v0.150.1
ParseReleaseWait reads devctl release wait's JSON document as a merge's release: available is its tag, a failed tag pipeline or commit status (ci_failed, status_failed) a failed release that keeps its tag, any other verdict (timeout, ambiguous_release, …) unconfirmed. reason is devctl's; ok is false when the document is none.
type RedJudgement ¶ added in v0.135.4
type RedJudgement struct {
Accepted []Accepted `json:"accepted,omitempty"`
Refused []string `json:"refused,omitempty"`
// Infra are the refused checks that died on a transient infrastructure
// failure, not on the pull request's change.
Infra []Infra `json:"infra,omitempty"`
}
RedJudgement is the gate's judgement of a red devctl pr merge document against its base: the red checks it lets through and the reasons it refuses the rest.
func JudgeRed ¶ added in v0.135.4
func JudgeRed(doc []byte, base github.BaseChecks, infra []Infra) RedJudgement
JudgeRed judges devctl pr merge's red document against its base: a red check that is neither required (by the document or base) nor a security scan, and is red on the base head too, is let through, named with why; any other red check refuses the merge, as does a red CircleCI workflow (a pipeline, judged by none of its jobs' names), a check green on the base head (the pull request broke it), and one the base head has no finished result for, so nothing slips through on a missing comparison. A refused check infra names (InfraReds) is refused as a transient infrastructure failure with its log line and rerun, not as the pull request's breakage.
func (RedJudgement) LetThrough ¶ added in v0.135.4
func (j RedJudgement) LetThrough() bool
LetThrough says whether every red check of the document is let through.
func (RedJudgement) Names ¶ added in v0.135.4
func (j RedJudgement) Names() []string
Names are the checks the judgement lets through.
func (RedJudgement) String ¶ added in v0.135.4
func (j RedJudgement) String() string
String is the judgement in one line: what is let through and what refuses.
type Stall ¶ added in v0.15.0
type Stall struct {
// Merge is the waiting merge whose gate call is in the gate.
Merge state.Merge `json:"merge"`
// Behind are the places before it that hold it up: seeds whose merges
// have not arrived, merges that left the gate.
Behind []state.Merge `json:"behind"`
// Since is when the wait began: the gate call's arrival, the last of
// those places going absent or the lane's last merge ending, the latest.
Since time.Time `json:"since"`
}
Stall is a lane's first arrived merge held up by places whose merges are not in the gate.