pod

package
v0.0.0-...-dcfb068 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PodStateAnnotationKey is a pod annotation key, value is the pod state
	PodStateAnnotationKey = "godel.bytedance.com/pod-state"

	// SchedulerAnnotationKey is a pod annotation key, value is the scheduler id who is responsible for scheduling this pod
	SchedulerAnnotationKey = "godel.bytedance.com/selected-scheduler"

	// FailedSchedulersAnnotationKey is a pod annotation key, value is schedulers who have already tried and failed to schedule the pod
	// this is used only when Node Partition is physical
	FailedSchedulersAnnotationKey = "godel.bytedance.com/failed-schedulers"

	// TraceContext represents the span context for the pod
	TraceContext = "trace-context"

	// AssumedNodeAnnotationKey is a pod annotation key, value is the assumed node name chosen by one scheduler
	// the scheduler will reserve the allocated resource for the pod. TODO: should all schedulers be aware of this ?
	// TODO: figure out if we can return multiple nodes ? if so how to deal with scheduler cache ?
	AssumedNodeAnnotationKey = "godel.bytedance.com/assumed-node"

	// TODO: figure out how to define cross node constraint and whether we need this annotation
	// AssumedCrossNodeAnnotationKey is a pod annotation key, value is the assumed node name chosen by one scheduler
	// the scheduler will reserve the allocated resource for the pod.
	// Pod need to resolve cross node constraint
	AssumedCrossNodeAnnotationKey = "godel.bytedance.com/assumed-cross-node"

	// PodGroupNameAnnotationKey is pod annotation key, the value is name of PodGroup custom resource.
	PodGroupNameAnnotationKey = "godel.bytedance.com/pod-group-name"

	// PotentialVictimsAnnotationKey is a pod annotation key, value is the victims chosen by dispatcher
	// this is used for best effort application pods
	// values can be like: [{queue: queue1, application: app1}, {queue: queue2, application: app2}]...
	PotentialVictimsAnnotationKey = "godel.bytedance.com/potential-victims"

	// NominatedNodeAnnotationKey is a pod annotation key,
	// value is the node name chosen by scheduler for placing the pending pod by evicting others
	// value can be like: {node: node1, victims: pod1, pod2...}
	// the scheduler will reserve the allocated resource for the pod. TODO: should all schedulers be aware of this ?
	// TODO: figure out if we can return multiple nodes ? if so how to deal with scheduler cache ?
	NominatedNodeAnnotationKey = "godel.bytedance.com/nominated-node"

	// ATTENTION: This annotation key will be DEPRECATED in the future and REPLACED by `QoSLevelKey=katalyst.kubewharf.io/qos_level`.
	// PodResourceTypeAnnotationKey is a pod annotation key, value is the pod resource type (guaranteed or best-effort)
	PodResourceTypeAnnotationKey = "godel.bytedance.com/pod-resource-type"

	// PodLauncherAnnotationKey is a pod annotation key, value is the launcher of this pod (kubelet or node-manager)
	PodLauncherAnnotationKey = "godel.bytedance.com/pod-launcher"

	// InitialHandledTimestampAnnotationKey is a pod annotation key, value is the timestamp when the pod is first handled by Godel Scheduler
	InitialHandledTimestampAnnotationKey = "godel.bytedance.com/initial-handled-timestamp"

	// MicroTopologyKey is an annotation key for pod micro topology assigned by scheduler&binder
	MicroTopologyKey = "godel.bytedance.com/micro-topology"

	IgnorePodsLimitAnnotationKey = "godel.bytedance.com/ignore-pods-limit"

	ProtectionDurationFromPreemptionKey = "godel.bytedance.com/protection-duration-from-preemption"

	UnitScheduledIndexAnnotationKey = "godel.bytedance.com/scheduled-index-in-scheduling-unit"

	// E2EExcludedPodAnnotationKey is a pod annotation key, pods with this annotation will be excluded when calculating e2e latency
	E2EExcludedPodAnnotationKey = "godel.bytedance.com/e2e-excluded"

	IncreasePercentageOfNodesToScoreAnnotationKey = "godel.bytedance.com/increase-percentage-of-nodes-to-score"

	IncreasePercentageOfNodesToScore = "true"
)
View Source
const (
	GuaranteedPod PodResourceType = "guaranteed"
	BestEffortPod PodResourceType = "best-effort"
	// UndefinedPod only used in metrics label
	UndefinedPod PodResourceType = "undefined"

	// Default priority values for pods with different resource types
	DefaultPriorityValueForGuaranteedPod int32 = 100
	DefaultPriorityValueForBestEffortPod int32 = 40
)
View Source
const (
	ReplicaSetKind       = "ReplicaSet"
	StatefulSetKind      = "StatefulSet"
	StatefulSetExtension = "StatefulSetExtension"
	RequestClassKind     = "RequestClass"
	PodGroupKind         = "PodGroup"
	DaemonSetKind        = "DaemonSet"

	KeySeperator string = "/"
)
View Source
const (
	AlignedResources = "godel.bytedance.com/aligned-resources"
)

