state

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StaticPools are generated by cpu plugin statically,
	// and they will be ignored when reading cpu advisor list and watch response.
	StaticPools = sets.NewString(
		commonstate.PoolNameReserve,
	)

	// ResidentPools are guaranteed existing in state,
	// and they are usually used to ensure stability.
	ResidentPools = sets.NewString(
		commonstate.PoolNameReclaim,
	).Union(StaticPools)
)

Functions

func CPUPreciseCeil added in v0.5.10

func CPUPreciseCeil(request float64) int

CPUPreciseCeil we can not use math.Ceil directly here, because the cpu requests are stored using floats, there is a chance of precision issues during addition calculations. in critical case: - the allocatable cpu of the node is 122 - the sum of allocated cpu requests is 118.00000000000001 (after ceil is 119), - the new pod request is 4 119 + 4 > 122, so qrm will reject the new pod.

func CheckAllocationInfoOriginTopologyAwareAssignments added in v0.5.9

func CheckAllocationInfoOriginTopologyAwareAssignments(ai1, ai2 *AllocationInfo) bool

func CheckAllocationInfoTopologyAwareAssignments added in v0.5.9

func CheckAllocationInfoTopologyAwareAssignments(ai1, ai2 *AllocationInfo) bool

func CountAllocationInfosToPoolsQuantityMap added in v0.5.4

func CountAllocationInfosToPoolsQuantityMap(allocationInfos []*AllocationInfo,
	poolsQuantityMap map[string]map[int]int,
	getContainerRequestedCores GetContainerRequestedCoresFunc,
) error

func GetCPUIncrRatio added in v0.5.4

func GetCPUIncrRatio(allocationInfo *AllocationInfo) float64

func GetIsolatedQuantityMapFromPodEntries

func GetIsolatedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocationInfos []*AllocationInfo, getContainerRequestedCores GetContainerRequestedCoresFunc) map[string]map[string]int

GetIsolatedQuantityMapFromPodEntries returns a map to indicates isolation info, and the map is formatted as pod -> container -> isolated-quantity

func GetNonBindingSharedRequestedQuantityFromPodEntries added in v0.5.4

func GetNonBindingSharedRequestedQuantityFromPodEntries(podEntries PodEntries, newNonBindingSharedRequestedQuantity map[string]float64, getContainerRequestedCores GetContainerRequestedCoresFunc) int

GetNonBindingSharedRequestedQuantityFromPodEntries returns total quanity shared_cores without numa_binding requested

func GetSharedBindingNUMAsFromQuantityMap added in v0.5.4

func GetSharedBindingNUMAsFromQuantityMap(poolsQuantityMap map[string]map[int]int) sets.Int

func GetSharedNUMABindingTargetNuma added in v0.5.9

func GetSharedNUMABindingTargetNuma(allocationInfo *AllocationInfo) (int, error)

func GetSharedQuantityMapFromPodEntries added in v0.2.0

func GetSharedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocationInfos []*AllocationInfo, getContainerRequestedCores GetContainerRequestedCoresFunc) (map[string]map[int]int, error)

GetSharedQuantityMapFromPodEntries returns a map to indicates quantity info for each shared pool, and the map is formatted as pool -> quantity

func WrapAllocationMetaFilter added in v0.5.12

func WrapAllocationMetaFilter(metaFilter func(meta *commonstate.AllocationMeta) bool) func(info *AllocationInfo) bool

WrapAllocationMetaFilter takes a filter function that operates on AllocationMeta and returns a wrapper function that applies the same filter to an AllocationInfo by extracting its AllocationMeta.

func WrapAllocationMetaFilterWithAnnotations added in v0.5.12

func WrapAllocationMetaFilterWithAnnotations(
	metaFilter func(meta *commonstate.AllocationMeta, annotations map[string]string) bool,
) func(info *AllocationInfo, annotations map[string]string) bool

WrapAllocationMetaFilterWithAnnotations takes a filter function that operates on AllocationMeta and returns a wrapper function that applies the same filter to an AllocationInfo by extracting its AllocationMeta and input annotations of candidate.

