crs

package
v0.0.0-...-ccb81e8 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyNoHostFound

func ClassifyNoHostFound(
	activeCRs []v1alpha1.CommittedResource,
	evaluator *SlotEvaluator,
	inputHosts []string,
	projectID, flavorGroupName string,
	vmMemBytes int64,
) string

ClassifyNoHostFound determines why no host was found for a nova placement request, in terms of committed resource coverage:

  • no_cr: project has no active CommittedResources for the flavor group (NH1)
  • cr_exhausted: CommittedResources exist but are fully occupied (NH2)
  • slot_exhausted: CR has remaining capacity but no input host has a usable slot (NH3)
  • slot_blocked: a usable slot exists but scheduling constraints excluded all such hosts (NH4)

func ClassifyPlacement

func ClassifyPlacement(
	evaluator *SlotEvaluator,
	activeCRs []v1alpha1.CommittedResource,
	candidateHosts []string,
	projectID, flavorGroupName string,
) string

ClassifyPlacement determines the CR slot outcome for a successful placement:

  • no_cr: no active CR or CR capacity fully exhausted (H1)
  • slot_missed: CR has remaining capacity but no candidate host has a slot with remaining > 0 (H2)
  • slot_used: CR has remaining capacity and at least one candidate host has a slot with remaining > 0 (H3)

func NewNoHostFoundCounter

func NewNoHostFoundCounter() *prometheus.CounterVec

NewNoHostFoundCounter creates the Prometheus counter for no-host-found classification. Register it with the metrics registry before assigning it to the Recorder.

func NewPlacementCounter

func NewPlacementCounter() *prometheus.CounterVec

NewPlacementCounter creates the Prometheus counter for successful Nova placements. Labels: flavor_group, intent, cr_slot (no_cr/slot_missed/slot_used/error). PAYG placements (flavor not in any group) are not counted — they return before reaching this counter. cr_slot=error is emitted when the flavor group lookup fails due to a K8s error. Register it with the metrics registry before assigning it to the Recorder.

func PickSlot

func PickSlot(candidates []v1alpha1.Reservation, vmMemoryBytes int64) string

PickSlot selects the best reservation slot for a new VM. A slot is usable if it has any remaining memory (overfill is allowed: the VM may exceed the slot's remaining capacity, with the overflow covered by the host's free capacity which the pipeline already verified). Selection: maximise coverage (min(remMem, vmMemoryBytes)), tiebreak by smallest remaining memory (tightest fit), then reservation name. Returns the slot name, or "" if no slot has any remaining memory.

func ReservationRemainingMemory

func ReservationRemainingMemory(res v1alpha1.Reservation) int64

ReservationRemainingMemory returns how many bytes of memory remain unallocated in a reservation slot. Returns 0 if the slot is nil or fully consumed.

Types

type Recorder

type Recorder struct {
	// Client is the Kubernetes client used to read and patch Reservation CRDs.
	client.Client

	// NoHostFoundCounter counts no-host-found results by CR slot outcome.
	NoHostFoundCounter *prometheus.CounterVec
	// PlacementCounter counts successful placements by CR slot outcome.
	PlacementCounter *prometheus.CounterVec
}

Recorder receives scheduling outcomes and updates CR reservations and metrics accordingly.

func (*Recorder) RecordNoHostFound

func (r *Recorder) RecordNoHostFound(ctx context.Context, intent v1alpha1.SchedulingIntent, request api.ExternalSchedulerRequest)

RecordNoHostFound classifies a no-host-found result and emits a log line and metric.

func (*Recorder) RecordPlacement

func (r *Recorder) RecordPlacement(ctx context.Context, result sched.PlacementResult, intent v1alpha1.SchedulingIntent, request api.ExternalSchedulerRequest)

RecordPlacement writes the placed VM UUID into the matching Reservation slot and emits placement metrics. Called after a successful Nova placement.

type SlotEvaluator

type SlotEvaluator struct {
	// contains filtered or unexported fields
}

SlotEvaluator provides post-pipeline evaluation of CR reservation slots. Build once per request from HV and Reservation CRDs; query without further reads.

func BuildSlotEvaluator

func BuildSlotEvaluator(ctx context.Context, c client.Client) (*SlotEvaluator, error)

BuildSlotEvaluator lists HV CRDs and CR Reservation CRDs once and returns an evaluator that can answer slot-usability queries without further K8s reads.

func BuildSlotEvaluatorFromReservations

func BuildSlotEvaluatorFromReservations(ctx context.Context, c client.Client, reservations []v1alpha1.Reservation) (*SlotEvaluator, error)

BuildSlotEvaluatorFromReservations builds a SlotEvaluator from an already-fetched reservation slice. Use this when the caller has already listed reservations to avoid a redundant K8s read.

func (*SlotEvaluator) CanAccommodateSlot

func (e *SlotEvaluator) CanAccommodateSlot(hostName string, requiredBytes int64) bool

CanAccommodateSlot reports whether hostName has enough free memory to absorb a reservation block of requiredBytes. Used to check whether a slot can follow a migrating VM to this host via the reconciler, even when no existing compatible slot is present.

Free memory is computed as: hvFreeMemory - sum(all ready committed-resource reservation blocks on host).

func (*SlotEvaluator) HasSlotWithCapacity

func (e *SlotEvaluator) HasSlotWithCapacity(hostName, projectID, flavorGroup string, requiredBytes int64) bool

HasSlotWithCapacity reports whether hostName has at least one ready CR slot matching projectID + flavorGroup whose remaining memory is >= requiredBytes. Unlike HasUsableSlot, this does not apply the overfill model — it is used during migration slot filtering where the full slot size must fit within a single reservation on the target host.

func (*SlotEvaluator) HasUsableSlot

func (e *SlotEvaluator) HasUsableSlot(hostName, projectID, flavorGroup string, vmMemBytes int64) bool

HasUsableSlot reports whether hostName has at least one CR slot that can accommodate a VM of vmMemBytes under the overfill model:

slot.remaining + host.base_free >= vmMemBytes

where host.base_free = hvFreeMemory[host] - sum(all reservation blocks on host). On happy-path candidates the pipeline already guarantees host capacity, so this simplifies to slot.remaining > 0 — but the full formula is evaluated regardless.

func (*SlotEvaluator) SlotsForHost

func (e *SlotEvaluator) SlotsForHost(hostName, projectID, flavorGroup string) []v1alpha1.Reservation

SlotsForHost returns all CR reservation slots on hostName matching projectID + flavorGroup.

Jump to

Keyboard shortcuts

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