util

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 36 Imported by: 1

Documentation

Index

Constants

View Source
const (
	EvictionKind            = "Eviction"
	EvictionGroupName       = "policy"
	EvictionSubResourceName = "pods/eviction"
)
View Source
const (
	NodeZoneType = "Node"
)

Variables

Functions

func AddResourceList added in v1.1.0

func AddResourceList(list, newList corev1.ResourceList)

AddResourceList adds the resources in newList to list.

func AppendHostPorts added in v1.3.0

func BoolToFloat64 added in v1.3.0

func BoolToFloat64(b bool) float64

func CloneHostPorts added in v1.3.0

func CloneHostPorts(ports framework.HostPortInfo) framework.HostPortInfo

func DumpJSON

func DumpJSON(o interface{}) string

DumpJSON returns the JSON encoding

func EvictPodByVersion added in v1.2.0

func EvictPodByVersion(ctx context.Context, kubernetes kubernetes.Interface, namespace, name string, opts metav1.DeleteOptions, evictVersion string) error

EvictPodByVersion evicts Pods using the best available method in Kubernetes.

The available methods are, in order of preference: * v1 eviction API * v1beta1 eviction API

func FindContainerIdAndStatusByName added in v0.2.0

func FindContainerIdAndStatusByName(status *corev1.PodStatus, name string) (string, *corev1.ContainerStatus, error)

func FindSupportedEvictVersion added in v1.2.0

func FindSupportedEvictVersion(client kubernetes.Interface) (version string, err error)

func GenNodeZoneName added in v1.4.0

func GenNodeZoneName(nodeID int) string

GenNodeZoneName generates the zone name according to the NUMA node ID.

func GenerateNodeKey added in v0.7.0

func GenerateNodeKey(node *metav1.ObjectMeta) string

GenerateNodeKey returns a generated key with given meta

func GeneratePodPatch added in v0.7.0

func GeneratePodPatch(oldPod, newPod *corev1.Pod) ([]byte, error)

func GenerateReservationPatch added in v0.7.0

func GenerateReservationPatch(oldReservation, newReservation *schedulingv1alpha1.Reservation) ([]byte, error)

func GetBatchMemoryFromResourceList added in v1.1.1

func GetBatchMemoryFromResourceList(r corev1.ResourceList) int64

func GetBatchMilliCPUFromResourceList added in v1.1.1

func GetBatchMilliCPUFromResourceList(r corev1.ResourceList) int64

func GetCPUSetFromPod added in v1.0.0

func GetCPUSetFromPod(podAnnotations map[string]string) (string, error)

func GetContainerBatchMemoryByteLimit added in v0.7.0

func GetContainerBatchMemoryByteLimit(c *corev1.Container) int64

func GetContainerBatchMemoryByteRequest added in v0.7.0

func GetContainerBatchMemoryByteRequest(c *corev1.Container) int64

func GetContainerBatchMilliCPULimit added in v0.7.0

func GetContainerBatchMilliCPULimit(c *corev1.Container) int64

func GetContainerBatchMilliCPURequest added in v0.7.0

func GetContainerBatchMilliCPURequest(c *corev1.Container) int64

func GetContainerExtendedResources added in v1.1.0

func GetContainerExtendedResources(container *corev1.Container) *apiext.ExtendedResourceContainerSpec

func GetContainerMemoryByteLimit added in v0.3.0

func GetContainerMemoryByteLimit(c *corev1.Container) int64

func GetContainerMilliCPULimit added in v0.3.0

func GetContainerMilliCPULimit(c *corev1.Container) int64

func GetContainerTargetExtendedResources added in v1.1.0

func GetContainerTargetExtendedResources(container *corev1.Container, resourceNames ...corev1.ResourceName) *apiext.ExtendedResourceContainerSpec

GetContainerTargetExtendedResources gets the resource requirements of a container with given extended resources. It returns nil if container is nil or specifies no extended resource.

func GetEmptyContainerExtendedResources added in v1.1.0

func GetEmptyContainerExtendedResources() *apiext.ExtendedResourceContainerSpec

func GetEmptyPodExtendedResources added in v1.1.0

func GetEmptyPodExtendedResources() *apiext.ExtendedResourceSpec

func GetFastLabelSelector

func GetFastLabelSelector(ps *metav1.LabelSelector) (labels.Selector, error)

func GetKubeQosClass added in v0.2.0

func GetKubeQosClass(pod *corev1.Pod) corev1.PodQOSClass

GetKubeQosClass gets the Kubernetes QOSClass for the pod. DEPRECATED: use extension.GetKubeQosClass instead.

func GetNamespacedName added in v1.3.0

func GetNamespacedName(namespace, name string) string

func GetNodeAddress added in v0.4.1

func GetNodeAddress(node *corev1.Node, addrType corev1.NodeAddressType) (string, error)