Types

type AllocationInfo

type AllocationInfo struct {
	commonstate.AllocationMeta `json:",inline"`

	RampUp bool `json:"ramp_up,omitempty"`

	AllocationResult         machine.CPUSet `json:"allocation_result,omitempty"`
	OriginalAllocationResult machine.CPUSet `json:"original_allocation_result,omitempty"`

	// key by numa node id, value is assignment for the pod in corresponding NUMA node
	TopologyAwareAssignments map[int]machine.CPUSet `json:"topology_aware_assignments"`
	// key by numa node id, value is assignment for the pod in corresponding NUMA node
	OriginalTopologyAwareAssignments map[int]machine.CPUSet `json:"original_topology_aware_assignments"`
	// for ramp up calculation. notice we don't use time.Time type here to avid checksum corruption.
	InitTimestamp string `json:"init_timestamp"`

	RequestQuantity float64 `json:"request_quantity,omitempty"`
}

func (*AllocationInfo) Clone

func (ai *AllocationInfo) Clone() *AllocationInfo

func (*AllocationInfo) GetAllocationResultNUMASet added in v0.5.4

func (ai *AllocationInfo) GetAllocationResultNUMASet() machine.CPUSet

GetAllocationResultNUMASet returns numaSet parsed from TopologyAwareAssignments

func (*AllocationInfo) GetPodAggregatedRequest added in v0.5.9

func (ai *AllocationInfo) GetPodAggregatedRequest() (float64, bool)

func (*AllocationInfo) String

func (ai *AllocationInfo) String() string

type CPUPluginCheckpoint

type CPUPluginCheckpoint struct {
	PolicyName                            string            `json:"policyName"`
	MachineState                          NUMANodeMap       `json:"machineState"`
	PodEntries                            PodEntries        `json:"pod_entries"`
	AllowSharedCoresOverlapReclaimedCores bool              `json:"allow_shared_cores_overlap_reclaimed_cores"`
	Checksum                              checksum.Checksum `json:"checksum"`
}

func NewCPUPluginCheckpoint

func NewCPUPluginCheckpoint() *CPUPluginCheckpoint

func (*CPUPluginCheckpoint) MarshalCheckpoint

func (cp *CPUPluginCheckpoint) MarshalCheckpoint() ([]byte, error)

MarshalCheckpoint returns marshaled checkpoint

func (*CPUPluginCheckpoint) UnmarshalCheckpoint

func (cp *CPUPluginCheckpoint) UnmarshalCheckpoint(blob []byte) error

UnmarshalCheckpoint tries to unmarshal passed bytes to checkpoint

func (*CPUPluginCheckpoint) VerifyChecksum

func (cp *CPUPluginCheckpoint) VerifyChecksum() error

VerifyChecksum verifies that current checksum of checkpoint is valid

type ContainerEntries

type ContainerEntries map[string]*AllocationInfo // Keyed by containerName.

func (ContainerEntries) GetMainContainerEntry added in v0.2.0

func (ce ContainerEntries) GetMainContainerEntry() *AllocationInfo

GetMainContainerEntry returns the main container entry in pod container entries

func (ContainerEntries) GetMainContainerPoolName added in v0.2.0

func (ce ContainerEntries) GetMainContainerPoolName() string

GetMainContainerPoolName returns the main container owner pool name in pod container entries

func (ContainerEntries) GetPoolEntry

func (ce ContainerEntries) GetPoolEntry() *AllocationInfo

func (ContainerEntries) IsPoolEntry

func (ce ContainerEntries) IsPoolEntry() bool

IsPoolEntry returns true if this entry is for a pool; otherwise, this entry is for a container entity.

type GenerateMachineStateFromPodEntriesFunc added in v0.5.12

type GenerateMachineStateFromPodEntriesFunc func(topology *machine.CPUTopology, podEntries PodEntries) (NUMANodeMap, error)

type GetContainerRequestedCoresFunc added in v0.5.10

