policy

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// ExportedResources is the basename of the file container resources are exported to.
	ExportedResources = "resources.sh"
	// ExportSharedCPUs is the shell variable used to export shared container CPUs.
	ExportSharedCPUs = "SHARED_CPUS"
	// ExportIsolatedCPUs is the shell variable used to export isolated container CPUs.
	ExportIsolatedCPUs = "ISOLATED_CPUS"
	// ExportExclusiveCPUs is the shell variable used to export exclusive container CPUs.
	ExportExclusiveCPUs = "EXCLUSIVE_CPUS"
	// ExportClaimedCPUs is the shell variable used to export the CPUs of the DRA
	// claims of a container.
	ExportClaimedCPUs = "CLAIMED_CPUS"
)
View Source
const (
	// MemoryResource is the resource name for memory
	MemoryResource = "memory"
	// CPUResource is the resource name for CPU
	CPUResource = "cpu"
	// MemsetAttribute is the attribute name for assignable memory set
	MemsetAttribute = "memory set"
	// CPUsAttribute is the attribute name for the assignable CPU set
	CPUsAttribute = "cpuset"
	// SharedCPUsAttribute is the attribute name for the assignable shared CPU set
	SharedCPUsAttribute = "shared cpuset"
	// ReservedCPUsAttribute is the attribute name for assignable the reserved CPU set
	ReservedCPUsAttribute = "reserved cpuset"
	// IsolatedCPUsAttribute is the attribute name for the assignable isolated CPU set
	IsolatedCPUsAttribute = "isolated cpuset"
	// ExcessCPUsAttribute is the attribute name for CPUs that
	// have been allocated yet not requested. For instance,
	// containers in a balloon request 1300 mCPU in total, so at
	// least 2 CPUs must be allocated to the balloon. This results
	// in excess 700 mCPUs available for bursting, for instance.
	ExcessCPUsAttribute = "excess cpus"
	// ComponentCPUsAttribute lists CPUs of components of a composite balloon
	ComponentCPUsAttribute = "component cpusets"
	// Exporting containers as topology subzones
	ContainerAllocationZoneType = "allocation for container"
)

Node resource topology resource and attribute names. XXX TODO(klihub): We'll probably need to add similar unified consts

for resource types (socket, die, NUMA node, etc.) and use them
in policies (for instance for TA pool 'kind's)

Variables

View Source
var ErrNoDRAClaims = errors.New("policy does not support DRA claims")

