Documentation
¶
Overview ¶
Package capacity computes a point-in-time breakdown of a single KVM hypervisor's capacity from the hypervisor resource and the reservations placed on it.
It separates two concerns:
Per-host arithmetic (HostUsageReport): mechanical. Given a host's capacity, its running workloads and the capacity each reservation blocks, it produces Total/Used/Reserved/Available/Oversubscribed. Available subtracts every reservation the caller passed in; which reservations count is decided before the report is built.
Per-reservation blocking policy (ReservationEffectivelyBlockedCapacity): the one reservation-type- and lifecycle-aware rule, kept here so every caller accounts reservations identically, but called out explicitly rather than hidden in the report builder.
Reserved is keyed by reservation type so no single type (failover) gets a privileged field; a consumer sums the types it cares about with ReservedTotal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HostUsageReport ¶
type HostUsageReport struct {
// Total is the schedulable capacity per resource: the effective (overcommit-adjusted)
// capacity, falling back to the raw capacity for any resource the effective map
// reports as zero or omits. A resource absent here is unknown to this host.
Total ResourceMap
// Used is capacity consumed by the workloads the hypervisor currently reports running
// (its allocation): the committed view (sum of workload sizes), not live utilisation.
Used ResourceMap
// Reserved is capacity blocked by reservations not yet backed by a running workload,
// keyed first by reservation type then by resource. Each type's inner map is the sum
// of ReservationEffectivelyBlockedCapacity over that type's counted reservations on
// this host. Consumers choose which types to account for and sum them with
// ReservedTotal; every type is subtracted from Available.
Reserved map[v1alpha1.ReservationType]ResourceMap
// Available is capacity free for a new placement: Total − Used − ReservedTotal(all),
// clamped at zero per resource. Any shortfall surfaces in Oversubscribed.
Available ResourceMap
// Oversubscribed is, per resource, how far Used + ReservedTotal(all) exceeds Total
// (absent/zero when the host is within capacity).
Oversubscribed ResourceMap
}
HostUsageReport is a point-in-time, purely arithmetic breakdown of one host's capacity. Build one with NewHostUsageReport. It carries no placement policy: Available subtracts every reservation the caller passed in; callers decide for themselves whether a demand fits (against Available, or against Total for an empty-datacenter view).
func NewHostUsageReport ¶
func NewHostUsageReport(hv hv1.Hypervisor, reservations []v1alpha1.Reservation) HostUsageReport
NewHostUsageReport computes the arithmetic report for hv from the reservations the caller has already decided should count. It always folds honestly: Available = Total − Used − Reserved(all types).
A reservation counts toward a host when its Spec.TargetHost or Status.Host equals hv.Name; one whose Spec.TargetHost is empty is treated as unplaced and never counts. Total is EffectiveCapacity, falling back per resource to raw Capacity for any resource the operator reports as zero or omits; a resource zero in both is dropped. When no resource has capacity the zero report is returned.
For an "empty host" view (what a host could hold once fully cleared), the caller passes no reservations and reads Total: with no workloads subtracted that is exactly the free capacity. There is no flag for it — a flag that still counted reservations would be a half-truth.
func (HostUsageReport) ReservedTotal ¶
func (r HostUsageReport) ReservedTotal(types ...v1alpha1.ReservationType) ResourceMap
ReservedTotal sums Reserved across the given reservation types (all types when none are passed) into one per-resource map, keeping the source quantities' formats. Use it for the combined blocked capacity rather than the per-type breakdown.
type ResourceMap ¶
type ResourceMap = map[hv1.ResourceName]resource.Quantity
ResourceMap is a per-resource quantity map keyed by hv1 resource name (cpu DecimalSI cores, memory BinarySI bytes). It is the unit every field and helper in this package speaks in.
func ReservationEffectivelyBlockedCapacity ¶
func ReservationEffectivelyBlockedCapacity(res v1alpha1.Reservation) ResourceMap
ReservationEffectivelyBlockedCapacity returns, per resource, the capacity a single reservation effectively blocks on its host right now: its reserved slot minus the workloads already running against it.
Per reservation type:
- CommittedResource, placed and confirmed (TargetHost == Status.Host, allocation present): the unconfirmed remainder of its slot, max(slot − confirmed workloads, 0) per resource, so workloads already in the hypervisor allocation are not double-counted. The full slot while mid-migration or before any allocation.
- Failover / InFlight: the full Spec.Resources (nothing is allocated against them).
- FailoverHost: the planner writes the full host capacity into Spec.Resources (it reserves an entire host), and this blocks that whole capacity regardless of lifecycle stage. New placements onto a draining failover host are kept off by filter_failover_host; this function only accounts the reserved capacity.