GetNodeAddress get node specified type address.

func GetNodeAllocatableBatchMemory added in v1.4.0

func GetNodeAllocatableBatchMemory(node *corev1.Node) int64

func GetNodeAllocatableBatchMilliCPU added in v1.4.0

func GetNodeAllocatableBatchMilliCPU(node *corev1.Node) int64

func GetNodeAnnoReservedJson added in v1.2.0

func GetNodeAnnoReservedJson(reserved apiext.NodeReservation) string

func GetNodeReservationFromAnnotation added in v1.2.0

func GetNodeReservationFromAnnotation(anno map[string]string) corev1.ResourceList

func GetNodeReservationFromKubelet added in v1.4.0

func GetNodeReservationFromKubelet(node *corev1.Node) corev1.ResourceList

func GetNodeReservationResources added in v1.3.0

func GetNodeReservationResources(reservation *apiext.NodeReservation) (corev1.ResourceList, error)

func GetPodBEMemoryByteLimit added in v0.2.0

func GetPodBEMemoryByteLimit(pod *corev1.Pod) int64

func GetPodBEMemoryByteRequestIgnoreUnlimited added in v0.3.0

func GetPodBEMemoryByteRequestIgnoreUnlimited(pod *corev1.Pod) int64

func GetPodBEMilliCPULimit added in v0.2.0

func GetPodBEMilliCPULimit(pod *corev1.Pod) int64

func GetPodBEMilliCPURequest added in v0.2.0

func GetPodBEMilliCPURequest(pod *corev1.Pod) int64

func GetPodExtendedResources added in v1.1.0

func GetPodExtendedResources(pod *corev1.Pod) *apiext.ExtendedResourceSpec

func GetPodKey

func GetPodKey(pod *corev1.Pod) string

func GetPodMetricKey

func GetPodMetricKey(podMetric *slov1alpha1.PodMetricInfo) string

func GetPodMilliCPULimit added in v0.7.0

func GetPodMilliCPULimit(pod *corev1.Pod) int64

func GetPodRequest

func GetPodRequest(pod *corev1.Pod, resourceNames ...corev1.ResourceName) corev1.ResourceList

func GetPodTargetExtendedResources added in v1.1.0

func GetPodTargetExtendedResources(pod *corev1.Pod, resourceNames ...corev1.ResourceName) *apiext.ExtendedResourceSpec

GetPodTargetExtendedResources gets the resource requirements of a pod with given extended resources. It returns nil if pod specifies no extended resource.

func IsIn added in v1.3.0

func IsIn(arr []string, val string) bool

func IsNodeAddressTypeSupported added in v0.4.1

func IsNodeAddressTypeSupported(addrType corev1.NodeAddressType) bool

IsNodeAddressTypeSupported determine whether addrType is a supported type.

func IsPodCPUBurstable added in v1.0.0

func IsPodCPUBurstable(pod *corev1.Pod) bool

IsPodCPUBurstable checks if cpu burst is allowed for the pod.

func IsPodCfsQuotaNeedUnset added in v1.0.0

func IsPodCfsQuotaNeedUnset(annotations map[string]string) (bool, error)

IsPodCfsQuotaNeedUnset checks if the pod-level and container-level cfs_quota should be unset to avoid unnecessary throttles. https://github.com/koordinator-sh/koordinator/issues/489

func IsPodTerminated added in v0.4.0

func IsPodTerminated(pod *corev1.Pod) bool

func IsQuantityDiff added in v1.4.0

func IsQuantityDiff(old, new resource.Quantity, diffThreshold float64) bool

func IsResourceDiff

func IsResourceDiff(old, new corev1.ResourceList, resourceName corev1.ResourceName, diffThreshold float64) bool

IsResourceDiff returns whether the new resource has big enough difference with the old one or not

func IsResourceListEqual added in v1.4.0

func IsResourceListEqual(a corev1.ResourceList, b corev1.ResourceList) bool

IsResourceListEqual checks if the two resource lists are numerically equivalent.

func IsResourceListEqualIgnoreZeroValues added in v1.4.0

func IsResourceListEqualIgnoreZeroValues(a, b corev1.ResourceList) bool

IsResourceListEqualIgnoreZeroValues checks if the two resource lists are numerically equivalent. NOTE: Resource name with a zero value will be ignored in comparison. e.g. a = {"cpu": "10", "memory": "0"}, b = {"cpu": "10"} => true

func IsZoneListResourceEqual added in v1.4.0

func IsZoneListResourceEqual(a, b v1alpha1.ZoneList, resourceNames ...string) bool

func LessThanOrEqualCompletely added in v1.4.0

func LessThanOrEqualCompletely(a corev1.ResourceList, b corev1.ResourceList) bool

LessThanOrEqualCompletely is different quotav1.LessThanOrEqual. It will compare non-exist value in b

func MaxFloat64 added in v1.3.0