ErrNoDRAClaims is what AllocateClaim and ReleaseClaim return in a policy which does not support DRA claims. Such a policy publishes no DRA devices either, so no claim can name it and these are never called in practice.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Name gets the well-known name of this policy.
	Name() string
	// Description gives a verbose description about the policy implementation.
	Description() string
	// Setup initializes the policy backend with the given options.
	Setup(*BackendOptions) error
	// Reconfigure the policy backend.
	Reconfigure(any) error
	// Start up and sycnhronizes the policy, using the given cache and resource constraints.
	Start() error
	// Sync synchronizes the policy, allocating/releasing the given containers.
	Sync([]cache.Container, []cache.Container) error
	// AllocateResources allocates resources to/for a container.
	AllocateResources(cache.Container) error
	// ReleaseResources release resources of a container.
	ReleaseResources(cache.Container) error
	// UpdateResources updates resource allocations of a container.
	UpdateResources(cache.Container) error
	// ContainerStarted tells the policy that a container has started.
	ContainerStarted(cache.Container) error
	// ExportResourceData provides resource data to export for the container.
	// It stays up to date, unlike the edits of AllocateClaim, which are fixed
	// when the container starts. A policy tells a container what its DRA
	// claims gave it here. dra.ContainerClaims finds those claims.
	ExportResourceData(cache.Container) map[string]string
	// GetTopologyZones returns the policy/pool data for 'topology zone' CRDs.
	GetTopologyZones() []*TopologyZone
	// GetExtendedResources returns the node-level extended
	// resources this policy manages on the local Node. The map
	// communicates both what to publish and what the policy owns,
	// so that the agent can reconcile node state without any
	// policy-specific knowledge:
	//   - A non-nil value publishes (or replaces) the named
	//     resource with the given capacity.
	//   - A nil value marks the key as "owned but not published":
	//     if the key is a plain resource name it is removed when
	//     present; if the key contains '*' it is an ownership
	//     pattern and every matching resource currently on the
	//     Node that the policy is not publishing is removed.
	// Returning nil or an empty map means the policy owns and
	// publishes nothing.
	GetExtendedResources() map[string]*resource.Quantity
	// AllocateClaim allocates resources for a claim being prepared. results
	// are the claim's allocation results, already filtered to the devices of
	// our own driver. The returned container edits correspond to results one
	// by one, so that edits[i] belongs to results[i]. A policy with nothing to
	// add for the containers returns no edits at all.
	//
	// A policy which takes no claim configs refuses a claim that has some. A
	// policy gets the configs of a claim with dra.ClaimConfigs.
	//
	// The policy records whatever it needs to release the claim again later,
	// keyed by the claim UID, saves those records and reads them back on
	// startup. Unlike container allocations they cannot be rebuilt from the
	// running containers: a claim may have no container yet.
	//
	// Preparing a claim is not a one-off event: kubelet asks again for a
	// second pod using the claim, and again after a restart. A claim the
	// policy has already allocated must therefore allocate nothing further
	// and return the same edits as the first time.
	//
	// The policy is also the last line of defense against handing the same
	// resources to two different claims, which it can be because it alone
	// knows what it has already given out. Kubernetes tries hard to prevent
	// this, but a force-deleted pod can have its replacement's claim prepared
	// before its own containers are gone.
	AllocateClaim(
		claim *resourceapi.ResourceClaim,
		results []resourceapi.DeviceRequestAllocationResult,
	) ([]specs.ContainerEdits, error)
	// ReleaseClaim releases the resources the policy allocated for the claim
	// with the given UID. Releasing a claim the policy has no record of is
	// not an error.
	ReleaseClaim(uid types.UID) error
}

Backend is the policy (decision making logic) interface exposed by implementations.

A backends operates in a set of policy domains. Currently each policy domain corresponds to some particular hardware resource (CPU, memory, cache, etc).

type BackendOptions

type BackendOptions struct {
	// System provides system/HW/topology information
	System system.System
	// System state/cache
	Cache cache.Cache
	// Owner is the resource manager running the policy.
	Owner Owner
	// Config is the policy-specific configuration.
	Config any
}

BackendOptions describes the options for a policy backend instance

type Constraint

type Constraint any

Constraint describes constraint of one hardware domain

type ConstraintSet

type ConstraintSet map[Domain]Constraint

ConstraintSet describes, per hardware domain, the resources available for a policy.

type CpuMetric added in v0.8.0

type CpuMetric struct {
	Id             int
	IdLabel        attribute.Set
	Allocation     int
	ContainerCount int
}

type CreateFn

type CreateFn func(*BackendOptions) Backend

CreateFn is the type for functions used to create a policy instance.

type Domain

type Domain string

Domain represents a hardware resource domain that can be policied by a backend.

const (
	// DomainCPU is the CPU resource domain.
	DomainCPU Domain = "CPU"
	// DomainMemory is the memory resource domain.
	DomainMemory Domain = "Memory"
	// DomainHugePage is the hugepages resource domain.
	DomainHugePage Domain = "HugePages"
	// DomainCache is the CPU cache resource domain.
	DomainCache Domain = "Cache"
	// DomainMemoryBW is the memory resource bandwidth.
	DomainMemoryBW Domain = "MBW"
)

type Metrics

type Metrics interface {
	Describe(chan<- *prometheus.Desc)
	Collect(chan<- prometheus.Metric)
}

Metrics is the interface we expect policy-specific metrics to implement.

type NodeMetric added in v0.8.0

