Documentation ¶
Index ¶
- Constants
- Variables
- func AddResources(a, b v1.ResourceList) v1.ResourceList
- func ApplyPodResources(resources map[string]v1.ResourceRequirements, pod *v1.Pod)
- func CalculateUnstructuredTotalResources(object *unstructured.Unstructured) (v1.ResourceList, v1.ResourceList)
- func CheckDaemonPod(pod *v1.Pod) bool
- func CheckObjectEqual(obj1, obj2 metav1.Object) bool
- func CheckQosClassChanged(resources map[string]v1.ResourceRequirements, pod *v1.Pod) (bool, error)
- func EmitResourceMetrics(name string, resourceList v1.ResourceList, tags map[string]string, ...)
- func FilterOutDeletingUnstructured(objList []*unstructured.Unstructured) []*unstructured.Unstructured
- func FilterOutSkipEvictionPods(pods []*v1.Pod, filterOutAnnotations, filterOutLabels sets.String) []*v1.Pod
- func FilterPods(pods []*v1.Pod, filterFunc func(*v1.Pod) (bool, error)) []*v1.Pod
- func GenerateContainerName(containerName string) consts.ContainerName
- func GenerateNamespaceNameKey(namespace, name string) string
- func GenerateObjectOwnerReferenceKey(reference metav1.OwnerReference) string
- func GeneratePodContainerName(podName, containerName string) consts.PodContainerName
- func GenerateUniqGVRNameKey(gvr string, workload metav1.Object) (string, error)
- func GenerateUniqObjectNameKey(obj metav1.Object) string
- func GenerateUniqObjectUIDKey(obj metav1.Object) string
- func GetCPUQuantity(resourceList v1.ResourceList) resource.Quantity
- func GetMemoryQuantity(resourceList v1.ResourceList) resource.Quantity
- func GetNamespacedNameListFromSlice(podSlice []*v1.Pod) []string
- func GetNonzeroQoSRequests(requests *v1.ResourceList) (int64, int64)
- func GetPodListForWorkload(workloadObj runtime.Object, podIndexer cache.Indexer, labelKeyList []string, ...) ([]*core.Pod, error)
- func GetPodNamespaceNameKeyMap(podList []*v1.Pod) map[string]*v1.Pod
- func GetRequestForQoSResource(resource v1.ResourceName, requests *v1.ResourceList, nonZero bool) int64
- func GetUnstructuredSelector(object *unstructured.Unstructured) (labels.Selector, error)
- func IsAssignedPod(pod *v1.Pod) bool
- func IsResourceGreaterThan(a resource.Quantity, b resource.Quantity) bool
- func MakeWorkloadInformers(workLoads []string, mapper meta.RESTMapper, ...) (map[string]WorkloadInformer, error)
- func MergeResources(updateList ...v1.ResourceList) v1.ResourceList
- func NewPodSourceImpList(pods []*v1.Pod) general.SourceList
- func NodeReady(node *v1.Node) bool
- func ObjectOwnerReferenceIndex(o interface{}) ([]string, error)
- func ParseContainerName(key consts.ContainerName) string
- func ParseHostPortsForContainer(container *v1.Container, portName string) []int32
- func ParseHostPortsForPod(pod *v1.Pod, portName string) []int32
- func ParsePodContainerName(key consts.PodContainerName) (string, string, error)
- func ParseUniqGVRNameKey(key string) (gvr string, namespace string, name string, err error)
- func PodAndContainersAreTerminal(pod *v1.Pod) (containersTerminal, podWorkerTerminal bool)
- func PodAnnotationFilter(pod *v1.Pod, key, value string) bool
- func PodCPURequestCmpFunc(i1, i2 interface{}) int
- func PodIsActive(pod *v1.Pod) bool
- func PodIsReady(pod *v1.Pod) bool
- func PodIsTerminated(pod *v1.Pod) bool
- func PodPriorityCmpFunc(i1, i2 interface{}) int
- func PodResourceDiff(pod *v1.Pod, containerResourcesToUpdate map[string]v1.ResourceRequirements) bool
- func ResourceQuantityToInt64Value(resourceName v1.ResourceName, quantity resource.Quantity) int64
- func ResourcesEqual(a, b v1.ResourceList) bool
- func SumUpPodLimitResources(pod *v1.Pod) v1.ResourceList
- func SumUpPodRequestResources(pod *v1.Pod) v1.ResourceList
- func ToSchemaGVR(group, version, resource string) schema.GroupVersionResource
- func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error)
- func TrimContainerIDPrefix(id string) string
- func VisitUnstructuredAncestors(object *unstructured.Unstructured, ...) bool
- type PodLabelIndexer
- type PodSourceList
- type QoSResource
- type WorkloadInformer
Constants ¶
const ( // DefaultReclaimedMilliCPURequest defines default milli reclaimed milli-cpu request number. DefaultReclaimedMilliCPURequest int64 = 100 // 0.1 core // DefaultReclaimedMemoryRequest defines default reclaimed memory request size. DefaultReclaimedMemoryRequest int64 = 200 * 1024 * 1024 // 200 MiB )
For each of these resources, a pod that doesn't request the resource explicitly will be treated as having requested the amount indicated below, for the purpose of computing priority only. This ensures that when scheduling zero-request pods, such pods will not all be scheduled to the machine with the smallest in-use request, and that when scheduling regular pods, such pods will not see zero-request pods as consuming no resources whatsoever. We chose these values to be similar to the resources that we give to cluster addon pods (#10653). But they are pretty arbitrary. As described in #11713, we use request instead of limit to deal with resource requirements.
const ContainerMetricPortName = "metrics"
const ContainerMetricStorePortName = "store"
Variables ¶
Functions ¶
func AddResources ¶
func AddResources(a, b v1.ResourceList) v1.ResourceList
AddResources sums up two ResourceList, and returns the summed as results.
func ApplyPodResources ¶
func ApplyPodResources(resources map[string]v1.ResourceRequirements, pod *v1.Pod)
ApplyPodResources is used to apply map[string]v1.ResourceRequirements to the given pod, and ignore the container-names / resource-names that not appear in the given map param
func CalculateUnstructuredTotalResources ¶
func CalculateUnstructuredTotalResources(object *unstructured.Unstructured) (v1.ResourceList, v1.ResourceList)
CalculateUnstructuredTotalResources returns the total resources of the unstructured object's pod template
func CheckDaemonPod ¶
CheckDaemonPod returns true if pod is for DaemonSet
func CheckObjectEqual ¶
CheckObjectEqual returns true if uid equals or the namespace/name pair equal
func CheckQosClassChanged ¶
CheckQosClassChanged checks whether the pod's QosClass will change if annotationResources are applied to this pod
func EmitResourceMetrics ¶
func EmitResourceMetrics(name string, resourceList v1.ResourceList, tags map[string]string, emitter metrics.MetricEmitter)
EmitResourceMetrics emit metrics for given ResourceList.
func FilterOutDeletingUnstructured ¶
func FilterOutDeletingUnstructured(objList []*unstructured.Unstructured) []*unstructured.Unstructured
func FilterOutSkipEvictionPods ¶
func FilterOutSkipEvictionPods(pods []*v1.Pod, filterOutAnnotations, filterOutLabels sets.String) []*v1.Pod
FilterOutSkipEvictionPods return pods should be candidates to evict including native critical pods and user-defined filtered pods
func FilterPods ¶
FilterPods filter pods that filter func return true.
func GenerateContainerName ¶
func GenerateContainerName(containerName string) consts.ContainerName
GenerateContainerName return a unique key for a container
func GenerateNamespaceNameKey ¶
GenerateNamespaceNameKey generate uniq key by concatenating namespace and name.
func GenerateObjectOwnerReferenceKey ¶
func GenerateObjectOwnerReferenceKey(reference metav1.OwnerReference) string
GenerateObjectOwnerReferenceKey is to generate a unique key by owner reference
func GeneratePodContainerName ¶
func GeneratePodContainerName(podName, containerName string) consts.PodContainerName
GeneratePodContainerName return a unique key for a container in a pod
func GenerateUniqGVRNameKey ¶
GenerateUniqGVRNameKey generate a uniq key (without UID) for the GVR and its corresponding object.
func GenerateUniqObjectNameKey ¶
GenerateUniqObjectNameKey generate a uniq key (without UID) for the given object.
func GenerateUniqObjectUIDKey ¶
GenerateUniqObjectUIDKey generate a uniq key (including UID) for the given object.
func GetCPUQuantity ¶
func GetCPUQuantity(resourceList v1.ResourceList) resource.Quantity
GetCPUQuantity returns cpu quantity for resourceList. since we may have different representations for cpu resource name, the prioritizes will be: native cpu name -> reclaimed milli cpu name
func GetMemoryQuantity ¶
func GetMemoryQuantity(resourceList v1.ResourceList) resource.Quantity
GetMemoryQuantity returns memory quantity for resourceList. since we may have different representations for memory resource name, the prioritizes will be: native memory name -> reclaimed memory name
func GetNamespacedNameListFromSlice ¶
GetNamespacedNameListFromSlice returns a slice of namespaced name
func GetNonzeroQoSRequests ¶
func GetNonzeroQoSRequests(requests *v1.ResourceList) (int64, int64)
GetNonzeroQoSRequests returns the default reclaimed_millicpu and reclaimed_memory resource request if none is found or what is provided on the request.
func GetPodListForWorkload ¶
func GetPodListForWorkload(workloadObj runtime.Object, podIndexer cache.Indexer, labelKeyList []string, podLister corelisters.PodLister) ([]*core.Pod, error)
GetPodListForWorkload returns pod list that belong to the given workload we will use label selector to find pods, and this may require that the given workload is limited to several selected objects.
func GetRequestForQoSResource ¶
func GetRequestForQoSResource(resource v1.ResourceName, requests *v1.ResourceList, nonZero bool) int64
GetRequestForQoSResource returns the requested values unless nonZero is true and there is no defined request for CPU and memory. If nonZero is true and the resource has no defined request for CPU or memory, it returns a default value.
func GetUnstructuredSelector ¶
func GetUnstructuredSelector(object *unstructured.Unstructured) (labels.Selector, error)
GetUnstructuredSelector parse a unstructured object and return its labelSelector (for pods)
func IsAssignedPod ¶
IsAssignedPod selects pods that are assigned (scheduled and running).
func IsResourceGreaterThan ¶
IsResourceGreaterThan checks if recommended resource is scaling down
func MakeWorkloadInformers ¶
func MakeWorkloadInformers( workLoads []string, mapper meta.RESTMapper, dynamicInformerFactory dynamicinformer.DynamicSharedInformerFactory, ) (map[string]WorkloadInformer, error)
MakeWorkloadInformers generate informers for workloads dynamically with rest-mapper
func MergeResources ¶
func MergeResources(updateList ...v1.ResourceList) v1.ResourceList
MergeResources merge multi ResourceList into one ResourceList, the resource of same resource name in all ResourceList we only use the first merged one.
func NewPodSourceImpList ¶
func NewPodSourceImpList(pods []*v1.Pod) general.SourceList
func ObjectOwnerReferenceIndex ¶
ObjectOwnerReferenceIndex is used by informer to index a resource by owner
func ParseContainerName ¶
func ParseContainerName(key consts.ContainerName) string
ParseContainerName parse key and return container name
func ParseHostPortsForContainer ¶
ParseHostPortsForContainer gets host port from container spec
func ParseHostPortsForPod ¶
ParseHostPortsForPod gets host ports from pod spec
func ParsePodContainerName ¶
func ParsePodContainerName(key consts.PodContainerName) (string, string, error)
ParsePodContainerName parse key and return pod name and container name
func ParseUniqGVRNameKey ¶
ParseUniqGVRNameKey parse the given key into GPR and namespace/name
func PodAnnotationFilter ¶
PodAnnotationFilter is used to filter pods annotated with a pair of specific key and value
func PodCPURequestCmpFunc ¶
func PodCPURequestCmpFunc(i1, i2 interface{}) int
PodCPURequestCmpFunc sorts cpu request of pods with less comparison
func PodIsActive ¶
PodIsActive returns whether the pod is not terminated.
func PodIsReady ¶
PodIsReady returns whether the pod is at ready state.
func PodIsTerminated ¶
PodIsTerminated returns whether the pod is at terminal state.
func PodPriorityCmpFunc ¶
func PodPriorityCmpFunc(i1, i2 interface{}) int
PodPriorityCmpFunc sorts priority of pods with greater comparison
func PodResourceDiff ¶
func PodResourceDiff(pod *v1.Pod, containerResourcesToUpdate map[string]v1.ResourceRequirements) bool
PodResourceDiff checks if pod resources (both for requests and limits) are NOT the same as the given resource map,
func ResourceQuantityToInt64Value ¶
func ResourceQuantityToInt64Value(resourceName v1.ResourceName, quantity resource.Quantity) int64
ResourceQuantityToInt64Value returns the int64 value according to its resource name
func ResourcesEqual ¶
func ResourcesEqual(a, b v1.ResourceList) bool
ResourcesEqual checks whether the given resources are equal with each other
func SumUpPodLimitResources ¶
func SumUpPodLimitResources(pod *v1.Pod) v1.ResourceList
SumUpPodLimitResources sum up resources in all containers request init container is included (count on the max limit of all init containers)
func SumUpPodRequestResources ¶
func SumUpPodRequestResources(pod *v1.Pod) v1.ResourceList
SumUpPodRequestResources sum up resources in all containers request init container is included (count on the max request of all init containers)
func ToSchemaGVR ¶
func ToSchemaGVR(group, version, resource string) schema.GroupVersionResource
func ToUnstructured ¶
func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error)
func TrimContainerIDPrefix ¶
TrimContainerIDPrefix is used to parse the specific containerID out of the whole containerID info
func VisitUnstructuredAncestors ¶
func VisitUnstructuredAncestors(object *unstructured.Unstructured, unstructuredMap map[schema.GroupVersionKind]cache.GenericLister, handleFunc func(owner *unstructured.Unstructured) bool) bool
VisitUnstructuredAncestors is to walk through all the ancestors of the given object, during this process, we will try to handle each ancestor with the given util function. if the handleFunc returns true, it means that we should continue the walking process for other ancestors, otherwise, we break the process and return.
Types ¶
type PodLabelIndexer ¶
type PodLabelIndexer string
func (PodLabelIndexer) IndexFunc ¶
func (p PodLabelIndexer) IndexFunc(obj interface{}) ([]string, error)
IndexFunc is used to construct informer index for labels in pod
type PodSourceList ¶
type PodSourceList struct {
// contains filtered or unexported fields
}
func (*PodSourceList) GetSource ¶
func (pl *PodSourceList) GetSource(index int) interface{}
func (*PodSourceList) Len ¶
func (pl *PodSourceList) Len() int
func (*PodSourceList) SetSource ¶
func (pl *PodSourceList) SetSource(index int, p interface{})
type QoSResource ¶
QoSResource is a collection of compute resource.
func CalculateQoSResource ¶
func CalculateQoSResource(pod *v1.Pod) (res QoSResource, non0CPU int64, non0Mem int64)
CalculateQoSResource calculates the QoS Resource of a Pod resourceRequest = max(sum(podSpec.Containers), podSpec.InitContainers) + overHead
func (*QoSResource) Add ¶
func (r *QoSResource) Add(rl v1.ResourceList)
Add adds ResourceList into QoSResource.
func (*QoSResource) SetMaxResource ¶
func (r *QoSResource) SetMaxResource(rl v1.ResourceList)
SetMaxResource compares with ResourceList and takes max value for each QoSResource.
type WorkloadInformer ¶
type WorkloadInformer struct { GVK *schema.GroupVersionKind GVR *schema.GroupVersionResource Informer informers.GenericInformer }
WorkloadInformer keeps the informer-related contents for each workload