capacity

package
v0.0.0-...-df5969a 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: 30 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

View Source
const (
	ResourceMemory = "memory"
	ResourceCores  = "cores"
)

Resource keys used for capacity splitting. Match CommittedResourceType constants.

Variables

This section is empty.

Functions

func LoggerFromContext

func LoggerFromContext(ctx context.Context) logr.Logger

LoggerFromContext returns a logger with greq and req values from the context. This creates a child logger with the request tracking values pre-attached, so you don't need to repeat them in every log call.

func SplitCapacity

func SplitCapacity(groups []GroupInput, hosts map[string]HostState) (freeResources, exclusiveResources map[string]map[string]int64, unassigned map[string]int64, strandedByHost map[string]map[string]int64, exclusiveHosts map[string][]string)

SplitCapacity runs the round-robin capacity assignment algorithm.

For each AZ it assigns resources (in raw units — bytes for memory, count for cores) to flavor groups in a fair, deterministic way such that no host is over-committed. Groups sharing hypervisors are served round-robin so no group monopolises shared hosts.

Returns:

  • freeResources[groupName]resource: sum of remaining resources across all candidate hosts for each group before the split. May overlap across groups sharing hosts.
  • exclusiveResources[groupName]resource: fairly attributed share after the split; sum across groups never exceeds actual installed capacity.
  • unassigned[resource]: resources on candidate hosts not claimed by any group due to fragmentation (for operator log visibility).
  • exclusiveHosts[groupName]: unique host names assigned to the group by the split. Each host appears in at most one group's list.

The caller divides exclusiveResources[group]ResourceMemory by the group's flavor memory to obtain the slot count meaningful to that group.

func WithNewGlobalRequestID

func WithNewGlobalRequestID(ctx context.Context) context.Context

WithNewGlobalRequestID creates a new context with a capacity-prefixed global request ID.

Types

type Config

type Config struct {
	// ReconcileInterval is the periodic floor: how often the reconciler re-runs even without a
	// watch event. Acts as a fallback for changes not covered by watches (e.g. blocked memory drift).
	ReconcileInterval metav1.Duration `json:"capacityReconcileInterval"`

	// MinReconcileInterval is the minimum time between two consecutive reconcile runs.
	// If Reconcile() is called sooner than this since the last successful run, it returns early
	// with RequeueAfter set to the remaining duration. Prevents back-to-back reconciles on rapid
	// watch events (e.g. a batch of CommittedResource updates).
	MinReconcileInterval metav1.Duration `json:"capacityMinReconcileInterval"`

	// TotalPipeline is the scheduler pipeline used for the empty-state probe.
	TotalPipeline string `json:"capacityTotalPipeline"`

	// PlaceablePipeline is the scheduler pipeline used for the current-state probe.
	// This pipeline considers current VM allocations to determine remaining placement capacity.
	PlaceablePipeline string `json:"capacityPlaceablePipeline"`
}

Config holds configuration for the capacity reconciler.

func DefaultConfig

func DefaultConfig() Config

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults fills in any unset values with defaults.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the config is internally consistent after defaults are applied.

type GroupInput

type GroupInput struct {
	Name            string
	FlavorResources map[string]int64
	CandidateHosts  []string
}

type HostState

type HostState struct {
	Remaining map[string]int64
}

type Monitor

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

Monitor provides Prometheus metrics for FlavorGroupCapacity CRDs. It implements prometheus.Collector and reads CRD status on each Collect call.

func NewMonitor

func NewMonitor(c client.Client) Monitor

NewMonitor creates a new Monitor that reads FlavorGroupCapacity CRDs.

func (*Monitor) Collect

func (m *Monitor) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector — lists all FlavorGroupCapacity CRDs and exports gauges.

func (*Monitor) Describe

func (m *Monitor) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

type Reconciler

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

Reconciler reconciles FlavorGroupCapacity CRDs, driven by both watch events and a periodic floor timer. All watch events are coalesced into a single reconcile key so rapid changes produce at most one queued reconcile.

func NewController

func NewController(c client.Client, config Config, vmSource reservations.VMSource, scheduler *sched.Placement) *Reconciler

func (*Reconciler) Reconcile

func (c *Reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error)

Reconcile implements reconcile.Reconciler. It is called by controller-runtime whenever a watched CRD changes, and also on the periodic RequeueAfter floor set by ReconcileInterval. If called sooner than MinReconcileInterval since the last successful run, it returns early.

func (*Reconciler) SetupWithManager

func (c *Reconciler) SetupWithManager(mgr ctrl.Manager, mcl *multicluster.Client) error

SetupWithManager registers the reconciler with the controller manager and sets up watches on all CRDs that affect capacity output. All events are coalesced to a single key.

Jump to

Keyboard shortcuts

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