util

package
v0.0.0-...-bc30bd0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unknown event
	Unknown = "Unknown"
	// PodAdd is the event when a new pod is added to API server.
	PodAdd = "PodAdd"
	// NodeAdd is the event when a new node is added to the cluster.
	NodeAdd = "NodeAdd"
	// NMNodeAdd is the event when a new NMNode is added to the cluster.
	NMNodeAdd = "NMNodeAdd"
	// CNRAdd is the event when a new CNR is added to the cluster.
	CNRAdd = "CNRAdd"
	// NodePartitionScaleOut is the event when scheduler's node partition changes from Physical to Logical.
	NodePartitionScaleOut = "NodePartitionScaleOut"
	// ScheduleAttemptFailure is the event when a schedule attempt fails.
	ScheduleAttemptFailure = "ScheduleAttemptFailure"
	// CreateUnitSucceed
	CreateUnitSucceed = "CreateUnitSucceed"
	// WaitingComplete is the event when a pod finishes waiting.
	WaitingComplete = "WaitingComplete"
	// BackoffComplete is the event when a pod finishes backoff.
	BackoffComplete = "BackoffComplete"
	// UnitReady is the event when an unit's ready to be scheduled.
	UnitReady = "UnitReady"
	// UnschedulableTimeout is the event when a pod stays in unschedulable for longer than timeout.
	UnschedulableTimeout = "UnschedulableTimeout"
	// AssignedPodAdd is the event when a pod is added that causes pods with matching affinity terms
	// to be more schedulable.
	AssignedPodAdd = "AssignedPodAdd"
	// AssignedPodUpdate is the event when a pod is updated that causes pods with matching affinity
	// terms to be more schedulable.
	AssignedPodUpdate = "AssignedPodUpdate"
	// AssignedPodDelete is the event when a pod is deleted that causes pods with matching affinity
	// terms to be more schedulable.
	AssignedPodDelete = "AssignedPodDelete"
	// PvAdd is the event when a persistent volume is added in the cluster.
	PvAdd = "PvAdd"
	// PvUpdate is the event when a persistent volume is updated in the cluster.
	PvUpdate = "PvUpdate"
	// PvcAdd is the event when a persistent volume claim is added in the cluster.
	PvcAdd = "PvcAdd"
	// PvcUpdate is the event when a persistent volume claim is updated in the cluster.
	PvcUpdate = "PvcUpdate"
	// StorageClassAdd is the event when a StorageClass is added in the cluster.
	StorageClassAdd = "StorageClassAdd"
	// ServiceAdd is the event when a service is added in the cluster.
	ServiceAdd = "ServiceAdd"
	// ServiceUpdate is the event when a service is updated in the cluster.
	ServiceUpdate = "ServiceUpdate"
	// ServiceDelete is the event when a service is deleted in the cluster.
	ServiceDelete = "ServiceDelete"
	// CSINodeAdd is the event when a CSI node is added in the cluster.
	CSINodeAdd = "CSINodeAdd"
	// CSINodeUpdate is the event when a CSI node is updated in the cluster.
	CSINodeUpdate = "CSINodeUpdate"
	// NodeSpecUnschedulableChange is the event when unschedulable node spec is changed.
	NodeSpecUnschedulableChange = "NodeSpecUnschedulableChange"
	// NodeAllocatableChange is the event when node allocatable is changed.
	NodeAllocatableChange = "NodeAllocatableChange"
	// NodeLabelsChange is the event when node label is changed.
	NodeLabelChange = "NodeLabelChange"
	// NodeTaintsChange is the event when node taint is changed.
	NodeTaintChange = "NodeTaintChange"
	// NodeConditionChange is the event when node condition is changed.
	NodeConditionChange = "NodeConditionChange"
	// PodGroupAdd is the event when a pod group is added in the cluster.
	PodGroupAdd = "PodGroupAdd"
	// PodGroupUpdate is the event when a pod group is updated in the cluster.
	PodGroupUpdate = "PodGroupUpdate"
	// ReservationDelete is the event when a reservation is deleted in the cluster.
	ReservationDelete = "ReservationDelete"
)

Events that trigger scheduler queue to change.

View Source
const (
	// DefaultMilliCPURequest defines default milli cpu request number.
	DefaultMilliCPURequest int64 = 100 // 0.1 core
	// DefaultMemoryRequest defines default memory request size.
	DefaultMemoryRequest int64 = 200 * 1024 * 1024 // 200 MB
)

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 (
	ResourceSriov v1.ResourceName = "bytedance.com/sriov.nic"
	ResourceGPU   v1.ResourceName = "nvidia.com/gpu"
	ResourceNuma  v1.ResourceName = "numa"
)
View Source
const (
	CanBePreemptedAnnotationKey = "godel.bytedance.com/can-be-preempted"
	CanBePreempted              = "true"
	CannotBePreempted           = "false"
	PreemptionPolicyKey         = "godel.bytedance.com/preemption-policy"
	ObjectNameField             = "metadata.name"

	// Debug Level
	DebugModeAnnotationKey = "godel.bytedance.com/debug-mode"
	// Debug Mode ON
	DebugModeOn = "on"
	// Debug Mode OFF
	DebugModeOff = "off"
	// Node that the pod want to watch by node labels
	WatchNodeNameLabelName = "godel.bytedance.com/watch-node-label"

	SemicolonSeperator = ";"
	CommaSeperator     = ","
	ColonSeperator     = ":"
	EqualSignSeperator = "="

	QoSLevelKey         = "katalyst.kubewharf.io/qos_level"
	MemoyEnhancementKey = "katalyst.kubewharf.io/memory_enhancement"
	// NumaBindingKey is a key that illustrate whether the pod needs bind numa
	NumaBindingKey   = "numa_binding"
	NumaExclusiveKey = "numa_exclusive"

	OwnerTypeDaemonSet  = "DaemonSet"
	OwnerTypeReplicaSet = "ReplicaSet"

	MaxAPICallRetryTimes = 3 // TODO: 5 will cause a timeout in UT (30s)
)
View Source
const (
	DeployNameKeyInPodLabels = "name"
)
View Source
const MemoyEnhancementTrue string = "true"

Variables

This section is empty.

Functions

func CheckIfNodeLabelsInSpecifiedLabels

func CheckIfNodeLabelsInSpecifiedLabels(labels map[string]string, requiredLabels map[string]string) bool

func ClearNominatedNodeName

func ClearNominatedNodeName(cs clientset.Interface, pods ...*v1.Pod) utilerrors.Aggregate

ClearNominatedNodeName internally submit a patch request to API server to set each pods[*].Status.NominatedNodeName> to "".

func DeletePod

func DeletePod(cs clientset.Interface, pod *v1.Pod) error

DeletePod deletes the given <pod> from API server

func EqualMap

func EqualMap(m1, m2 map[string]string) bool

func FormatLabels

func FormatLabels(labels map[string]string) string

func GetDaemonSetKey

func GetDaemonSetKey(ds *appsv1.DaemonSet) string

func GetDeployNameFromPod

func GetDeployNameFromPod(pod *v1.Pod) string

TODO: if we support multiple controller kinds later, we need to get the controller name

func GetMovementName

func GetMovementName(movement *schedulingv1a1.Movement) string

func GetNamespacesFromPodAffinityTerm

func GetNamespacesFromPodAffinityTerm(pod *v1.Pod, podAffinityTerm *v1.PodAffinityTerm) sets.String

GetNamespacesFromPodAffinityTerm returns a set of names according to the namespaces indicated in podAffinityTerm. If namespaces is empty it considers the given pod's namespace.

func GetNonZeroQuantityForResource

func GetNonZeroQuantityForResource(name v1.ResourceName, requests v1.ResourceList) *resource.Quantity

func GetNonzeroRequestForResource

func GetNonzeroRequestForResource(resource v1.ResourceName, requests *v1.ResourceList) int64

GetNonzeroRequestForResource returns the default resource request if none is found or what is provided on the request.

func GetNonzeroRequests

func GetNonzeroRequests(requests *v1.ResourceList) (int64, int64)

GetNonzeroRequests returns the default cpu and memory resource request if none is found or what is provided on the request.

func GetPDBKey

func GetPDBKey(pdb *policy.PodDisruptionBudget) string

func GetPodAffinityTerms

func GetPodAffinityTerms(affinity *v1.Affinity) (terms []v1.PodAffinityTerm)

GetPodAffinityTerms gets pod affinity terms by a pod affinity object.

func GetPodDebugMode

func GetPodDebugMode(pod *v1.Pod) string

Get Pod debug mode annotation

func GetPodDebugModeOnNode

func GetPodDebugModeOnNode(pod *v1.Pod, node *v1.Node, nmNode *nodev1alpha1.NMNode) bool

func GetPodFullName

func GetPodFullName(pod *v1.Pod) string

GetPodFullName returns a name that uniquely identifies a pod.

func GetPodPreferedAntiAffinityTerms

func GetPodPreferedAntiAffinityTerms(affinity *v1.Affinity) (terms []v1.WeightedPodAffinityTerm)

GetPodPreferedAntiAffinityTerms gets pod affinity terms by a pod prefered-anti-affinity.

func GetPodRequiredAntiAffinityTerms

func GetPodRequiredAntiAffinityTerms(affinity *v1.Affinity) (terms []v1.PodAffinityTerm)

GetPodRequiredAntiAffinityTerms gets pod affinity terms by a pod require-anti-affinity.

func GetPodStartTime

func GetPodStartTime(pod *v1.Pod) *metav1.Time

GetPodStartTime returns start time of the given pod or current timestamp if it hasn't started yet.

func GetPodWatchLabelValueString

func GetPodWatchLabelValueString(pod *v1.Pod) string

Get Pod watch label value string

func GetReplicaSetKey

func GetReplicaSetKey(rs *appsv1.ReplicaSet) string

func GetScheduler

func GetScheduler(cs crdclientset.Interface, schedulerName string) (*v1alpha1.Scheduler, error)

GetScheduler returns the latest <scheduler> from API server

func MarshalMicroTopology

func MarshalMicroTopology(topology map[int]*v1.ResourceList) string

func MergeLabels

func MergeLabels(labels1, labels2 map[string]string) map[string]string

func NeedConsiderTopology

func NeedConsiderTopology(pod *v1.Pod) (bool, bool)

NeedConsiderTopology checks if need to consider numa topology

func NeedNumaBinding

func NeedNumaBinding(pod *v1.Pod) (bool, bool)

NeedNumaBinding checks if need to consider numa topology

func NodesHaveSameTopologyKey

func NodesHaveSameTopologyKey(nodeA, nodeB *v1.Node, topologyKey string) bool

NodesHaveSameTopologyKey checks if nodeA and nodeB have same label value with given topologyKey as label key. Returns false if topologyKey is empty.

func ParallelizeUntil

func ParallelizeUntil(stop *bool, workers int, pieces int, doWorkPiece func(piece int))

func PatchPod

func PatchPod(cs clientset.Interface, old *v1.Pod, new *v1.Pod) (err error)

PatchPod calculates the delta bytes change from <old> to <new>, and then submit a request to API server to patch the pod changes.

func PodMatchesTermsNamespaceAndSelector

func PodMatchesTermsNamespaceAndSelector(pod *v1.Pod, namespaces sets.String, selector labels.Selector) bool

PodMatchesTermsNamespaceAndSelector returns true if the given <pod> matches the namespace and selector defined by <affinityPod>`s <term>.

func PostScheduler

func PostScheduler(cs crdclientset.Interface, scheduler *v1alpha1.Scheduler) (*v1alpha1.Scheduler, error)

PostScheduler create v1alpha1.Scheduler in API server

func RemoveLabels

func RemoveLabels(labels1, labels2 map[string]string) map[string]string

func Retry

func Retry(attempts int, sleep time.Duration, f func() error) error

func SetMetaDataLabel

func SetMetaDataLabel(obj *metav1.ObjectMeta, key string, value string)

func SetMetaDataMap

func SetMetaDataMap(obj *metav1.ObjectMeta, key string, value string)

func UnmarshalMicroTopology

func UnmarshalMicroTopology(microTopologyStr string) (map[int]*v1.ResourceList, error)

func UpdateSchedulerStatus

func UpdateSchedulerStatus(cs crdclientset.Interface, scheduler *v1alpha1.Scheduler) (*v1alpha1.Scheduler, error)

UpdateSchedulerStatus updates v1alpha1.Scheduler in API server

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock provides an interface for getting the current time

type QoSLevel

type QoSLevel string
const (
	DedicatedCores QoSLevel = "dedicated_cores"
	SharedCores    QoSLevel = "shared_cores"
	ReclaimedCores QoSLevel = "reclaimed_cores"
)

type RealClock

type RealClock struct{}

RealClock implements a clock using time

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current time with time.Now

type Topologies

type Topologies struct {
	DefaultKeys []string
}

Topologies contains topologies information of nodes.

func (*Topologies) NodesHaveSameTopologyKey

func (tps *Topologies) NodesHaveSameTopologyKey(nodeA, nodeB *v1.Node, topologyKey string) bool

NodesHaveSameTopologyKey checks if nodeA and nodeB have same label value with given topologyKey as label key.

Directories

Path Synopsis
pod
qos
package taints implements utilities for working with taints
package taints implements utilities for working with taints
volume

Jump to

Keyboard shortcuts

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