func MaxFloat64(i, j float64) float64

func MaxInt64 added in v0.3.0

func MaxInt64(i, j int64) int64

func MergeCfg added in v0.2.0

func MergeCfg(old, new interface{}) (interface{}, error)

MergeCfg returns a merged interface. Value in new will override old's when both fields exist. It will throw an error if:

  1. either of the inputs was nil;
  2. inputs were not a pointer of the same json struct.

func MergeZoneList added in v1.4.0

func MergeZoneList(a, b v1alpha1.ZoneList) v1alpha1.ZoneList

MergeZoneList merges ZoneList b override ZoneList a.

func MinFloat64 added in v1.3.0

func MinFloat64(i, j float64) float64

func MinInt64 added in v0.3.0

func MinInt64(i, j int64) int64

func MinResourceList added in v1.3.0

MinResourceList returns the result of Min(a, b) for each named resource, corresponding to the quotav1.Max(). It should be semantically equivalent to the result of `quotav1.Subtract(quotav1.Add(a, b), quotav1.Max(a, b))`.

e.g.

a = {"cpu": "10", "memory": "20Gi"}, b = {"cpu": "6", "memory": "24Gi", "nvidia.com/gpu": "2"}
=> {"cpu": "6", "memory": "20Gi"}

func MultiplyMilliQuant

func MultiplyMilliQuant(quant resource.Quantity, factor float64) resource.Quantity

MultiplyMilliQuant scales quantity by factor

func MultiplyQuant

func MultiplyQuant(quant resource.Quantity, factor float64) resource.Quantity

MultiplyQuant scales quantity by factor

func NewZeroResourceList

func NewZeroResourceList() corev1.ResourceList

func OnceValues added in v1.4.1

func OnceValues(f func() ([]int, error)) func() ([]int, error)

TODO: Replace this function with the standard library after go1.21+ version

func ParseContainerId added in v0.2.0

func ParseContainerId(data string) (cType, cID string, err error)

func PatchPod added in v0.7.0

func PatchPod(ctx context.Context, clientset clientset.Interface, oldPod, newPod *corev1.Pod) (*corev1.Pod, error)

func PatchReservation added in v0.7.0

func PatchReservation(ctx context.Context, clientset koordinatorclientset.Interface, oldReservation, newReservation *schedulingv1alpha1.Reservation) (*schedulingv1alpha1.Reservation, error)

func QuantityPtr added in v1.1.1

func QuantityPtr(q resource.Quantity) *resource.Quantity

func RemoveHostPorts added in v1.3.0

func RemoveHostPorts(ports framework.HostPortInfo, r framework.HostPortInfo)

func RequestedHostPorts added in v1.3.0

func RequestedHostPorts(pod *corev1.Pod) framework.HostPortInfo

func ResetHostPorts added in v1.3.0

func ResetHostPorts(pod *corev1.Pod, ports framework.HostPortInfo)

func RetryOnConflictOrTooManyRequests added in v0.7.0

func RetryOnConflictOrTooManyRequests(fn func() error) error

func RunFeature added in v0.2.0

func RunFeature(moduleFunc func(), featureDependency []featuregate.Feature, interval int, stopCh <-chan struct{}) bool

RunFeature runs moduleFunc only if interval > 0 AND at least one feature dependency is enabled

func RunFeatureWithInit added in v0.2.0

func RunFeatureWithInit(moduleInit func() error, moduleFunc func(), featureDependency []featuregate.Feature, interval int, stopCh <-chan struct{}) bool

RunFeatureWithInit runs moduleFunc only if interval > 0 , at least one feature dependency is enabled and moduleInit function returns nil

func SupportEviction added in v1.3.0

func SupportEviction(client kubernetes.Interface) (string, error)

func TrimDifferentZone added in v1.4.0

func TrimDifferentZone(a, b v1alpha1.ZoneList) v1alpha1.ZoneList

func TrimNodeAllocatableByNodeReservation added in v1.3.0

func TrimNodeAllocatableByNodeReservation(node *corev1.Node) (trimmedAllocatable corev1.ResourceList, trimmed bool)

func ZoneListToZoneResourceList added in v1.4.0

func ZoneListToZoneResourceList(zoneList v1alpha1.ZoneList) map[string]corev1.ResourceList

ZoneListToZoneResourceList transforms the zone list into a map from zone name to its resource list. It supposes the capacity, allocatable, available of a ResourceInfo is the same.

func ZoneResourceListToZoneList added in v1.4.0

func ZoneResourceListToZoneList(zoneResourceList map[string]corev1.ResourceList) v1alpha1.ZoneList

ZoneResourceListToZoneList transforms the zone resource list into the zone list by the orders of the zone name and the resource name. It supposes the capacity, allocatable, available of a ResourceInfo is the same.

Types

This section is empty.

Jump to

Keyboard shortcuts

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