AllContainers specifies that all containers be visited

View Source
const PodKeySeperator string = "/"
View Source
const PvcSelectedNodeAnnotation = "volume.kubernetes.io/selected-node"
View Source
const RSKind = "ReplicaSet"

Variables

View Source
var (
	PodLauncherUnsupportError = fmt.Errorf("pod launcher only allow %v", []PodLauncher{Kubelet, NodeManager})
	PodLauncherMissedError    = fmt.Errorf("missing pod launcher")
)
View Source
var (
	PodResourceTypeUnsupportError = fmt.Errorf("pod resource type only allow %v", []PodResourceType{GuaranteedPod, BestEffortPod})
	PodResourceTypeMissedError    = fmt.Errorf("missing pod resource type")
)

Functions

func AbnormalPodState

func AbnormalPodState(pod *v1.Pod) bool

AbnormalPodState checks if the given pod is in abnormal state

func AbnormalPodStateOfGodel

func AbnormalPodStateOfGodel(pod *v1.Pod, schedulerName string) bool

func AssumedPod

func AssumedPod(pod *v1.Pod) bool

AssumedPod checks if the given pod is in assumed state

func AssumedPodOfGodel

func AssumedPodOfGodel(pod *v1.Pod, schedulerName string) bool

func BoundPod

func BoundPod(pod *v1.Pod) bool

BoundPod checks if the given pod is bound

func CanPodBePreempted

func CanPodBePreempted(pod *v1.Pod) int

CanPodBePreempted indicates whether the pod can be preempted -1: not pass 0: not sure 1: pass

func CleanupPodAnnotations

func CleanupPodAnnotations(client clientset.Interface, pod *v1.Pod) error

func ConvertToPod

func ConvertToPod(obj interface{}) (*v1.Pod, error)

func DispatchedPod

func DispatchedPod(pod *v1.Pod) bool

DispatchedPod checks if the given pod is in dispatched state

func DispatchedPodOfGodel

func DispatchedPodOfGodel(pod *v1.Pod, schedulerName string) bool

func DispatchedPodOfOtherScheduler

func DispatchedPodOfOtherScheduler(pod *v1.Pod, schedulerID string) bool

func DispatchedPodOfThisScheduler

func DispatchedPodOfThisScheduler(pod *v1.Pod, schedulerID string) bool

func FilteringUpdate

func FilteringUpdate(
	filterFn func(*v1.Pod) bool,
	addFunc func(*v1.Pod) error,
	updateFunc func(*v1.Pod, *v1.Pod) error,
	deleteFunc func(*v1.Pod) error,
	oldPod, newPod *v1.Pod,
)

func FindPort

func FindPort(pod *v1.Pod, svcPort *v1.ServicePort) (int, error)

FindPort locates the container port for the given pod and portName. If the targetPort is a number, use that. If the targetPort is a string, look that string up in all named ports in all containers in the target pod. If no match is found, fail.

func GeneratePodKey

func GeneratePodKey(pod *v1.Pod) string

func GetBestEffortPodAppName

func GetBestEffortPodAppName(pod *v1.Pod) string

func GetContainerStatus

func GetContainerStatus(statuses []v1.ContainerStatus, name string) (v1.ContainerStatus, bool)

GetContainerStatus extracts the status of container "name" from "statuses". It also returns if "name" exists.

func GetDefaultPriorityForGodelPod

func GetDefaultPriorityForGodelPod(pod *v1.Pod) int32

GetDefaultPriorityForGodelPod return the default priority. used by unit creation

func GetExistingContainerStatus

func GetExistingContainerStatus(statuses []v1.ContainerStatus, name string) v1.ContainerStatus

GetExistingContainerStatus extracts the status of container "name" from "statuses", It also returns if "name" exists.

func GetFailedSchedulersNames

func GetFailedSchedulersNames(pod *v1.Pod) sets.String

GetFailedSchedulersNames return failed schedulers of the given pod, from annotation failedSchedulers, in the format of sets.String

func GetOwnerInfo

func GetOwnerInfo(pod *v1.Pod) (string, string)

func GetOwnerInfoKey

func GetOwnerInfoKey(ownerInfo *OwnerInfo) string

func GetPodAlignedResources

func GetPodAlignedResources(pod *v1.Pod) ([]string, bool)

func GetPodCondition

func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodConditionFromList

func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.

func GetPodFullKey

func GetPodFullKey(namespace, name, uid string) string

func GetPodGroupName

func GetPodGroupName(pod *v1.Pod) string

GetPodGroupName return pod group name

func GetPodKey

func GetPodKey(pod *v1.Pod) string

func GetPodOwner

func GetPodOwner(pod *v1.Pod) string

func GetPodPriority

func GetPodPriority(pod *v1.Pod) int32

GetPodPriority returns priority of the given pod.

func GetPodReadyCondition

func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition

GetPodReadyCondition extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.

func GetPodRequest

func GetPodRequest(pod *v1.Pod, resourceType v1.ResourceName, format resource.Format) *resource.Quantity

func GetPodRequests

func GetPodRequests(pod *v1.Pod) map[string]*resource.Quantity

func GetProtectionDuration

func GetProtectionDuration(objectKey string, annotations map[string]string) (int64, bool)

func GetRSFromPod

func GetRSFromPod(pod *v1.Pod) (string, error)

func GetSchedulerNameForPod

func GetSchedulerNameForPod(pod *v1.Pod) string

func GetUIDFromPodFullKey

func GetUIDFromPodFullKey(key string) string

func IgnorePodsLimit

func IgnorePodsLimit(pod *v1.Pod) bool

func IsLongRunningTask

func IsLongRunningTask(pod *v1.Pod) bool

IsLongRunningTask checks if this pod is long-running task

func IsPodAvailable

func IsPodAvailable(pod *v1.Pod, minReadySeconds int32, now metav1.Time) bool

IsPodAvailable returns true if a pod is available; false otherwise. Precondition for an available pod is that it must be ready. On top of that, there are two cases when a pod can be considered available: 1. minReadySeconds == 0, or 2. LastTransitionTime (is set) + minReadySeconds < current time

func IsPodEligibleForPreemption

func IsPodEligibleForPreemption(pod *v1.Pod) bool

IsPodEligibleForPreemption returns false if a pod never preempts; true otherwise.

func IsPodReady

func IsPodReady(pod *v1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise.

func IsPodReadyConditionTrue

func IsPodReadyConditionTrue(status v1.PodStatus) bool

IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.

func IsPvcVolumeLocalPV

func IsPvcVolumeLocalPV(pvcLister corelisters.PersistentVolumeClaimLister, pvc string, pod *v1.Pod) (bool, string)

func IsSharedCores

func IsSharedCores(pod *v1.Pod) bool

func LegalPodResourceTypeAndLauncher

func LegalPodResourceTypeAndLauncher(pod *v1.Pod) bool

func NodeExists

func NodeExists(nodeName string, nodeLister lister.NodeLister, nmNodeLister nodelister.NMNodeLister) (bool, error)

NodeExists checks if the given node exists

func ParsePodKey

func ParsePodKey(str string) (string, string, types.UID, error)

func PendingPod

func PendingPod(pod *v1.Pod) bool

PendingPod checks if the given pod is in pending state

func PendingPodOfGodel

func PendingPodOfGodel(pod *v1.Pod, schedulerName string) bool

func PodHasDaemonSetOwnerReference

func PodHasDaemonSetOwnerReference(pod *v1.Pod) bool

TODO: revisit this.

func SchedulerExists

func SchedulerExists(schedulerName string, schedulerLister schedulerv1alpha1.SchedulerLister) (bool, error)

SchedulerExists checks if the given scheduler exists

func UpdatePodCondition

func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool

UpdatePodCondition updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the status has changed. Returns true if pod condition has changed or has been added.

func VisitContainers

func VisitContainers(podSpec *v1.PodSpec, mask ContainerType, visitor ContainerVisitor) bool

VisitContainers invokes the visitor function with a pointer to every container spec in the given pod spec with type set in mask. If visitor returns false, visiting is short-circuited. VisitContainers returns true if visiting completes, false if visiting was short-circuited.

func VisitPodConfigmapNames

func VisitPodConfigmapNames(pod *v1.Pod, visitor Visitor) bool

VisitPodConfigmapNames invokes the visitor function with the name of every configmap referenced by the pod spec. If visitor returns false, visiting is short-circuited. Transitive references (e.g. pod -> pvc -> pv -> secret) are not visited. Returns true if visiting completed, false if visiting was short-circuited.

func VisitPodSecretNames

func VisitPodSecretNames(pod *v1.Pod, visitor Visitor) bool

VisitPodSecretNames invokes the visitor function with the name of every secret referenced by the pod spec. If visitor returns false, visiting is short-circuited. Transitive references (e.g. pod -> pvc -> pv -> secret) are not visited. Returns true if visiting completed, false if visiting was short-circuited.

Types

type ContainerType

type ContainerType int

ContainerType signifies container type

const (
	// Containers is for normal containers
	Containers ContainerType = 1 << iota
	// InitContainers is for init containers
	InitContainers
	// EphemeralContainers is for ephemeral containers
	EphemeralContainers
)

func AllFeatureEnabledContainers

func AllFeatureEnabledContainers() ContainerType

AllFeatureEnabledContainers returns a ContainerType mask which includes all container types except for the ones guarded by feature gate.

type ContainerVisitor

type ContainerVisitor func(container *v1.Container, containerType ContainerType) (shouldContinue bool)

ContainerVisitor is called with each container spec, and returns true if visiting should continue.

type OwnerInfo

type OwnerInfo struct {
	// Owner type, e.g. ReplicaSet/StatefulSet...
	Type string `json:"type"`

	// Owner name
	Name string `json:"name"`

	// Owner namespace
	Namespace string `json:"namespace"`

	// Owner uid
	UID types.UID `json:"uid"`
}

func GetPodOwnerInfo

func GetPodOwnerInfo(pod *v1.Pod) *OwnerInfo

type PodLauncher

type PodLauncher string
const (
	Kubelet     PodLauncher = "kubelet"
	NodeManager PodLauncher = "node-manager"
)

func GetPodLauncher

func GetPodLauncher(pod *v1.Pod) (PodLauncher, error)

GetPodLauncher return the launcher of the given pod, only kubelet and node-manager are allowed.

type PodResourceType

type PodResourceType string

func GetPodResourceType

func GetPodResourceType(pod *v1.Pod) (PodResourceType, error)

GetPodResourceType return the resource type of the given pod only Guaranteed and BestEffort are allowed.

func GetResourceTypeFromQoS

func GetResourceTypeFromQoS(qosLevel string) PodResourceType

type PodState

type PodState string
const (
	PodNotInit    PodState = ""
	PodPending    PodState = "pending"
	PodDispatched PodState = "dispatched"
	PodAssumed    PodState = "assumed"
)

please refer to the file: pod_state_machine.go in the same package for pod state change diagram.

func GetPodState

func GetPodState(annotations map[string]string) PodState

type Visitor

type Visitor func(name string) (shouldContinue bool)

Visitor is called with each object name, and returns true if visiting should continue

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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