placement

package
v1.0.0-rc.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package placement decides which queued agent task goes to which runner.

Place is a pure function: it takes every input as a value, the clock included, does no I/O, and returns its decisions. Beekeeper runs it whenever an input changes, and Capacity answers a queue's gate with the same rules.

The rules:

  • Order: class (incident, repair, continuing, starting), then the task's priority (lower first, unset last), then age (older first).
  • Matching: a runner of the task's organization that is connected, whose host may still work, whose purposes take the task's kind, whose focus matches the task's fields, that has the task's required capabilities and a harness for it, that hasn't just declined it, that has a free slot, whose pressure is within bounds, and one of whose subscriptions is on pace for the task's class.
  • Affinity: a task prefers its preferred runner, and a continuing task without one the runner of its subject's last session. While that runner is held only by something that passes (a full slot, pressure, pace, a reconnect), the task waits for it up to the affinity wait; then any matching runner takes it.
  • Choice: among the runners and subscriptions that fit, preferred capabilities first, then the preferred provider (and the provider to avoid last), then paced subscriptions before unpaced ones, then the subscription furthest behind its pace, then the runner with the most free slots.
  • A task that waits gets the reason of the runners that came closest, naming the gate with its numbers, such as `no free slot with docker: laptop-a 2/2`.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPolicy = Policy{
	AffinityWait:   5 * time.Minute,
	DeclineBackoff: 10 * time.Minute,
	Limits: Limits{
		MaxLoad:            0.9,
		MinFreeMemory:      resource.MustParse("2Gi"),
		MinFreeDisk:        resource.MustParse("10Gi"),
		MinGitHubRemaining: 500,
	},
	Pace: pace.DefaultRules,
}

DefaultPolicy is placement's default configuration.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	// Available is true when a runner would take the task now.
	Available bool `json:"available"`
	// Gate and Reason say, when none would, what holds it.
	Gate   Gate   `json:"gate"`
	Reason string `json:"reason"`
	// Runner, Harness, Subscription and Provider say where it would go.
	Runner       string `json:"runner"`
	Harness      string `json:"harness"`
	Subscription string `json:"subscription"`
	Provider     string `json:"provider"`
}

Answer is whether a runner could take a hypothetical task now.

func Capacity

func Capacity(in Input, policy Policy, probe v1alpha1.AgentTask) Answer

Capacity asks placement about a hypothetical task, queued now behind the tasks already queued, and answers where it would go or what holds it. A task without a class is a starting one.

type Decisions

type Decisions struct {
	Offers  []Offer
	Holds   []Hold
	Expired []Expiry
}

Decisions are what Place decided, each queued task once.

func Place

func Place(in Input, policy Policy) Decisions

Place decides, for every queued task in order, whether it is offered to a runner, waits, or has passed its deadline.

type Expiry

type Expiry struct {
	Namespace string
	Task      string
	Reason    string
}

Expiry fails a task that wasn't started by its deadline.

type Gate

type Gate string

Gate names the check that holds a task. It labels metrics.

const (
	GateNoRunner   Gate = "no_runner"
	GateOffline    Gate = "offline"
	GateHost       Gate = "host"
	GatePurpose    Gate = "purpose"
	GateFocus      Gate = "focus"
	GateCapability Gate = "capability"
	GateHarness    Gate = "harness"
	GateDeclined   Gate = "declined"
	GateSlot       Gate = "slot"
	GatePressure   Gate = "pressure"
	GatePace       Gate = "pace"
	GateAffinity   Gate = "affinity"
)

The gates, in the order a runner is checked.

type Hold

type Hold struct {
	Namespace string
	Task      string
	Gate      Gate
	Reason    string
}

Hold keeps a task queued.

type Input

type Input struct {
	// Now is the clock.
	Now time.Time
	// Tasks are the tasks to place and those that hold slots or
	// reservations. Only queued ones are placed.
	Tasks []v1alpha1.AgentTask
	// Runners are the registered runners, with their live status.
	Runners []v1alpha1.Runner
	// Sessions are recent sessions, for each subject's last runner.
	Sessions []v1alpha1.AgentSession
	// Subscriptions are the subscriptions with their newest readings.
	Subscriptions []v1alpha1.Subscription
}

Input is everything placement decides on.

type Limits

type Limits struct {
	MaxLoad            float64
	MinFreeMemory      resource.Quantity
	MinFreeDisk        resource.Quantity
	MinGitHubRemaining int32
}

Limits are the default pressure bounds for runners that set none.

type Offer

type Offer struct {
	Namespace    string
	Task         string
	Runner       string
	Harness      string
	Subscription string
	Provider     string
	// Reservation is the headroom to hold on the subscription, unset for an
	// unpaced one.
	Reservation *v1alpha1.Reservation
}

Offer places a task on a runner.

type Policy

type Policy struct {
	// AffinityWait is how long a task waits for its preferred runner.
	AffinityWait time.Duration
	// DeclineBackoff is how long a runner that declined a task isn't offered
	// it again.
	DeclineBackoff time.Duration
	// Limits are the default pressure bounds.
	Limits Limits
	// Pace are the default pace rules.
	Pace pace.Rules
}

Policy holds placement's configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL