util

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AnnotationReservePod indicates whether the pod is a reserved pod.
	AnnotationReservePod = apiext.SchedulingDomainPrefix + "/reserve-pod"
	// AnnotationReservationName indicates the name of the reservation.
	AnnotationReservationName = apiext.SchedulingDomainPrefix + "/reservation-name"
	// AnnotationReservationNode indicates the node name if the reservation specifies a node.
	AnnotationReservationNode = apiext.SchedulingDomainPrefix + "/reservation-node"
)

Functions

func AddResourceList added in v1.1.0

func AddResourceList(list, newList corev1.ResourceList)

AddResourceList adds the resources in newList to list.

func DefaultCPUBurstConfig added in v0.3.0

func DefaultCPUBurstConfig() slov1alpha1.CPUBurstConfig

func DefaultCPUBurstStrategy added in v0.3.0

func DefaultCPUBurstStrategy() *slov1alpha1.CPUBurstStrategy

func DefaultCPUQOS added in v0.6.0

func DefaultCPUQOS(qos apiext.QoSClass) *slov1alpha1.CPUQOS

func DefaultMemoryQOS added in v0.6.0

func DefaultMemoryQOS(qos apiext.QoSClass) *slov1alpha1.MemoryQOS

DefaultMemoryQOS returns the recommended configuration for memory qos strategy. Please refer to `apis/slo/v1alpha1` for the definition of each field. In the recommended configuration, all abilities of memcg qos are disable, including `MinLimitPercent`, `LowLimitPercent`, `ThrottlingPercent` since they are not fully beneficial to all scenarios. Whereas, they are still useful when the use case is determined. e.g. lock some memory to improve file read performance. Asynchronous memory reclaim is enabled by default to alleviate the direct reclaim pressure, including `WmarkRatio` and `WmarkScalePermill`. The watermark of async reclaim is not recommended to set too low, since lower the watermark the more excess reclamations. Memory min watermark grading corresponding to `WmarkMinAdj` is enabled. It benefits high-priority pods by postponing global reclaim when machine's free memory is below than `/proc/sys/vm/min_free_kbytes`.

func DefaultNodeSLOSpecConfig

func DefaultNodeSLOSpecConfig() slov1alpha1.NodeSLOSpec

DefaultNodeSLOSpecConfig defines the default config of the nodeSLOSpec, which would be used by the resmgr

func DefaultResourceQOSStrategy added in v0.6.0

func DefaultResourceQOSStrategy() *slov1alpha1.ResourceQOSStrategy

func DefaultResourceThresholdStrategy

func DefaultResourceThresholdStrategy() *slov1alpha1.ResourceThresholdStrategy

func DumpJSON

func DumpJSON(o interface{}) string

DumpJSON returns the JSON encoding

func FindContainerIdAndStatusByName added in v0.2.0

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

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

func GetNodeAddress added in v0.4.1

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

GetNodeAddress get node specified type address.

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

func GetReservationKey(r *schedulingv1alpha1.Reservation) string

func GetReservationNameFromReservePod added in v0.7.0

func GetReservationNameFromReservePod(pod *corev1.Pod) string

func GetReservationNodeName added in v0.7.0

func GetReservationNodeName(r *schedulingv1alpha1.Reservation) string

func GetReservationSchedulerName added in v0.7.0

func GetReservationSchedulerName(r *schedulingv1alpha1.Reservation) string

func GetReservePodKey added in v0.7.0

func GetReservePodKey(pod *corev1.Pod) string

func GetReservePodNodeName added in v0.7.0

func GetReservePodNodeName(pod *corev1.Pod) string

func IsNodeAddressTypeSupported added in v0.4.1

func IsNodeAddressTypeSupported(addrType corev1.NodeAddressType) bool

IsNodeAddressTypeSupported determine whether addrType is a supported type.

func IsObjValidActiveReservation added in v0.7.0

func IsObjValidActiveReservation(obj interface{}) bool

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

func IsReservationActive(r *schedulingv1alpha1.Reservation) bool

IsReservationActive checks if the reservation is scheduled and its status is Available/Waiting (active to use).

func IsReservationAvailable added in v0.7.0

func IsReservationAvailable(r *schedulingv1alpha1.Reservation) bool

IsReservationAvailable checks if the reservation is scheduled on a node and its status is Available.

func IsReservationExpired added in v0.7.0

func IsReservationExpired(r *schedulingv1alpha1.Reservation) bool

func IsReservationFailed added in v0.7.0

func IsReservationFailed(r *schedulingv1alpha1.Reservation) bool

func IsReservationSucceeded added in v0.7.0

func IsReservationSucceeded(r *schedulingv1alpha1.Reservation) bool

func IsReservePod added in v0.7.0

func IsReservePod(pod *corev1.Pod) 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 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 MinInt64 added in v0.3.0

func MinInt64(i, j int64) int64

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

func NewReservePod(r *schedulingv1alpha1.Reservation) *corev1.Pod

NewReservePod returns a fake pod set as the reservation's specifications. The reserve pod is only visible for the scheduler and does not make actual creation on nodes.

func NewZeroResourceList

func NewZeroResourceList() corev1.ResourceList

