native

package
v0.5.15 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 39 Imported by: 37

Documentation

Index

Constants

View Source
const (
	ContainerMetricPortName      = "metrics"
	ContainerMetricStorePortName = "store"
)
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.

Variables

View Source
var GetPodHostIPs = func(pod *v1.Pod) ([]string, bool) {
	ip, ok := GetPodHostIP(pod)
	if !ok {
		return []string{}, false
	}
	return []string{ip}, true
}

Functions

func AddNodeNameIndexerForPod added in v0.4.2

func AddNodeNameIndexerForPod(podInformer v1.PodInformer) error

AddNodeNameIndexerForPod add node name index for pod informer

func AddResources

func AddResources(a, b v1.ResourceList) v1.ResourceList

AddResources sums up two ResourceList, and returns the summed as results.

func AggregateAvgQuantities added in v0.4.1

func AggregateAvgQuantities(quantities []resource.Quantity) *resource.Quantity

AggregateAvgQuantities get the average of the quantities

func AggregateMaxQuantities added in v0.4.1

func AggregateMaxQuantities(quantities []resource.Quantity) *resource.Quantity

AggregateMaxQuantities get the maximum of the quantities

func AggregateSumQuantities added in v0.4.1

func AggregateSumQuantities(quantities []resource.Quantity) *resource.Quantity

AggregateSumQuantities get the sum of quantities

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 CalculateResource added in v0.4.0

func CalculateResource(pod *v1.Pod) v1.ResourceList

CalculateResource resourceRequest = max(sum(podSpec.Containers), podSpec.InitContainers)

func CheckContainerNotRunning added in v0.3.0

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

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

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

func DefaultCPUQuantityGetter added in v0.4.0

func DefaultCPUQuantityGetter(resourceList v1.ResourceList) resource.Quantity

DefaultCPUQuantityGetter 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 DefaultMemoryQuantityGetter added in v0.4.0

func DefaultMemoryQuantityGetter(resourceList v1.ResourceList) resource.Quantity

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

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

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 added in v0.3.0

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

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

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

GetContainerID gets container id from pod status by container 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 added in v0.2.0

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

GetPodCondition extracts the given condition for the given pod

func GetPodHostIP

func GetPodHostIP(pod *v1.Pod) (string, bool)

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

func GetPodTransformer() (cache.TransformFunc, bool)

func GetPodsAssignedToNode added in v0.4.2

func GetPodsAssignedToNode(nodeName string, podIndexer cache.Indexer) ([]*core.Pod, error)

GetPodsAssignedToNode returns pods that belong to this node by indexer

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 GetUnstructuredPodTemplateSpec added in v0.4.1

func GetUnstructuredPodTemplateSpec(object *unstructured.Unstructured) (*v1.PodTemplateSpec, error)

func GetUnstructuredSelector

func GetUnstructuredSelector(object *unstructured.Unstructured) (labels.Selector, error)

GetUnstructuredSelector parse a unstructured object and return its labelSelector (for pods)

func GetUnstructuredTemplateAnnotations added in v0.4.0

func GetUnstructuredTemplateAnnotations(object *unstructured.Unstructured) (map[string]string, error)

GetUnstructuredTemplateAnnotations parse a unstructured object and return its template's annotations (for workload like deployments, statefulsets)

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 MultiplyMilliQuantity added in v0.4.0

func MultiplyMilliQuantity(quantity resource.Quantity, y float64) resource.Quantity

MultiplyMilliQuantity scales quantity by y.

func MultiplyQuantity added in v0.4.0

func MultiplyQuantity(quantity resource.Quantity, y float64) resource.Quantity

MultiplyQuantity scales quantity by y.

func MultiplyResourceQuantity added in v0.4.0

func MultiplyResourceQuantity(resourceName v1.ResourceName, quantity resource.Quantity, y float64) resource.Quantity

MultiplyResourceQuantity scales quantity according to its resource name.

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 ParseHostPortForPod added in v0.4.0

func ParseHostPortForPod(pod *v1.Pod, portName string) (int32, bool)

ParseHostPortForPod gets host ports from pod spec

func ParseHostPortsForContainer

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

ParseHostPortsForContainer gets host port from container spec

func ParseNamespaceNameUIDKey added in v0.4.0

func ParseNamespaceNameUIDKey(key string) (string, string, string, error)

ParseNamespaceNameUIDKey parse the given key into namespace/name/uid

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 ParseUniqObjectUIDKey added in v0.4.0

func ParseUniqObjectUIDKey(key string) (namespace string, name string, uid string, err error)

ParseUniqObjectUIDKey parse the given key into namespace, name and uid

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 PodGuaranteedCPUs added in v0.5.0

func PodGuaranteedCPUs(pod *v1.Pod) int

func PodIsActive

func PodIsActive(pod *v1.Pod) bool

PodIsActive returns whether the pod is not terminated.

func PodIsPending added in v0.4.0

func PodIsPending(pod *v1.Pod) bool

PodIsPending returns whether the pod is pending.

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 PodUniqKeyCmpFunc added in v0.4.0

func PodUniqKeyCmpFunc(i1, i2 interface{}) int

PodUniqKeyCmpFunc sorts uniq key of pod with greater comparison

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 ResourcesLess added in v0.5.2

func ResourcesLess(a, b v1.ResourceList, resourceNameList []v1.ResourceName) bool

ResourcesLess checks whether the given resources a are less than b

func SetCPUQuantityGetter added in v0.4.0

