pod

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: 23 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"

	MovementNameKey = "godel.bytedance.com/movement-name"

	// Pods with same request template share the same requirements.
	PodRequestTemplateAnnotationKey = "godel.bytedance.com/request-template"
	// reservation related
	MatchedReservationPlaceholderKey = "godel.bytedance.com/matched-reservation-placeholder"
	ReservationTTLKey                = "godel.bytedance.com/reservation-ttl"
)
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"
	RequestTemplateKind  = "RequestTemplate"

	KeySeperator string = "/"
)
View Source
const (
	PodResourceReservationAnnotationForGodel = "godel.bytedance.com/reservation"
	PodHasReservationRequirement             = "true"
	PodResourceReservationAnnotation         = "pod.tce.kubernetes.io/reservation"
	// In memory object annotation for reservation placeholderPod.
	ReservationPlaceHolderPodAnnotation = "godel.bytedance.com/reservation-placeholder"
	IsReservationPlaceHolderPods        = "true"
	ReservationIndexAnnotation          = "godel.bytedance.com/reservation-index"
	PlaceholderPodUIDAnno               = "godel.bytedance.com/placeholder-uid"
	ReservationOwnerTypeAnno            = "godel.bytedance.com/reservation-owner-type"
	ReservationOwnerNameAnno            = "godel.bytedance.com/reservation-owner"
	ReservationOriginalPodNameAnno      = "godel.bytedance.com/reservation-original-pod"
)
View Source
const (
	AlignedResources = "godel.bytedance.com/aligned-resources"
)

AllContainers specifies that all containers be visited

View Source
const PodKeySeperator string = "/"
View Source
const RSKind = "ReplicaSet"
View Source
const ReservationPlaceholderPostFix = "-placeholder"

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 ConstructReservationAccordingToPod

func ConstructReservationAccordingToPod(pod *v1.Pod, defaultTTL int64) (res *schedulingv1alpha1.Reservation, err error)

TODO: make Reservation & fakepod relationship simple & clean.

func ConvertReservationToPod

func ConvertReservationToPod(res *schedulingv1alpha1.Reservation) *v1.Pod

func ConvertToPod

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

func CreateReservationFakePod

func CreateReservationFakePod(pod *v1.Pod) *v1.Pod

func CreateReservationFakePodForAssume

func CreateReservationFakePodForAssume(pod *v1.Pod) *v1.Pod

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 GetMatchedReservationPlaceholderPod

func GetMatchedReservationPlaceholderPod(pod *v1.Pod) string

func GetMovementNameFromPod

func GetMovementNameFromPod(pod *v1.Pod) string

func GetOwnerInfo

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

func GetOwnerInfoKey

func GetOwnerInfoKey(ownerInfo *schedulingv1a1.OwnerInfo) string

func GetPlaceholderFromReservation

func GetPlaceholderFromReservation(res *schedulingv1alpha1.Reservation) 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 GetPodGroupOwnerInfo

func GetPodGroupOwnerInfo(pod *v1.Pod) *schedulingv1a1.OwnerInfo

func GetPodKey

func GetPodKey(pod *v1.Pod) string

func GetPodOwner

func GetPodOwner(pod *v1.Pod) string

TODO: Convergence related function calls. GetPodOwner will consider PodGroup as well.

func GetPodOwnerInfo

func GetPodOwnerInfo(pod *v1.Pod) *schedulingv1a1.OwnerInfo

func GetPodOwnerInfoKey

func GetPodOwnerInfoKey(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 GetPodReservationTimeoutPeriod

func GetPodReservationTimeoutPeriod(pod *v1.Pod) int64

func GetPodTemplateKey

func GetPodTemplateKey(pod *v1.Pod) string

func GetPodUID

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

func GetProtectionDuration

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

func GetQoSLevelForPod

func GetQoSLevelForPod(pod *v1.Pod) util.QoSLevel

func GetRSFromPod

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

func GetReservationIndex

func GetReservationIndex(pod *v1.Pod) string

func GetReservationKey

func GetReservationKey(res *schedulingv1alpha1.Reservation) string

func GetReservationPlaceholder

func GetReservationPlaceholder(pod *v1.Pod) string

TODO: re-implement this, can not get deployment name from annotation

func GetSchedulerNameForPod

func GetSchedulerNameForPod(pod *v1.Pod) string

func GetSelectedNodeOfLpv

func GetSelectedNodeOfLpv(pvcLister corelisters.PersistentVolumeClaimLister, pod *v1.Pod) (nodename string)

func GetUIDFromPodFullKey

func GetUIDFromPodFullKey(key string) string

func HasMatchedReservationPlaceholder

func HasMatchedReservationPlaceholder(pod *v1.Pod) bool

func HasReservationRequirement

func HasReservationRequirement(pod *v1.Pod) bool

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 IsPlaceholderPod

func IsPlaceholderPod(p *v1.Pod) bool

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 IsReservationPlaceholderPod

func IsReservationPlaceholderPod(pod *v1.Pod) bool

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 ShouldOccupyResources

func ShouldOccupyResources(res *schedulingv1alpha1.Reservation) bool

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 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