type GetContainerRequestedCoresFunc func(allocationInfo *AllocationInfo) float64

type NUMANodeMap

type NUMANodeMap map[int]*NUMANodeState // keyed by numa node id

func GenerateMachineStateFromPodEntries added in v0.2.0

func GenerateMachineStateFromPodEntries(topology *machine.CPUTopology, podEntries PodEntries) (NUMANodeMap, error)

GenerateMachineStateFromPodEntries for dynamic policy

func GenerateMachineStateFromPodEntriesByPolicy added in v0.5.12

func GenerateMachineStateFromPodEntriesByPolicy(topology *machine.CPUTopology, podEntries PodEntries, policyName string) (NUMANodeMap, error)

GenerateMachineStateFromPodEntriesByPolicy returns NUMANodeMap for given resource based on machine info and reserved resources along with existed pod entries and policy name todo: extracting entire state package as a common standalone utility

func GetDefaultMachineState

func GetDefaultMachineState(topology *machine.CPUTopology) NUMANodeMap

func (NUMANodeMap) Clone

func (nm NUMANodeMap) Clone() NUMANodeMap

func (NUMANodeMap) GetAvailableCPUSet added in v0.3.0

func (nm NUMANodeMap) GetAvailableCPUSet(reservedCPUs machine.CPUSet) machine.CPUSet

GetAvailableCPUSet returns available cpuset in this node

func (NUMANodeMap) GetDefaultCPUSet

func (nm NUMANodeMap) GetDefaultCPUSet() machine.CPUSet

GetDefaultCPUSet returns default cpuset in this node

func (NUMANodeMap) GetFilteredAvailableCPUSet added in v0.2.0

func (nm NUMANodeMap) GetFilteredAvailableCPUSet(reservedCPUs machine.CPUSet,
	excludeEntry, excludeWholeNUMA func(ai *AllocationInfo) bool,
) machine.CPUSet

GetFilteredAvailableCPUSet returns available cpuset in this node, along with the filter functions

func (NUMANodeMap) GetFilteredDefaultCPUSet added in v0.2.0

func (nm NUMANodeMap) GetFilteredDefaultCPUSet(excludeEntry, excludeWholeNUMA func(ai *AllocationInfo) bool) machine.CPUSet

GetFilteredDefaultCPUSet returns default cpuset in this node, along with the filter functions

func (NUMANodeMap) GetFilteredNUMASet added in v0.3.0

func (nm NUMANodeMap) GetFilteredNUMASet(excludeNUMAPredicate func(ai *AllocationInfo) bool) machine.CPUSet

GetFilteredNUMASet return numa set except the numa which are excluded by the predicate.

func (NUMANodeMap) GetFilteredNUMASetWithAnnotations added in v0.5.4

func (nm NUMANodeMap) GetFilteredNUMASetWithAnnotations(
	excludeNUMAPredicate func(ai *AllocationInfo, annotations map[string]string) bool,
	annotations map[string]string,
) machine.CPUSet

GetFilteredNUMASetWithAnnotations return numa set except the numa which are excluded by the predicate accepting AllocationInfo in the target NUMA and input annotations of candidate.

func (NUMANodeMap) String

func (nm NUMANodeMap) String() string

type NUMANodeState

type NUMANodeState struct {
	// equals to allocatable cpuset subtracting original allocation result of dedicated_cores with NUMA binding
	DefaultCPUSet machine.CPUSet `json:"default_cpuset,omitempty"`
	// equals to original allocation result of dedicated_cores with NUMA binding
	AllocatedCPUSet machine.CPUSet `json:"allocated_cpuset,omitempty"`

	PodEntries PodEntries `json:"pod_entries"`
}

func (*NUMANodeState) Clone

func (ns *NUMANodeState) Clone() *NUMANodeState

func (*NUMANodeState) ExistMatchedAllocationInfo added in v0.3.0

func (ns *NUMANodeState) ExistMatchedAllocationInfo(f func(ai *AllocationInfo) bool) bool

ExistMatchedAllocationInfo returns true if the stated predicate holds true for some pods of this numa else it returns false.