func SetCPUQuantityGetter(getter QuantityGetter)

func SetMemoryQuantityGetter added in v0.4.0

func SetMemoryQuantityGetter(getter QuantityGetter)

func SetPodTransformer added in v0.4.1

func SetPodTransformer(f PodTransformerFunc)

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.

Types

type DynamicInformer added in v0.2.0

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

DynamicInformer keeps the informer-related contents for each workload

type DynamicResourcesManager added in v0.2.0

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

func NewDynamicResourcesManager added in v0.2.0

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

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

GetDynamicInformers gets current dynamic informers

func (*DynamicResourcesManager) Run added in v0.2.0

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 KubeletConfiguration added in v0.5.10

type KubeletConfiguration struct {
	// cpuManagerPolicy is the name of the policy to use.
	// Requires the CPUManager feature gate to be enabled.
	// Default: "None"
	// +optional
	CPUManagerPolicy string `json:"cpuManagerPolicy,omitempty"`
	// memoryManagerPolicy is the name of the policy to use by memory manager.
	// Requires the MemoryManager feature gate to be enabled.
	// Default: "none"
	// +optional
	MemoryManagerPolicy string `json:"memoryManagerPolicy,omitempty"`
	// topologyManagerPolicy is the name of the topology manager policy to use.
	// Valid values include:
	//
	// - `restricted`: kubelet only allows pods with optimal NUMA node alignment for
	//   requested resources;
	// - `best-effort`: kubelet will favor pods with NUMA alignment of CPU and device
	//   resources;
	// - `none`: kubelet has no knowledge of NUMA alignment of a pod's CPU and device resources.
	// - `single-numa-node`: kubelet only allows pods with a single NUMA alignment
	//   of CPU and device resources.
	//
	// Policies other than "none" require the TopologyManager feature gate to be enabled.
	// Default: "none"
	// +optional
	TopologyManagerPolicy string `json:"topologyManagerPolicy,omitempty"`
	// topologyManagerScope represents the scope of topology hint generation
	// that topology manager requests and hint providers generate. Valid values include:
	//
	// - `container`: topology policy is applied on a per-container basis.
	// - `pod`: topology policy is applied on a per-pod basis.
	//
	// "pod" scope requires the TopologyManager feature gate to be enabled.
	// Default: "container"
	// +optional
	TopologyManagerScope string `json:"topologyManagerScope,omitempty"`
	// featureGates is a map of feature names to bools that enable or disable experimental
	// features. This field modifies piecemeal the built-in default values from
	// "k8s.io/kubernetes/pkg/features/kube_features.go".
	// Default: nil
	// +optional
	FeatureGates map[string]bool `json:"featureGates,omitempty"`

	// systemReserved is a set of ResourceName=ResourceQuantity (e.g. cpu=200m,memory=150G)
	// pairs that describe resources reserved for non-kubernetes components.
	// Currently only cpu and memory are supported.
	// See http://kubernetes.io/docs/user-guide/compute-resources for more detail.
	// Default: nil
	// +optional
	SystemReserved map[string]string `json:"systemReserved,omitempty"`
	// kubeReserved is a set of ResourceName=ResourceQuantity (e.g. cpu=200m,memory=150G) pairs
	// that describe resources reserved for kubernetes system components.
	// Currently cpu, memory and local storage for root file system are supported.
	// See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
	// for more details.
	// Default: nil
	// +optional
	KubeReserved map[string]string `json:"kubeReserved,omitempty"`
	// The reservedSystemCPUs option specifies the CPU list reserved for the host
	// level system threads and kubernetes related threads. This provide a "static"
	// CPU list rather than the "dynamic" list by systemReserved and kubeReserved.
	// This option does not support systemReservedCgroup or kubeReservedCgroup.
	ReservedSystemCPUs string `json:"reservedSystemCPUs,omitempty"`

	// NumericTopologyAlignResources is a list of resources which need to be aligned numa affinity
	// in numeric topology policy.
	// Default: [cpu, memory]
	// +optional
	NumericTopologyAlignResources []string `json:"numericTopologyAlignResources,omitempty"`
}

KubeletConfiguration contains the configuration for the Kubelet This struct is a simplification of the definition in the kubelet api repo, holding only the fields used by katalyst.

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 PodResource added in v0.4.0

type PodResource map[string]v1.ResourceList

PodResource key: namespace/name, value: pod requested ResourceList

func (*PodResource) AddPod added in v0.4.0

func (pr *PodResource) AddPod(pod *v1.Pod) bool

func (*PodResource) DeletePod added in v0.4.0

func (pr *PodResource) DeletePod(pod *v1.Pod) bool

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

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 QuantityGetter added in v0.4.0

type QuantityGetter func(resourceList v1.ResourceList) resource.Quantity

func CPUQuantityGetter added in v0.4.0

func CPUQuantityGetter() QuantityGetter

func MemoryQuantityGetter added in v0.4.0

func MemoryQuantityGetter() QuantityGetter

type ResourceThreshold added in v0.2.0

type ResourceThreshold map[v1.ResourceName]float64

ResourceThreshold is map of resource name to threshold of water level

func (*ResourceThreshold) Set added in v0.2.0

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

func (*ResourceThreshold) String added in v0.2.0

func (t *ResourceThreshold) String() string

func (*ResourceThreshold) Type added in v0.2.0

func (t *ResourceThreshold) Type() string

Jump to

Keyboard shortcuts

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