Documentation
¶
Overview ¶
Package failoverhost keeps a fleet of OpenStack Nova compute hosts ready to absorb the workload of a failed host.
What a failover host reservation is ¶
When a hypervisor fails, Nova has to evacuate every virtual machine running on it onto other hosts. For that to succeed quickly and predictably there must be somewhere to put those vms. This package keeps a fraction of every group of interchangeable hosts empty and reserved, so a whole host's workload can be gang-evacuated onto a reserved "failover host" in one move. A failover host reservation (v1alpha1.Reservation of type FailoverHostReservation) blocks a target host from receiving ordinary placements so it stays available for this purpose. Its full lifecycle (Designated -> Active -> In Use, plus the Failed and Revoked/Used terminal states) is documented on the ReservationTypeFailoverHost constant in the v1alpha1 package.
Partitions ¶
Hosts are not interchangeable across the whole cloud: a HANA host, a general-purpose host and an external-customer host can generally only ever fail over within their own kind, because their workloads carry scheduling constraints (flavors, image properties, aggregates) that only matching hosts satisfy. We therefore group hosts into failover partitions: maximal sets of hosts within which every host can be evacuated onto every other host. We do not configure these groups by hand; we discover them from the scheduler's own placement decisions, so the grouping always reflects the live constraints.
The two halves of the controller ¶
The controller has a producer and a consumer that communicate through the desiredReservations map:
- A periodic calculation loop (Start -> loop, both in controller.go) recomputes the desired set of failover host reservations from the current cluster state on a fixed interval, and stores it as desiredReservations.
- An event-driven reconciler (Reconcile, below) brings the actual reservations in the cluster in line with that desired set, creating, updating and pruning Reservation objects.
The loop never writes Reservation objects itself; it only recomputes the desired state and nudges the reconciler. Keeping the expensive, external-call heavy computation out of the reconcile path means reconciles stay cheap and idempotent.
The calculation ¶
The calculation half is a ReservationGenerator (generation.go): loop calls Generate each pass, swaps its result in as the desired state, and wakes the reconciler. The production generator runs a four-stage pipeline (Seeder -> PathFinder -> PartitionBuilder -> ReservationPlanner); see pipelineGenerator in generation.go for the end-to-end flow. The interface lets the whole generation strategy be swapped without touching the controller's plumbing.
Index ¶
- func SelectFailoverHost(reservations []v1alpha1.Reservation, sourceHost string) *v1alpha1.Reservation
- type Config
- type Controller
- type ControllerConfig
- type Flavor
- type Matcher
- type MatcherMonitor
- type Monitor
- func (m *Monitor) Collect(ch chan<- prometheus.Metric)
- func (m *Monitor) Describe(ch chan<- *prometheus.Desc)
- func (m *Monitor) RecordCalculation(summary calculationSummary)
- func (m *Monitor) RecordCalculationAbort(reason string)
- func (m *Monitor) RecordReservationCreated()
- func (m *Monitor) RecordReservationDeleted()
- func (m *Monitor) RecordReservationError(op string)
- func (m *Monitor) RecordReservationUpdated()
- func (m *Monitor) RecordSchedulerRequest(status string, duration time.Duration)
- type Partition
- type PartitionBuilder
- type Path
- type PathFinder
- type ReservationGenerator
- type ReservationPlanner
- type Seed
- type Seeder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SelectFailoverHost ¶
func SelectFailoverHost(reservations []v1alpha1.Reservation, sourceHost string) *v1alpha1.Reservation
SelectFailoverHost picks the one failover host reservation a source host should gang-evacuate onto, deterministically. It is a pure function of the reservation snapshot, so the filter_failover_host filter, the weigher_failover_host weigher and this Matcher — which all run over the same snapshot within one pipeline execution — select the same target without coordinating.
Among the reservations whose partition includes sourceHost it prefers the one already in use by this very source (the gang-evacuation path — the whole gang lands on the same target), never picks one in use by a different source (which would steal an active landing zone), and otherwise takes the first Active one by target host name. A not-yet-in-use reservation is only eligible once it is Active (its host drained and empty); a still-draining, not-yet-Active one is never selected (though the filter still blocks it from ordinary placement). Returns nil when nothing is selectable.
Types ¶
type Config ¶
type Config struct {
Failover struct {
Hosts ControllerConfig `json:"hosts"`
} `json:"failover"`
}
Config is the top-level config section this controller reads from the shared cortex conf.json. The controller's own settings are nested under failover.hosts so they sit alongside the (flavor-based) failover controller's settings without colliding with the flat, top-level keys read from the same file.
type Controller ¶
type Controller struct {
client.Client // k8s client
Config ControllerConfig
// Scheduler is the shared in-process scheduler the path finder probes for
// placement candidates. Required (the controller cannot compute failover
// partitions without it).
Scheduler *compute.Placement
// Monitor records Prometheus metrics for the calculation loop and the
// reconciler. It may be nil (e.g. in tests); every call site nil-guards it.
Monitor *Monitor
// contains filtered or unexported fields
}
Controller keeps the cluster's failover host reservations in sync with the current cluster state. It has two cooperating halves (see the package doc for the bigger picture):
- a periodic calculation loop (Start -> loop) that recomputes the desired reservations and stores them in desiredReservations, and
- the Reconcile method that drives the actual Reservation objects toward that desired set.
The loop is the single writer of desiredReservations and Reconcile the single reader, both synchronised by desiredReservationsMu.
func (*Controller) Reconcile ¶
Reconcile drives a single failover host reservation toward the desired state computed by the calculation loop. It is triggered by the loop (via reconcileCh) for every reservation that is either desired or still present, so between them the two cover create, update, delete and no-op:
- desired, not present -> create it.
- not desired, present -> prune it (it no longer matches any partition).
- desired and present -> update it if the spec/labels drifted.
- neither desired nor present, or already in sync -> nothing to do.
It is level-triggered and idempotent: it reads the current actual and desired state on every call and makes at most one write, so redundant events and retries are harmless.
func (*Controller) SetupWithManager ¶
func (c *Controller) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager wires both halves of the controller into the manager:
- It registers the Controller as a Runnable (mgr.Add) so the manager starts and stops the periodic calculation loop (Start) alongside the controller.
- It registers the reconciler with a channel event source, so the loop can enqueue reconcile requests by sending on reconcileCh.
It also defaults the generator to the production pipelineGenerator. Tests may set it beforehand to substitute a fake (e.g. a path finder pointed at a stub scheduler); it is only defaulted here when nil.
func (*Controller) Start ¶
func (c *Controller) Start(ctx context.Context) error
Start runs the periodic calculation loop until ctx is cancelled.
It implements manager.Runnable so the manager owns its lifecycle (it is registered via mgr.Add in SetupWithManager). Start first validates the config — a misconfigured ratio, minimum or interval is a programming/deployment error that should fail fast rather than silently produce no reservations — then runs one pass immediately (so reservations exist without waiting a full interval) and re-runs loop on every tick. On shutdown it closes reconcileCh so the reconciler's event source drains cleanly.
type ControllerConfig ¶
type ControllerConfig struct {
// Ratio is a global ratio that determines how many failover hosts inside
// a partition are created. For example, a ratio of 0.1 means that
// if a partition consists of 10 hosts, 1 failover host will be created.
// The number of resulting failover hosts in a partition will be rounded
// down. This means if there are not sufficient hosts inside a partition,
// it is possible that no failover hosts will be created.
Ratio float64 `json:"ratio"`
// Minimum is the minimum number of failover hosts that should be created
// in a partition, regardless of the ratio. This ensures that even small
// partitions have at least a certain number of failover hosts.
Minimum int `json:"minimum"`
// GenerationInterval is the interval within which failover partitions are
// recalculated and failover host reservations are updated accordingly.
GenerationInterval metav1.Duration `json:"generationInterval"`
}
ControllerConfig contains configuration for failover host reservations.
type Flavor ¶
type Flavor struct {
// Name is the flavor name, used for pipeline inference, trait/capability
// extraction and to label the failover edges a seed supports.
Name string
// MemoryMB and VCPUs size the probe. RAM is in MiB (despite the "MB" label),
// matching what the scheduler expects on NovaFlavor.MemoryMB.
MemoryMB uint64
VCPUs uint64
// ExtraSpecs carries the flavor's extra specs (hypervisor type, custom
// traits, hardware requirements) so the same filters apply as for a real vm.
ExtraSpecs map[string]string
}
Flavor is the slice of a flavor the seeder permutes into a scheduler probe: its name, size, and extra specs (which carry the hypervisor type, traits and other constraints the pipeline filters on). It deliberately mirrors only the fields fed into api.NovaFlavor, so the rest of the flavor-group shape never leaks into the pathfinder.
type Matcher ¶
type Matcher struct {
client.Client
// Monitor records the evacuation-without-reservation metric. May be nil.
Monitor *MatcherMonitor
}
Matcher confirms an evacuation's gang target after the scheduling pipeline has run and pins the source host to that target, implementing gang-evacuation.
The candidate shaping — removing the other reserved hosts and lifting the selected failover host to the front — is done inside the pipeline by the filter_failover_host filter and the weigher_failover_host weigher. The Matcher does not touch the candidate list. Its sole job is the stateful write: once the pipeline has settled on a target host, it marks the matching reservation InUse so that subsequent evacuations from the same source host deterministically land on the same target.
It runs from inside the pipeline controller's exclusive lock, on write runs only, so the InUse write is serialized against — and visible to — subsequent evacuation requests from the same source host. The write is committed only once (on the first evacuation from a given source); later requests see the already-InUse reservation (the filter/weigher keep selecting it) and so land on the same target.
The Matcher only ever advances a reservation to InUse. Moving it back out (to Active/Used once the evacuation completes) is owned by the failover host lifecycle reconciler, based on the real workload present on the host.
func (*Matcher) ConfirmAndMarkInUse ¶
func (m *Matcher) ConfirmAndMarkInUse(ctx context.Context, request api.ExternalSchedulerRequest, orderedHosts []string) error
ConfirmAndMarkInUse inspects the pipeline's ordered candidates for an evacuation request and, if the top candidate is the failover host reservation selected for the request's source host, marks that reservation InUse.
It is a no-op for non-evacuation requests and for evacuations without a source host. When no failover host reservation matches the source host — or the selected one did not end up as the top candidate (it was filtered out by other constraints, so the evacuation falls back to an ordinary host) — it records the evacuation-without-reservation metric and writes nothing.
type MatcherMonitor ¶
type MatcherMonitor struct {
// contains filtered or unexported fields
}
MatcherMonitor is the small Prometheus collector owned by the scheduling pipeline's failover host Matcher. It is kept separate from the failover host controller's Monitor so both can be registered independently: the pipeline controller and the failover-host-reservations-controller can be enabled at once without their collectors colliding on shared metric names.
func NewMatcherMonitor ¶
func NewMatcherMonitor() *MatcherMonitor
NewMatcherMonitor creates a new matcher monitor with Prometheus metrics.
func (*MatcherMonitor) Collect ¶
func (m *MatcherMonitor) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*MatcherMonitor) Describe ¶
func (m *MatcherMonitor) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
func (*MatcherMonitor) RecordEvacuationWithoutReservation ¶
func (m *MatcherMonitor) RecordEvacuationWithoutReservation(az string)
RecordEvacuationWithoutReservation records an evacuation scheduling request whose source host matched no failover host reservation, so the request fell back to the ordinary candidate set. az is the request's availability zone (may be empty if unknown).
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor provides Prometheus metrics for the failover host controller. It covers two activities: the periodic calculation loop that recomputes the desired reservations, and the reconciler that drives the actual Reservation objects toward that desired state.
Unlike the sibling failover controller, the calculation loop here is cluster-wide (one pass covers every partition and availability zone at once, and a partition clique is not guaranteed to be single-AZ), so the loop-level metrics carry no availability-zone label. The scheduler-request and reconcile metrics do carry a small label each where it is actionable.
func NewMonitor ¶
func NewMonitor() *Monitor
NewMonitor creates a new monitor with Prometheus metrics.
func (*Monitor) Collect ¶
func (m *Monitor) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*Monitor) Describe ¶
func (m *Monitor) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
func (*Monitor) RecordCalculation ¶
func (m *Monitor) RecordCalculation(summary calculationSummary)
RecordCalculation records the metrics of a single completed calculation pass.
func (*Monitor) RecordCalculationAbort ¶
RecordCalculationAbort records a calculation pass that aborted before producing a desired state. reason is "collect", "seeding" or "pathfinding".
func (*Monitor) RecordReservationCreated ¶
func (m *Monitor) RecordReservationCreated()
RecordReservationCreated records a successful reservation create.
func (*Monitor) RecordReservationDeleted ¶
func (m *Monitor) RecordReservationDeleted()
RecordReservationDeleted records a successful stale-reservation delete.
func (*Monitor) RecordReservationError ¶
RecordReservationError records a failed reservation write. op is "create", "update" or "delete".
func (*Monitor) RecordReservationUpdated ¶
func (m *Monitor) RecordReservationUpdated()
RecordReservationUpdated records a successful reservation update.
type Partition ¶
type Partition struct {
// Hosts are the partition's members, sorted by name.
Hosts []hv1.Hypervisor
// Flavors are the flavor names accepted on every host of the partition,
// sorted.
Flavors []string
}
Partition is one failover partition: a set of hypervisors in which every host can be evacuated onto every other host, plus the flavors that whole set can run. Flavors answers "which flavors can be spawned anywhere in this partition": a flavor is listed only if *every* host in the partition accepts it, so a listed flavor is guaranteed to run on all of them. Flavors is sorted and may be empty — e.g. when the members' accept sets are disjoint, so no single flavor is proven to fit everywhere in the partition.
type PartitionBuilder ¶
type PartitionBuilder interface {
// BuildPartitions groups the failover Paths into partitions, each carrying the
// flavors its whole host set can run. The output is deterministic regardless
// of edge order.
BuildPartitions(paths []Path) []Partition
}
PartitionBuilder is the third pipeline stage. It clusters the directed failover edges found by the PathFinder into failover partitions.
A failover partition is a maximal set of hypervisors in which every host can be evacuated onto every other host. For example, HANA hosts, general-purpose hosts and external-customer hosts typically each form their own partition, because their workloads can only ever fail over within the group.
type Path ¶
type Path struct {
// Source and Target are the endpoints: source can be evacuated onto target.
Source, Target hv1.Hypervisor
// Flavors are the names of the flavor seeds both endpoints co-accepted, which
// is what produced this edge. Sorted and deduplicated.
Flavors []string
}
Path is one directed edge of the failover graph: source's whole workload can be gang-evacuated onto target. It also carries the flavors whose seed proved the edge — i.e. the flavors source and target co-accept — so downstream stages can report which flavors a partition can actually run. Flavors is sorted and deduplicated.
type PathFinder ¶
type PathFinder interface {
// FindPaths returns the failover edges as Paths, discovered by probing the
// scheduler with the given seeds; each Path also records the flavors its
// endpoints co-accepted. A seed the scheduler accepts on fewer than two hosts
// yields no edge and is not an error. Any lookup error, by contrast, is an
// infrastructure failure (scheduler unreachable/timed out/non-200) that
// invalidates the pass, so it is returned to abort it rather than silently
// collapsing the failover graph.
FindPaths(ctx context.Context, topo topology, seeds []Seed) ([]Path, error)
}
PathFinder is the second pipeline stage. It discovers the directed edges of the failover graph: for every host it reports the hosts that host's workload could be gang-evacuated onto. An edge source->target means "a host's whole workload can be evacuated onto target, and target is large enough to hold it".
Edges are no longer derived from the vms that happen to run on a host. Instead we probe with flavor seeds (see Seeder): for every (flavor, availability zone) permutation we ask the scheduler which hosts would accept it, and treat the hosts that co-accept a seed as mutually compatible under that flavor. This escapes two blind spots of vm-seeding — partitions whose hosts run no vms, and a single exotic vm vetoing a host from its partition — both documented on Seed.
We probe with evacuation intent: a failover ultimately cold-migrates (evacuates) a dead host's workload, and evacuation is the weaker check — it does not verify the CPU/feature compatibility that live migration does. We deliberately do not probe live-migratability here even though a freshly reserved host is drained by live migration before its reservation goes active: we assume a partition holds enough peers to absorb that drain, which later draining code arranges, rather than proving it per host at partition time.
The direction matters. source->target does not imply target->source: target might be too small for source's workload even if the reverse fits. The PartitionBuilder later keeps only the mutual edges, so this stage is free to report one-directional possibilities.
type ReservationGenerator ¶
type ReservationGenerator interface {
// Generate snapshots the cluster and returns the desired failover host
// reservations keyed by their object reference (name only; reservations are
// cluster-scoped), together with the topology snapshot it reasoned over — the
// controller needs topo.existing to wake the reconciler for every reservation
// that may need pruning. ok=false means the pass should be abandoned without
// touching the published desired state; the generator has already logged the
// reason and recorded the abort metric.
Generate(ctx context.Context) (desired map[corev1.ObjectReference]v1alpha1.Reservation, topo topology, ok bool)
}
ReservationGenerator computes the full desired set of failover host reservations from the current cluster state. It is the swappable "producer" half of the controller: the controller's loop calls Generate each pass, swaps the result in as the desired state, and wakes the reconciler. Replacing this interface replaces the entire generation strategy without touching the controller's plumbing (ticker, lock/swap, publish).
type ReservationPlanner ¶
type ReservationPlanner interface {
// PlanReservations returns the desired failover host reservations for the
// given partition. The topology supplies the reservations that already
// exist, which the planner prefers to keep so target hosts stay stable
// across passes rather than flapping from one host to another. description
// is a human-readable label of what distinguishes the partition's hosts,
// stored verbatim on each reservation. See characterizePartitions.
PlanReservations(topo topology, partition []hv1.Hypervisor, description string) []v1alpha1.Reservation
}
ReservationPlanner is the fourth pipeline stage. For a single failover partition it decides which hosts should become failover targets, i.e. be kept empty so another host in the partition can gang-evacuate onto them.
We do not reserve a fixed number per partition. Reserving too few leaves no landing space when a host fails; reserving too many wastes capacity. So the count scales with the partition: a configured ratio of the hosts, floored at a configured minimum so even small partitions keep some headroom.
type Seed ¶
type Seed struct {
// Flavor is the flavor to probe placement for.
Flavor Flavor
// AvailabilityZone is the AZ to probe in, drawn from the hypervisor CRDs.
AvailabilityZone string
}
Seed is a single hypothetical placement the PathFinder probes the scheduler with: a flavor in a given availability zone. It replaces the running vm the old pathfinder seeded from.
Seeding from flavors rather than vms fixes two blind spots of the vm-based approach:
- A group of hosts that happen to run no vms produced no probe at all, so its partition was never discovered — even though it is perfectly capable of absorbing a failover once a vm lands there. A flavor seed exists whether or not anything is currently scheduled, so the partition is found up front.
- A single "exotic" vm on a host (one whose scheduling constraints no peer satisfies) emptied that host's candidate intersection and kept it out of the partition it otherwise belongs to. Flavor seeds carry no host affiliation, so one odd flavor can never veto a host from a partition it matches under every other flavor.
type Seeder ¶
type Seeder interface {
// Seeds returns every (flavor, availability zone) permutation to probe,
// restricted to flavors whose hypervisor type this controller supports (see
// the hvType filter in seeder.Seeds). The topology supplies the availability
// zones (the distinct topology-zone labels of the known hypervisors); the
// flavors come from the flavor-groups Knowledge CRD. Any error aborts the
// pass, exactly like a failed scheduler probe, so partitions are never
// recomputed from a shrunken seed set.
Seeds(ctx context.Context, topo topology) ([]Seed, error)
}
Seeder produces the seeds a single calculation pass probes with. It is the first input to the pipeline, replacing the per-host vm enumeration.