func (*NUMANodeState) ExistMatchedAllocationInfoWithAnnotations added in v0.5.4

func (ns *NUMANodeState) ExistMatchedAllocationInfoWithAnnotations(
	f func(ai *AllocationInfo, annotations map[string]string) bool,
	annotations map[string]string,
) bool

ExistMatchedAllocationInfoWithAnnotations returns true if the stated predicate (with annotations of candidate) holds true for some pods of this numa else it returns false.

func (*NUMANodeState) GetAvailableCPUQuantity added in v0.5.4

func (ns *NUMANodeState) GetAvailableCPUQuantity(reservedCPUs machine.CPUSet) float64

GetAvailableCPUQuantity calculates available quantity by allocatable - sum(requested) It's used when allocating CPUs for shared_cores with numa_binding containers, since pool size may be adjusted, and DefaultCPUSet & AllocatedCPUSet are calculated by pool size, we should use allocationInfo.RequestQuantity to calculate available cpu quantity for candidate shared_cores with numa_binding container.

func (*NUMANodeState) GetAvailableCPUSet

func (ns *NUMANodeState) GetAvailableCPUSet(reservedCPUs machine.CPUSet) machine.CPUSet

GetAvailableCPUSet returns available cpuset in this numa

func (*NUMANodeState) GetFilteredDefaultCPUSet added in v0.2.0

func (ns *NUMANodeState) GetFilteredDefaultCPUSet(excludeEntry, excludeWholeNUMA func(ai *AllocationInfo) bool) machine.CPUSet

GetFilteredDefaultCPUSet returns default cpuset in this numa, along with the filter functions

func (*NUMANodeState) SetAllocationInfo

func (ns *NUMANodeState) SetAllocationInfo(podUID string, containerName string, allocationInfo *AllocationInfo)

type PodEntries

type PodEntries map[string]ContainerEntries // Keyed by podUID.

func (PodEntries) CheckPoolEmpty added in v0.2.0

func (pe PodEntries) CheckPoolEmpty(poolName string) bool

CheckPoolEmpty returns true if the given pool doesn't exist

func (PodEntries) Clone

func (pe PodEntries) Clone() PodEntries

func (PodEntries) GetCPUSetForPool added in v0.2.0

func (pe PodEntries) GetCPUSetForPool(poolName string) (machine.CPUSet, error)

GetCPUSetForPool returns cpuset that belongs to the given pool

func (PodEntries) GetFilteredPodEntries added in v0.2.0

func (pe PodEntries) GetFilteredPodEntries(filter func(ai *AllocationInfo) bool) PodEntries

GetFilteredPodEntries filter out PodEntries according to the given filter logic

func (PodEntries) GetFilteredPoolsCPUSet added in v0.2.0

func (pe PodEntries) GetFilteredPoolsCPUSet(ignorePools sets.String) machine.CPUSet

GetFilteredPoolsCPUSet returns a mapping of pools for all of them (except for those skipped ones)

func (PodEntries) GetFilteredPoolsCPUSetMap added in v0.2.0

func (pe PodEntries) GetFilteredPoolsCPUSetMap(ignorePools sets.String) (map[string]map[int]machine.CPUSet, error)

GetFilteredPoolsCPUSetMap returns a mapping of pools for all of them (except for those skipped ones)

func (PodEntries) String

func (pe PodEntries) String() string

type ReadonlyState

type ReadonlyState interface {
	// contains filtered or unexported methods
}

ReadonlyState interface only provides methods for tracking pod assignments

type State

type State interface {
	// contains filtered or unexported methods
}

State interface provides methods for tracking and setting pod assignments

func NewCPUPluginState

func NewCPUPluginState(topology *machine.CPUTopology) State

func NewCheckpointState

func NewCheckpointState(stateDir, checkpointName, policyName string,
	topology *machine.CPUTopology, skipStateCorruption bool, generateMachineStateFunc GenerateMachineStateFromPodEntriesFunc,
) (State, error)

Jump to

Keyboard shortcuts

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