Documentation ¶
Index ¶
- Constants
- Variables
- func CompareCPU(ci, cj Container) int
- func CompareContainerCtime(ci, cj Container) int
- func CompareMemory(ci, cj Container) int
- func ComparePodCtime(ci, cj Container) int
- func CompareQOS(ci, cj Container) int
- func IsPodQOSClassName(class string) bool
- func SortContainers(containers []Container, compareFns ...CompareContainersFn)
- type Affinity
- type Cache
- type Cacheable
- type CompareContainersFn
- type Container
- type ContainerState
- type Device
- type Expression
- type ImplicitAffinity
- type MatchType
- type Mount
- type Options
- type PathList
- type Pod
- type PodState
Constants ¶
const ( // UserWeightCutoff is the cutoff we clamp user-provided weights to. UserWeightCutoff = 1000 // DefaultWeight is the default assigned weight if omitted in annotations. DefaultWeight int32 = 1 )
const ( // CPU marks changes that can be applied by the CPU controller. CPU = "cpu" // NRI marks changes that can be applied by NRI. NRI = "nri" // RDT marks changes that can be applied by the RDT controller. RDT = "rdt" // BlockIO marks changes that can be applied by the BlockIO controller. BlockIO = "blockio" // RDTClassKey is the pod annotation key for specifying a container RDT class. RDTClassKey = "rdtclass" + "." + kubernetes.ResmgrKeyNamespace // BlockIOClassKey is the pod annotation key for specifying a container Block I/O class. BlockIOClassKey = "blockioclass" + "." + kubernetes.ResmgrKeyNamespace // ToptierLimitKey is the pod annotation key for specifying container top tier memory limits. ToptierLimitKey = "toptierlimit" + "." + kubernetes.ResmgrKeyNamespace // RDTClassPodQoS denotes that the RDTClass should be taken from PodQosClass RDTClassPodQoS = "/PodQos" // ToptierLimitUnset is the reserved value for indicating unset top tier limits. ToptierLimitUnset int64 = -1 // TopologyHintsKey can be used to opt out from automatic topology hint generation. TopologyHintsKey = "topologyhints" + "." + kubernetes.ResmgrKeyNamespace // PreserveCpuKey means that CPU resources should not be touched. PreserveCpuKey = "cpu.preserve." + kubernetes.ResmgrKeyNamespace // PreserveMemoryKey means that memory resources should not be touched. PreserveMemoryKey = "memory.preserve." + kubernetes.ResmgrKeyNamespace // MemoryTypeKey defines memory types of containers. MemoryTypeKey = "memory-type." + kubernetes.ResmgrKeyNamespace )
const ( // ContainerStateCreating marks a container being created. ContainerStateCreating = ContainerState(nri.ContainerState_CONTAINER_UNKNOWN - 1) // ContainerStateUnknown marks a container to be in an unknown state. ContainerStateUnknown = nri.ContainerState_CONTAINER_UNKNOWN // ContainerStateCreated marks a container created, not running. ContainerStateCreated = nri.ContainerState_CONTAINER_CREATED // ContainerStateRunning marks a container created, running. ContainerStateRunning = nri.ContainerState_CONTAINER_RUNNING // ContainerStateExited marks a container exited. ContainerStateExited = nri.ContainerState_CONTAINER_STOPPED // ContainerStateStale marks a container removed. ContainerStateStale = ContainerState(nri.ContainerState_CONTAINER_STOPPED + 1) )
const (
// CacheVersion is the running version of the cache.
CacheVersion = "1"
)
Variables ¶
var ( QuotaToMilliCPU = kubernetes.QuotaToMilliCPU MilliCPUToQuota = kubernetes.MilliCPUToQuota )
var CompareByQOSMemoryCPU = []CompareContainersFn{CompareQOS, CompareMemory, CompareCPU}
CompareByQOSMemoryCPU is a slice for comparing container by QOS, memory, and CPU.
Functions ¶
func CompareCPU ¶
CompareCPU compares containers by CPU requests and limits.
func CompareContainerCtime ¶ added in v0.4.0
func CompareMemory ¶
CompareMemory compares containers by memory requests and limits.
func ComparePodCtime ¶ added in v0.4.0
func CompareQOS ¶
CompareQOS compares containers by QOS class.
func IsPodQOSClassName ¶
IsPodQOSClassName returns true if the given class is one of the Pod QOS classes.
func SortContainers ¶
func SortContainers(containers []Container, compareFns ...CompareContainersFn)
SortContainers sorts a slice of containers using the given comparison functions. If the containers are otherwise equal they are sorted by pod and container name. If the comparison functions are omitted, containers are compared by QoS class, memory and cpuset size.
Types ¶
type Affinity ¶
type Affinity struct { Scope *resmgr.Expression `json:"scope,omitempty"` // scope for evaluating this affinity Match *resmgr.Expression `json:"match"` // affinity expression Weight int32 `json:"weight,omitempty"` // (optional) weight for this affinity }
Affinity specifies a single container affinity.
func GlobalAffinity ¶
GlobalAffinity creates an affinity with all containers in scope.
func GlobalAntiAffinity ¶
GlobalAntiAffinity creates an anti-affinity with all containers in scope.
type Cache ¶
type Cache interface { // InsertPod inserts a pod into the cache, using a runtime request or reply. InsertPod(pod *nri.PodSandbox, ch <-chan *podresapi.PodResources) Pod // DeletePod deletes a pod from the cache. DeletePod(id string) Pod // LookupPod looks up a pod in the cache. LookupPod(id string) (Pod, bool) // InsertContainer inserts a container into the cache, using a runtime request or reply. InsertContainer(*nri.Container) (Container, error) // DeleteContainer deletes a container from the cache. DeleteContainer(id string) Container // LookupContainer looks up a container in the cache. LookupContainer(id string) (Container, bool) // LookupContainerByCgroup looks up a container for the given cgroup path. LookupContainerByCgroup(path string) (Container, bool) // GetPendingContainers returns all containers with pending changes. GetPendingContainers() []Container // GetPods returns all the pods known to the cache. GetPods() []Pod // GetContainers returns all the containers known to the cache. GetContainers() []Container // GetContaineIds return the ids of all containers. GetContainerIds() []string // FilterScope returns the containers selected by the scope expression. FilterScope(*resmgr.Expression) []Container // EvaluateAffinity evaluates the given affinity against all known in-scope containers EvaluateAffinity(*Affinity) map[string]int32 // AddImplicitAffinities adds a set of implicit affinities (added to all containers). AddImplicitAffinities(map[string]ImplicitAffinity) error // DeleteImplicitAffinities deletes a set of implicit affinities by name. DeleteImplicitAffinities(names ...string) // GetActivePolicy returns the name of the active policy stored in the cache. GetActivePolicy() string // SetActivePolicy updates the name of the active policy stored in the cache. SetActivePolicy(string) error // ResetActivePolicy clears the active policy any any policy-specific data from the cache. ResetActivePolicy() error // SetPolicyEntry sets the policy entry for a key. SetPolicyEntry(string, interface{}) // GetPolicyEntry gets the policy entry for a key. GetPolicyEntry(string, interface{}) bool // Save requests a cache save. Save() error // RefreshPods purges/inserts stale/new pods/containers using a pod sandbox list response. RefreshPods([]*nri.PodSandbox, <-chan *podresapi.PodResourcesList) ([]Pod, []Pod, []Container) // RefreshContainers purges/inserts stale/new containers using a container list response. RefreshContainers([]*nri.Container) ([]Container, []Container) // Get the container (data) directory for a container. ContainerDirectory(string) string // OpenFile opens the names container data file, creating it if necessary. OpenFile(string, string, os.FileMode) (*os.File, error) // WriteFile writes a container data file, creating it if necessary. WriteFile(string, string, os.FileMode, []byte) error }
Cache is the primary interface exposed for tracking pods and containers.
Cache tracks pods and containers in the runtime, mostly by processing CRI requests and responses which the cache is fed as these are being processed. Cache also saves its state upon changes to secondary storage and restores itself upon startup.
type Cacheable ¶ added in v0.8.0
type Cacheable interface { // Set value (via a pointer receiver) to the object. Set(value interface{}) // Get the object that should be cached. Get() interface{} }
type CompareContainersFn ¶
CompareContainersFn compares two containers by some arbitrary property. It returns a negative integer, 0, or a positive integer, depending on whether the first container is considered smaller, equal, or larger than the second.
type Container ¶
type Container interface { // GetPod returns the pod of the container and a boolean indicating if there was one. GetPod() (Pod, bool) // GetID returns the ID of the container. GetID() string // GetPodID returns the pod ID of the container. GetPodID() string // GetName returns the name of the container. GetName() string // GetNamespace returns the namespace of the container. GetNamespace() string // GetCtime returns the creation time of the container cache object. GetCtime() time.Time // UpdateState updates the state of the container. UpdateState(ContainerState) // GetState returns the ContainerState of the container. GetState() ContainerState // GetQOSClass returns the QoS class the pod would have if this was its only container. GetQOSClass() v1.PodQOSClass // GetArgs returns the container command arguments. GetArgs() []string // GetLabel returns the value of a container label. GetLabel(string) (string, bool) // GetAnnotation returns the value of a container annotation. GetAnnotation(key string, objPtr interface{}) (string, bool) // GetEnv returns the value of a container environment variable. GetEnv(string) (string, bool) // GetMounts returns all the mounts of the container. GetMounts() []*Mount // GetDevices returns all the linux devices of the container. GetDevices() []*Device // PrettyName returns the user-friendly $namespace/$pod/$container for the container. PrettyName() string // GetResmgrLabel returns the value of a container label from the // nri-resource-policy namespace. GetResmgrLabel(string) (string, bool) // GetResmgrAnnotation returns the value of a container annotation from the // nri-resource-policy namespace. GetResmgrAnnotation(key string, objPtr interface{}) (string, bool) // GetEffectiveAnnotation returns the effective annotation for the container from the pod. GetEffectiveAnnotation(key string) (string, bool) // Containers can be subject for expression evaluation. resmgr.Evaluable // Expand a string with possible key references. Expand(string, bool) (string, error) // We have String() for containers. fmt.Stringer // GetResourceRequirements returns the resource requirements for this container. // The requirements are calculated from the containers cgroup parameters. GetResourceRequirements() v1.ResourceRequirements // GetPodResources gets container-specific resources acquired from podresourceapi. GetPodResources() *podresapi.ContainerResources // SetResourceUpdates sets updated resources for a container. Returns true if the // resources were really updated. SetResourceUpdates(*nri.LinuxResources) bool // GetResourceUpdates() returns any updated resource requirements for this container. // The updates are calculated from the cgroups parameters in the resource update. GetResourceUpdates() (v1.ResourceRequirements, bool) // InsertMount inserts a mount into the container. InsertMount(*Mount) // Get any attached topology hints. GetTopologyHints() topology.Hints SetCPUShares(int64) // SetCPUQuota sets the CFS CPU quota of the container. SetCPUQuota(int64) // SetCPUPeriod sets the CFS CPU period of the container. SetCPUPeriod(int64) // SetCpusetCpu sets the cgroup cpuset.cpus of the container. SetCpusetCpus(string) // SetCpusetMems sets the cgroup cpuset.mems of the container. SetCpusetMems(string) // SetMemoryLimit sets the memory limit in bytes for the container. SetMemoryLimit(int64) // SetMemorySwap sets the swap limit in bytes for the container. SetMemorySwap(int64) GetCPUShares() int64 // GetCPUQuota gets the CFS CPU quota of the container. GetCPUQuota() int64 // GetCPUPeriod gets the CFS CPU period of the container. GetCPUPeriod() int64 // GetCpusetCpu gets the cgroup cpuset.cpus of the container. GetCpusetCpus() string // GetCpusetMems gets the cgroup cpuset.mems of the container. GetCpusetMems() string // GetMemoryLimit gets the memory limit in bytes for the container. GetMemoryLimit() int64 // GetMemorySwap gets the swap limit in bytes for the container. GetMemorySwap() int64 // PreserveCpuResources() returns true if CPU resources of the // container must not be changed. PreserveCpuResources() bool // PreserveMemoryResources() returns true if memory resources // of the container must not be changed. PreserveMemoryResources() bool // MemoryTypes() returns memory type mask. The default is 0. MemoryTypes() (libmem.TypeMask, error) // GetPendingAdjusmentn clears and returns any pending adjustment for the container. GetPendingAdjustment() *nri.ContainerAdjustment // GetPendingUpdate clears and returns any pending update for the container. GetPendingUpdate() *nri.ContainerUpdate // GetAffinity returns the annotated affinity expressions for this container. GetAffinity() ([]*Affinity, error) // GetCgroupDir returns the relative path of the cgroup directory for the container. GetCgroupDir() string // SetRDTClass assigns this container to the given RDT class. SetRDTClass(string) // GetRDTClass returns the RDT class for this container. GetRDTClass() string // SetBlockIOClass assigns this container to the given BlockIO class. SetBlockIOClass(string) // GetBlockIOClass returns the BlockIO class for this container. GetBlockIOClass() string // GetProcesses returns the pids of processes in the container. GetProcesses() ([]string, error) // GetTasks returns the pids of threads in the container. GetTasks() ([]string, error) // GetPending gets the names of the controllers with pending changes. GetPending() []string // HasPending checks if the container has pending chanhes for the given controller. HasPending(string) bool // ClearPending clears the pending change marker for the given controller. ClearPending(string) // GetTag gets the value of the given tag. GetTag(string) (string, bool) // SetTag sets the value of the given tag and returns its previous value.. SetTag(string, string) (string, bool) // DeleteTag deletes the given tag, returning its deleted value. DeleteTag(string) (string, bool) }
Container is the exposed interface from a cached container.
type ContainerState ¶
type ContainerState = nri.ContainerState
ContainerState is the container state in the runtime.
type Device ¶
type Device = nri.LinuxDevice
type Expression ¶
type Expression struct {
resmgr.Expression
}
Expression is used to describe affinity container scope and matching criteria.
type ImplicitAffinity ¶
ImplicitAffinity can implicitly inject affinities to containers.
type Options ¶
type Options struct { // CacheDir is the directory the cache should save its state in. CacheDir string }
Options contains the configurable cache options.
type Pod ¶
type Pod interface { // GetContainers returns the containers of the pod. GetContainers() []Container // GetId returns the pod id of the pod. GetID() string // GetUID returns the (kubernetes) unique id of the pod. GetUID() string // GetName returns the name of the pod. GetName() string // GetNamespace returns the namespace of the pod. GetNamespace() string // GetCtime returns the creation time of the pod cache object. GetCtime() time.Time // GetQOSClass returns the PodQOSClass of the pod. GetQOSClass() v1.PodQOSClass // GetLabel returns the value of the given label and whether it was found. GetLabel(string) (string, bool) // GetAnnotation returns the value of the given annotation and whether it was found. GetAnnotation(key string) (string, bool) // GetCgroupParent returns the pods cgroup parent directory. GetCgroupParent() string // PrettyName returns $namespace/$name as the pretty name for the pod. PrettyName() string // GetResmgrLabel returns the value of a pod label from the // nri-resource-policy namespace. GetResmgrLabel(string) (string, bool) // GetAnnotation returns the value of a pod annotation from the // nri-resource-policy namespace and whether it was found. GetResmgrAnnotation(key string) (string, bool) // GetEffectiveAnnotation returns the effective annotation for a container. // For any given key $K and container $C it will look for annotations in // this order and return the first one found: // $K/container.$C // $K/pod // $K // and return the value of the first key found. GetEffectiveAnnotation(key, container string) (string, bool) // GetPodResources returns the pod resources for this pod, waiting for any // pending fetch to complete or a timeout. GetPodResources() *podresapi.PodResources // GetContainerAffinity returns the affinity expressions for the named container. GetContainerAffinity(string) ([]*Affinity, error) // ScopeExpression returns an affinity expression for defining this pod as the scope. ScopeExpression() *resmgr.Expression // Pods can be subject for expression evaluation. resmgr.Evaluable // Expand a string with possible key references. Expand(string, bool) (string, error) // We have String() for pods. fmt.Stringer // GetProcesses returns the pids of all processes in the pod either excluding // container processes, if called with false, or including those if called with true. GetProcesses(bool) ([]string, error) // GetTasks returns the pids of all threads in the pod either excluding container // processes, if called with false, or including those if called with true. GetTasks(bool) ([]string, error) }
Pod is the exposed interface from a cached pod.