type NodeMetric struct {
	Id             int
	IdLabel        attribute.Set
	Capacity       int64
	Usage          int64
	ContainerCount int
}

type Options

type Options struct {
	// Owner is the resource manager running the policy.
	Owner Owner
}

Options describes policy options

type Owner added in v0.15.0

type Owner interface {
	// The resource manager holds the lock while the policy handles NRI
	// requests other than Synchronize, DRA claims and reconfiguration.
	// A policy takes it itself only for work it starts on its own, like
	// a timer firing.
	sync.Locker
	// UpdateContainers pushes the pending container changes to the runtime.
	// It must be called with the lock held.
	UpdateContainers() error
	// PublishDRADevices publishes the given DRA devices, replacing the ones
	// published before. A policy calls it whenever its devices change. The
	// devices are copied, so the policy is free to change them afterwards.
	PublishDRADevices([]resourceapi.Device) error
	// DRAListAttributesSupported tells whether DRA devices may have
	// attributes with a list of values. The API server rejects them without
	// the DRAListTypeAttributes feature gate.
	DRAListAttributesSupported() bool
}

Owner is what a policy can ask of the resource manager running it.

type Policy

type Policy interface {
	// ActivePolicy returns the name of the policy backend in use.
	ActivePolicy() string
	// Start starts up policy, prepare for serving resource management requests.
	Start(any) error
	// Reconfigure the policy.
	Reconfigure(any) error
	// Sync synchronizes the state of the active policy.
	Sync([]cache.Container, []cache.Container) error
	// AllocateResources allocates resources to a container.
	AllocateResources(cache.Container) error
	// ReleaseResources releases resources of a container.
	ReleaseResources(cache.Container) error
	// UpdateResources updates resource allocations of a container.
	UpdateResources(cache.Container) error
	// ContainerStarted tells the active policy that a container has started.
	ContainerStarted(cache.Container) error
	// ExportResourceData exports/updates resource data for the container.
	ExportResourceData(cache.Container)
	// GetTopologyZones returns the policy/pool data for 'topology zone' CRDs.
	GetTopologyZones() []*TopologyZone
	// GetExtendedResources returns the node-level extended
	// resources the active policy manages on the local Node.
	GetExtendedResources() map[string]*resource.Quantity
	// AllocateClaim allocates resources for a claim being prepared.
	AllocateClaim(
		claim *resourceapi.ResourceClaim,
		results []resourceapi.DeviceRequestAllocationResult,
	) ([]specs.ContainerEdits, error)
	// ReleaseClaim releases the resources allocated for the given claim.
	ReleaseClaim(uid types.UID) error
}

Policy is the exposed interface for container resource allocations decision making.

func NewPolicy

func NewPolicy(backend Backend, cache cache.Cache, o *Options) (Policy, error)

NewPolicy creates a policy instance using the given backend.

type SystemCollector added in v0.8.0

type SystemCollector struct {
	Nodes          map[int]*NodeMetric
	Cpus           map[int]*CpuMetric
	NodeCapacity   metric.Int64Gauge
	NodeUsage      metric.Int64Gauge
	NodeContainers metric.Int64Gauge
	CpuAllocation  metric.Int64Gauge
	CpuContainers  metric.Int64Gauge
	// contains filtered or unexported fields
}

func (*SystemCollector) Update added in v0.8.0

func (s *SystemCollector) Update()

type TopologyZone

type TopologyZone struct {
	Name       string
	Parent     string
	Type       string
	Resources  []*ZoneResource
	Attributes []*ZoneAttribute
}

TopologyZone provides policy-/pool-specific data for 'node resource topology' CRs.

type ZoneAttribute

type ZoneAttribute struct {
	Name  string
	Value string
}

ZoneAttribute represents additional, policy-specific information about a zone.

type ZoneResource

type ZoneResource struct {
	Name        string
	Capacity    resource.Quantity
	Allocatable resource.Quantity
	Available   resource.Quantity
}

ZoneResource is a resource available in some TopologyZone.

Jump to

Keyboard shortcuts

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