func NoneCPUQOS added in v0.6.0

func NoneCPUQOS() *slov1alpha1.CPUQOS

func NoneMemoryQOS added in v0.6.0

func NoneMemoryQOS() *slov1alpha1.MemoryQOS

NoneMemoryQOS returns the all-disabled configuration for memory qos strategy.

func NoneResctrlQOS added in v0.6.0

func NoneResctrlQOS() *slov1alpha1.ResctrlQOS

func NoneResourceQOS added in v0.6.0

func NoneResourceQOS(qos apiext.QoSClass) *slov1alpha1.ResourceQOS

func NoneResourceQOSStrategy added in v0.6.0

func NoneResourceQOSStrategy() *slov1alpha1.ResourceQOSStrategy

NoneResourceQOSStrategy indicates the qos strategy with all qos

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(clientset clientset.Interface, oldPod, newPod *corev1.Pod) (*corev1.Pod, error)

func PatchReservation added in v0.7.0

func PatchReservation(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 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 SetReservationNodeName added in v0.7.0

func SetReservationNodeName(r *schedulingv1alpha1.Reservation, nodeName string)

func SetReservationUnschedulable added in v0.7.0

func SetReservationUnschedulable(r *schedulingv1alpha1.Reservation, msg string)

func ValidateReservation added in v0.7.0

func ValidateReservation(r *schedulingv1alpha1.Reservation) error

Types

type Patch added in v0.7.0

type Patch struct {
	Clientset      clientset.Interface
	KoordClientset koordinatorclientset.Interface

	// patch data
	// NOTE: add more fields if needed
	LabelsAdd         map[string]string
	AnnotationsAdd    map[string]string
	LabelsRemove      []string
	AnnotationsRemove []string
}

Patch is for simply patching arbitrary objects (e.g. pods, koord CRDs).

func NewPatch added in v0.7.0

func NewPatch() *Patch

func (*Patch) AddAnnotations added in v0.7.0

func (p *Patch) AddAnnotations(annotations map[string]string) *Patch

func (*Patch) AddLabels added in v0.7.0

func (p *Patch) AddLabels(labels map[string]string) *Patch

func (*Patch) PatchPod added in v0.7.0

func (p *Patch) PatchPod(pod *corev1.Pod) (*corev1.Pod, error)

func (*Patch) PatchPodOrReservation added in v0.7.0

func (p *Patch) PatchPodOrReservation(pod *corev1.Pod) (interface{}, error)

PatchPodOrReservation patches the pod (if the pod is not a reserve pod) or corresponding reservation object (if the pod is a reserve pod) with the given patch data.

func (*Patch) PatchReservation added in v0.7.0

func (*Patch) RemoveAnnotations added in v0.7.0

func (p *Patch) RemoveAnnotations(annotationKeys []string) *Patch

func (*Patch) RemoveLabels added in v0.7.0

func (p *Patch) RemoveLabels(labelKeys []string) *Patch

func (*Patch) WithClientset added in v0.7.0

func (p *Patch) WithClientset(cs clientset.Interface) *Patch

func (*Patch) WithHandle added in v0.7.0

func (p *Patch) WithHandle(handle framework.Handle) *Patch

func (*Patch) WithKoordinatorClientSet added in v0.7.0

func (p *Patch) WithKoordinatorClientSet(cs koordinatorclientset.Interface) *Patch

type ReservationToPodEventHandlerFuncs added in v0.7.0

type ReservationToPodEventHandlerFuncs struct {
	FilterFunc func(obj interface{}) bool
	PodHandler cache.ResourceEventHandler
}

ReservationToPodEventHandlerFuncs can be used to handle reservation events with a pod event handler, which converts each reservation object into the corresponding reserve pod object.

e.g.
func registerReservationEventHandler(handle framework.Handle, podHandler podHandler) {
  extendedHandle, ok := handle.(frameworkext.ExtendedHandle)
  if !ok { // if not implement extendedHandle, ignore reservation events
    klog.V(3).Infof("registerReservationEventHandler aborted, cannot convert handle to frameworkext.ExtendedHandle, got %T", handle)
    return
  }
  extendedHandle.KoordinatorSharedInformerFactory().Scheduling().V1alpha1().Reservations().Informer().AddEventHandler(&util.ReservationToPodEventHandlerFuncs{
    FilterFunc: util.IsObjValidActiveReservation,
    PodHandler: &podHandler,
  })
}

func (ReservationToPodEventHandlerFuncs) OnAdd added in v0.7.0

func (r ReservationToPodEventHandlerFuncs) OnAdd(obj interface{})

func (ReservationToPodEventHandlerFuncs) OnDelete added in v0.7.0

func (r ReservationToPodEventHandlerFuncs) OnDelete(obj interface{})

OnDelete calls DeleteFunc if it's not nil.

func (ReservationToPodEventHandlerFuncs) OnUpdate added in v0.7.0

func (r ReservationToPodEventHandlerFuncs) OnUpdate(oldObj, newObj interface{})

OnUpdate calls UpdateFunc if it's not nil.

Directories

Path Synopsis
metrics

Jump to

Keyboard shortcuts

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