state

package
v0.5.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	PoolNameShare           = "share"
	PoolNameReclaim         = "reclaim"
	PoolNameDedicated       = "dedicated"
	PoolNameReserve         = "reserve"
	PoolNamePrefixIsolation = "isolation"

	// PoolNameFallback is not a real pool, and is a union of
	// all none-reclaimed pools to put pod should have been isolated
	PoolNameFallback = "fallback"
)

notice that pool-name may not have direct mapping relations with qos-level, for instance - both isolated_shared_cores and dedicated_cores fall into PoolNameDedicated

View Source
const (
	EmptyOwnerPoolName = ""
	FakedContainerName = ""
	FakedNUMAID        = -1
	NameSeparator      = "#"
	NUMAPoolInfix      = "-NUMA"
)

FakedContainerName represents a placeholder since pool entry has no container-level FakedNUMAID represents a placeholder since pools like shared/reclaimed will not contain a specific numa

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(
		PoolNameReserve,
	)

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

Functions

func CheckDedicated added in v0.2.0

func CheckDedicated(ai *AllocationInfo) bool

CheckDedicated returns true if the AllocationInfo is for pod with dedicated-qos

func CheckDedicatedNUMABinding added in v0.2.0

func CheckDedicatedNUMABinding(ai *AllocationInfo) bool

CheckDedicatedNUMABinding returns true if the AllocationInfo is for pod with dedicated-qos and numa-binding enhancement

func CheckDedicatedPool added in v0.3.0

func CheckDedicatedPool(ai *AllocationInfo) bool

CheckDedicatedPool returns true if the AllocationInfo is for a container in the dedicated pool

func CheckNUMABinding added in v0.2.0

func CheckNUMABinding(ai *AllocationInfo) bool

CheckNUMABinding returns true if the AllocationInfo is for pod with numa-binding enhancement

func CheckNUMABindingSharedCoresAntiAffinity added in v0.5.4

func CheckNUMABindingSharedCoresAntiAffinity(ai *AllocationInfo, annotations map[string]string) bool

CheckNUMABindingSharedCoresAntiAffinity returns true if the AllocationInfo isn't compatible for the annotations of a numa binding shared cores candidate

func CheckReclaimed added in v0.2.0

func CheckReclaimed(ai *AllocationInfo) bool

CheckReclaimed returns true if the AllocationInfo is for pod with reclaimed-qos

func CheckShared added in v0.2.0

func CheckShared(ai *AllocationInfo) bool

CheckShared returns true if the AllocationInfo is for pod with shared-qos

func CheckSharedNUMABinding added in v0.5.4

func CheckSharedNUMABinding(ai *AllocationInfo) bool

CheckSharedNUMABinding returns true if the AllocationInfo is for pod with shared-qos and numa-binding enhancement

func CountAllocationInfosToPoolsQuantityMap added in v0.5.4

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

func GetCPUIncrRatio added in v0.5.4

func GetCPUIncrRatio(allocationInfo *AllocationInfo) float64

func GetContainerRequestedCores

func GetContainerRequestedCores() func(allocationInfo *AllocationInfo) float64

func GetIsolatedQuantityMapFromPodEntries

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

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

func GetNUMAPoolName added in v0.5.4

func GetNUMAPoolName(candidateSpecifiedPoolName string, targetNUMANode uint64) string

func GetNonBindingSharedRequestedQuantityFromPodEntries added in v0.5.4

func GetNonBindingSharedRequestedQuantityFromPodEntries(podEntries PodEntries) int

GetTotoalSharedQuantity returns total quanity shared_cores without numa_binding requested

func GetPoolType added in v0.4.0

func GetPoolType(poolName string) string

func GetSharedBindingNUMAsFromQuantityMap added in v0.5.4

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

func GetSharedQuantityMapFromPodEntries added in v0.2.0

func GetSharedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocationInfos []*AllocationInfo) (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 GetSpecifiedPoolName

func GetSpecifiedPoolName(qosLevel, cpusetEnhancementValue string) string

GetSpecifiedPoolName todo: this function (along with pool-name consts) should be moved to generic qos conf

func IsIsolationPool added in v0.3.0

func IsIsolationPool(poolName string) bool

func SetContainerRequestedCores added in v0.3.0

func SetContainerRequestedCores(f func(allocationInfo *AllocationInfo) float64)

Types

type AllocationInfo

type AllocationInfo struct {
	PodUid                   string         `json:"pod_uid,omitempty"`
	PodNamespace             string         `json:"pod_namespace,omitempty"`
	PodName                  string         `json:"pod_name,omitempty"`
	ContainerName            string         `json:"container_name,omitempty"`
	ContainerType            string         `json:"container_type,omitempty"`
	ContainerIndex           uint64         `json:"container_index,omitempty"`
	RampUp                   bool           `json:"ramp_up,omitempty"`
	OwnerPoolName            string         `json:"owner_pool_name,omitempty"`
	PodRole                  string         `json:"pod_role,omitempty"`
	PodType                  string         `json:"pod_type,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"`

	Labels          map[string]string `json:"labels"`
	Annotations     map[string]string `json:"annotations"`
	QoSLevel        string            `json:"qosLevel"`
	RequestQuantity float64           `json:"request_quantity,omitempty"`
}

func (*AllocationInfo) CheckMainContainer added in v0.2.0

func (ai *AllocationInfo) CheckMainContainer() bool

CheckMainContainer returns true if the AllocationInfo is for main container

func (*AllocationInfo) CheckSideCar added in v0.2.0

func (ai *AllocationInfo) CheckSideCar() bool

CheckSideCar returns true if the AllocationInfo is for side-car container

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) GetOwnerPoolName added in v0.2.0

func (ai *AllocationInfo) GetOwnerPoolName() string

GetOwnerPoolName parses the owner pool name for AllocationInfo

func (*AllocationInfo) GetPoolName added in v0.2.0

func (ai *AllocationInfo) GetPoolName() string

GetPoolName parses the owner pool name for AllocationInfo if owner exists, just return; otherwise, parse from qos-level

func (*AllocationInfo) GetSpecifiedNUMABindingPoolName added in v0.5.4

func (ai *AllocationInfo) GetSpecifiedNUMABindingPoolName() (string, error)

GetSpecifiedNUMABindingPoolName get numa_binding pool name for numa_binding shared_cores according to enhancements and NUMA hint

func (*AllocationInfo) GetSpecifiedPoolName added in v0.2.0

func (ai *AllocationInfo) GetSpecifiedPoolName() string

GetSpecifiedPoolName parses the owner pool name for AllocationInfo from qos-level

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 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, policyName string) (NUMANodeMap, error)

GenerateMachineStateFromPodEntries returns NUMANodeMap for given resource based on machine info and reserved resources along with existed pod entries

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

ExistMatchedAllocationInfo 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) int

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,
) (State, error)

Jump to

Keyboard shortcuts

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