native

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const ContainerMetricPortName = "metrics"
View Source
const ContainerMetricStorePortName = "store"

Variables

View Source
var GetPodHostIP = func(pod *v1.Pod) (string, error) {
	if pod == nil {
		return "", fmt.Errorf("empty pod")
	}

	hostIP := pod.Status.HostIP
	if len(hostIP) == 0 {
		return "", fmt.Errorf("empty hostIP")
	}

	return hostIP, nil
}

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 CheckContainerNotRunning

func CheckContainerNotRunning(pod *v1.Pod, containerName string) (bool, error)

CheckContainerNotRunning returns whether the given container is not-runnin

func CheckDaemonPod

func CheckDaemonPod(pod *v1.Pod) bool

CheckDaemonPod returns true if pod is for DaemonSet

func CheckObjectEqual

func CheckObjectEqual(obj1, obj2 metav1.Object) bool

CheckObjectEqual returns true if uid equals or the namespace/name pair equal

func CheckQosClassChanged

func CheckQosClassChanged(resources map[string]v1.ResourceRequirements, pod *v1.Pod) (bool, error)

CheckQosClassChanged checks whether the pod's QosClass will change if annotationResources are applied to this pod

func DeepCopyPodContainers

func DeepCopyPodContainers(pod *v1.Pod) (containers []v1.Container)

DeepCopyPodContainers returns a deep-copied objects for v1.Container slice

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 FilterPodAnnotations

func FilterPodAnnotations(filterKeys []string, pod *v1.Pod) map[string]string

FilterPodAnnotations returns the needed annotations for the given pod.

func FilterPods

func FilterPods(pods []*v1.Pod, filterFunc func(*v1.Pod) (bool, error)) []*v1.Pod

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 GenerateDynamicResourceByGVR

func GenerateDynamicResourceByGVR(gvr schema.GroupVersionResource) string

GenerateDynamicResourceByGVR generates dynamic resource by given gvr, the format is such as `resource.version.group`, which can be input of ParseResourceArg

func GenerateNamespaceNameKey

func GenerateNamespaceNameKey(namespace, name string) string

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

func GenerateUniqGVRNameKey(gvr string, workload metav1.Object) (string, error)

GenerateUniqGVRNameKey generate a uniq key (without UID) for the GVR and its corresponding object.

func GenerateUniqObjectNameKey

func GenerateUniqObjectNameKey(obj metav1.Object) string

GenerateUniqObjectNameKey generate a uniq key (without UID) for the given object.

func GenerateUniqObjectUIDKey

func GenerateUniqObjectUIDKey(obj metav1.Object) string

GenerateUniqObjectUIDKey generate a uniq key (including UID) for the given object.

func GetAndUnmarshalForHttps

func GetAndUnmarshalForHttps(ctx context.Context, port int, nodeAddress, endpoint, authTokenFile string, v interface{}) error

GetAndUnmarshalForHttps gets data from the given url and unmarshal it into the given struct.

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 GetContainerEnvs

func GetContainerEnvs(pod *v1.Pod, containerName string, envs ...string) map[string]string

GetContainerEnvs gets container envs from pod spec by container name and envs name

func GetContainerID

func GetContainerID(pod *v1.Pod, containerName string) (string, error)

GetContainerID gets container id from pod status by container 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

func GetNamespacedNameListFromSlice(podSlice []*v1.Pod) []string

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 GetPodCondition

func GetPodCondition(pod *v1.Pod, conditionType v1.PodConditionType) (v1.PodCondition, bool)

GetPodCondition extracts the given condition for the given pod

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 GetPodNamespaceNameKeyMap

func GetPodNamespaceNameKeyMap(podList []*v1.Pod) map[string]*v1.Pod

func GetPodTransformer

func GetPodTransformer() (cache.TransformFunc, bool)

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

func IsAssignedPod(pod *v1.Pod) bool

IsAssignedPod selects pods that are assigned (scheduled and running).

func IsResourceGreaterThan

func IsResourceGreaterThan(a resource.Quantity, b resource.Quantity) bool

IsResourceGreaterThan checks if recommended resource is scaling down

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 NodeReady

func NodeReady(node *v1.Node) bool

func ObjectOwnerReferenceIndex

func ObjectOwnerReferenceIndex(o interface{}) ([]string, error)

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

func ParseHostPortsForContainer(container *v1.Container, portName string) []int32

ParseHostPortsForContainer gets host port from container spec

func ParseHostPortsForPod

func ParseHostPortsForPod(pod *v1.Pod, portName string) []int32

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

func ParseUniqGVRNameKey(key string) (gvr string, namespace string, name string, err error)

ParseUniqGVRNameKey parse the given key into GVR and namespace/name

func PodAndContainersAreTerminal

func PodAndContainersAreTerminal(pod *v1.Pod) (containersTerminal, podWorkerTerminal bool)

func PodAnnotationFilter

func PodAnnotationFilter(pod *v1.Pod, key, value string) bool

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

func PodIsActive(pod *v1.Pod) bool

PodIsActive returns whether the pod is not terminated.

func PodIsReady

func PodIsReady(pod *v1.Pod) bool

PodIsReady returns whether the pod is at ready state.

func PodIsTerminated

func PodIsTerminated(pod *v1.Pod) bool

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 are not the same as the given resource map, both for requests and limits.

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

func TrimContainerIDPrefix(id string) string

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.

func WithPodTransformer

func WithPodTransformer(f PodTransformerFunc)

Types

type DynamicInformer

type DynamicInformer struct {
	GVK      schema.GroupVersionKind
	GVR      schema.GroupVersionResource
	Informer informers.GenericInformer
}

DynamicInformer keeps the informer-related contents for each workload

type DynamicResourcesManager

type DynamicResourcesManager struct {
	// contains filtered or unexported fields
}

func NewDynamicResourcesManager

func NewDynamicResourcesManager(
	dynamicResources []string,
	mapper *dynamicmapper.RegeneratingDiscoveryRESTMapper,
	dynamicInformerFactory dynamicinformer.DynamicSharedInformerFactory,
) (*DynamicResourcesManager, error)

NewDynamicResourcesManager initializes a dynamic resources manger to manage dynamic informers

func (*DynamicResourcesManager) GetDynamicInformers

func (m *DynamicResourcesManager) GetDynamicInformers() map[string]DynamicInformer

GetDynamicInformers gets current dynamic informers

func (*DynamicResourcesManager) Run

Run start mapper to refresh starts a goroutine to check if it has new gvr support available, and if so, panics to restart to make sure all caches are correct

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 PodTransformerFunc

type PodTransformerFunc func(src, dest *corev1.Pod)

type QoSResource

type QoSResource struct {
	ReclaimedMilliCPU int64
	ReclaimedMemory   int64
}

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 ResourceThreshold

type ResourceThreshold map[v1.ResourceName]float64

ResourceThreshold is map of resource name to threshold of water level

func (*ResourceThreshold) Set

func (t *ResourceThreshold) Set(value string) error

func (*ResourceThreshold) String

func (t *ResourceThreshold) String() string

func (*ResourceThreshold) Type

func (t *ResourceThreshold) Type() string

Jump to

Keyboard shortcuts

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