limits

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package limits holds the caps the cluster owns on devices, labs and tenants. The chart sets them (values limits.*); the management agent enforces them on CreateLabs and reports them in GetFeatures, and the planning profile (the default of a device without resources) is the one the scheduler counts with.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSat added in v1.6.0

func AddSat(a, b int64) int64

AddSat is a + b for non-negative amounts, MaxInt64 instead of an overflow.

func DevicePodResources added in v1.7.0

func DevicePodResources(spec *laboratoryv1alpha1.DeviceResources, defaults DeviceDefaults) (requests, limits corev1.ResourceList)

DevicePodResources returns the requests and the limits of a device container. Memory is one amount for both (limit, else request, else the default). CPU may burst: the request is cpuRequest (else cpuLimit, else the default) and the limit is cpuLimit (else the request), never below the request. A quantity that does not parse, is zero or negative (it would remove the limit) or is beyond the absolute bound is skipped, and one above the chart maximum is clamped to it, so an object that predates the validation cannot run a pod without limits. Both nil when nothing is set.

func DeviceQuantity

func DeviceQuantity(s string, cpu bool) (int64, error)

DeviceQuantity parses a device cpu (millicores) or memory (bytes) value the way a tenant may write it: it must be positive and within the absolute bound. A zero value would remove the pod limit, a negative or an overflowing one would skew the sums. Quantities are compared as quantities, so an exponent that overflows int64 is refused, not wrapped.

func DeviceRequests added in v1.7.0

DeviceRequests is what the scheduler, the quotas and the reservations count for a device container: the requests of DevicePodResources. The CPU limit above it is a burst that nothing plans with. Nil when nothing is set.

func LabNeed added in v1.6.0

func LabNeed(spec *laboratoryv1alpha1.LabSpec, defaults DeviceDefaults) (cpu, mem int64)

LabNeed is what the pods of a lab's container devices request together, as the scheduler counts them (DeviceRequests per device; switches and hubs run no pod).

Types

type Config

type Config struct {
	DeviceMaxCPU        string `env:"DEVICE_MAX_CPU" envDefault:"2000m"`
	DeviceMaxMemory     string `env:"DEVICE_MAX_MEMORY" envDefault:"4Gi"`
	DeviceDefaultCPU    string `env:"DEVICE_DEFAULT_CPU" envDefault:"100m"`
	DeviceDefaultMemory string `env:"DEVICE_DEFAULT_MEMORY" envDefault:"256Mi"`
	// LabMaxDevices caps the devices of one lab, switches and hubs included (0 = the platform ceiling, names.MaxLabDevices).
	LabMaxDevices int `env:"AGENT_LIMIT_LAB_MAX_DEVICES" envDefault:"32"`
	// GroupMaxLabs caps the labs of one LabGroup (0 = no limit); GroupMaxCPU and GroupMaxMemory cap the sum of
	// the resources of the devices of all its labs (the planning profile counts for a device without resources;
	// "0" = no limit).
	GroupMaxLabs   int    `env:"AGENT_LIMIT_GROUP_MAX_LABS" envDefault:"50"`
	GroupMaxCPU    string `env:"AGENT_LIMIT_GROUP_MAX_CPU" envDefault:"0"`
	GroupMaxMemory string `env:"AGENT_LIMIT_GROUP_MAX_MEMORY" envDefault:"0"`
	TenantMaxLabs  int    `env:"AGENT_LIMIT_TENANT_MAX_LABS" envDefault:"0"`
}

Config is read by the agent from the environment the chart gives it. CPU is a Kubernetes quantity ("500m", "2"), memory too ("512Mi"). The defaults mirror values.yaml. The DEVICE_* names are the operator's (the same chart values limits.device.*).

func (Config) Parse

func (c Config) Parse() (Limits, error)

Parse validates the quantities and the counts.

type DeviceDefaults added in v1.6.0

type DeviceDefaults struct {
	CPU    string
	Memory string
	// MaxCPU and MaxMemory are the chart maxima of one device (limits.device.max*): a larger value of an existing
	// object is clamped to them. Empty or "0" = no maximum beyond the absolute bound of the limits package.
	MaxCPU    string
	MaxMemory string
}

DeviceDefaults are the CPU and memory of a device container that declares none. Empty strings leave the resource unset.

type Limits

type Limits struct {
	DeviceMaxCPU, DeviceMaxMemory         int64
	DeviceDefaultCPU, DeviceDefaultMemory int64
	LabMaxDevices                         int
	GroupMaxLabs                          int
	GroupMaxCPU, GroupMaxMemory           int64
	TenantMaxLabs                         int
}

Limits is Config parsed: CPU in millicores, memory in bytes. A zero cap means no limit.

func (Limits) CheckSpec

func (l Limits) CheckSpec(spec *laboratoryv1alpha1.LabSpec) error

CheckSpec refuses a lab spec that passes a cap: too many devices (every type counts), too many interfaces on a device (16 on a container, 48 on a switch or hub), or a device over the device maximum. The message names the numbers.

func (Limits) DeviceResources

func (l Limits) DeviceResources(r *laboratoryv1alpha1.DeviceResources) (cpu, mem int64, err error)

DeviceResources is what a device is planned with. Memory: its limit, else its request, else the default. CPU: its request, else its limit, else the default (a CPU limit above the request is a burst and is not planned). A quantity that does not parse is an error.

func (Limits) GroupFits

func (l Limits) GroupFits(labs int, cpu, mem, addCPU, addMem int64) error

GroupFits says whether a group that already holds labs labs planned at cpu and mem can take one more lab of the given totals; the error says which cap stops it.

func (Limits) SpecTotals

func (l Limits) SpecTotals(spec *laboratoryv1alpha1.LabSpec) (cpu, mem int64, containers int, err error)

SpecTotals is the CPU (millicores) and memory (bytes) the container devices of a spec are planned with, and how many there are. A quantity that does not parse is an error naming the device.

Jump to

Keyboard shortcuts

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