internal

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsBadRequestPanic

func AsBadRequestPanic()

Wrap and Rethrow Panic as BadRequestError Panic

func BindPod

func BindPod(kClient kubeClient.Interface, bindingPod *core.Pod)

func CreateClient

func CreateClient(kConfig *rest.Config) kubeClient.Interface

func ExtractPodBindAnnotations

func ExtractPodBindAnnotations(allocatedPod *core.Pod) map[string]string

func ExtractPodBindInfo

func ExtractPodBindInfo(allocatedPod *core.Pod) *si.PodBindInfo

PodBindInfo comes from internal, so just need to assert when deserialization.

func ExtractPodSchedulingSpec

func ExtractPodSchedulingSpec(pod *core.Pod) *si.PodSchedulingSpec

PodSchedulingSpec comes from external, so need more Defaulting and Validation when deserialization.

func GetKey

func GetKey(obj interface{}) (string, error)

func HandleInformerPanic

func HandleInformerPanic(logPfx string, logOnSucceeded bool)

Recover User Error Panic Rethrow Platform Error Panic

func HandleRoutinePanic

func HandleRoutinePanic(logPfx string)

Wrap and Rethrow Panic

func HandleWebServerPanic

func HandleWebServerPanic(handler func(*si.WebServerError))

Log and Recover Panic

func IsAllocated

func IsAllocated(state PodState) bool

func IsBound

func IsBound(pod *core.Pod) bool

Scheduler only can see live Pod, so the IsLive() check is usually redundant. A bound Pod means it is currently holding its requested resources.

func IsCompleted

func IsCompleted(pod *core.Pod) bool

func IsHivedEnabled

func IsHivedEnabled(pod *core.Pod) bool

func IsInterested

func IsInterested(pod *core.Pod) bool

Aligned with K8S HTTPExtender, so that Informer is also aligned with WebServer.

func IsLive

func IsLive(pod *core.Pod) bool

func IsNodeHealthy added in v0.3.0

func IsNodeHealthy(node *core.Node) bool

A node is considered healthy if it is not unschedulable and in ready condition.

func IsUnbound

func IsUnbound(pod *core.Pod) bool

An unbound Pod means it is currently waiting on its requested resources.

func Key

func Key(p *core.Pod) string

func NewBadRequestError

func NewBadRequestError(message string) *si.WebServerError

func NewBindingPod

func NewBindingPod(pod *core.Pod, podBindInfo *si.PodBindInfo) *core.Pod

func SplitKey

func SplitKey(key string) (namespace, name string, err error)

func ToNode

func ToNode(obj interface{}) *core.Node

obj should come from Node SharedIndexInformer, otherwise may panic.

func ToPod

func ToPod(obj interface{}) *core.Pod

obj should come from Pod SharedIndexInformer, otherwise may panic.

Types

type ExtenderHandlers

type ExtenderHandlers struct {
	FilterHandler  func(args ei.ExtenderArgs) *ei.ExtenderFilterResult
	BindHandler    func(args ei.ExtenderBindingArgs) *ei.ExtenderBindingResult
	PreemptHandler func(args ei.ExtenderPreemptionArgs) *ei.ExtenderPreemptionResult
}

WebServer Callbacks with K8S Default Scheduler Notes:

  1. Error should be delivered by panic
  2. Should not assume previous succeeded operation also has been successfully executed by K8S Default Scheduler.

type InspectHandlers added in v0.2.4

type InspectHandlers struct {
	GetAllAffinityGroupsHandler        func() si.AffinityGroupList
	GetAffinityGroupHandler            func(groupName string) si.AffinityGroup
	GetClusterStatusHandler            func() si.ClusterStatus
	GetPhysicalClusterStatusHandler    func() si.PhysicalClusterStatus
	GetAllVirtualClustersStatusHandler func() map[si.VirtualClusterName]si.VirtualClusterStatus
	GetVirtualClusterStatusHandler     func(vcName si.VirtualClusterName) si.VirtualClusterStatus
}

type PodKey

type PodKey struct {
	Namespace string
	Name      string
	UID       types.UID
}

func NewPodKey

func NewPodKey(namespace string, name string, uid types.UID) *PodKey

func (*PodKey) String

func (pk *PodKey) String() string

type PodPreemptInfo

type PodPreemptInfo struct {
	// Only need to include the victim Pods for the current preemptor Pod.
	// Need to ensure the newly deleted victim Pods are eventually removed from here,
	// otherwise, the default scheduler refuse to execute any preemption.
	// Need to ensure the newly added victim Pods are eventually added to here,
	// otherwise, the preemption will never complete.
	// It can be empty, such as current preemptor Pod is waiting for the victim Pods
	// of other preemptor Pods in the same group to be preempted.
	// It can contain victim Pods across multiple nodes, such as a victim group may
	// contain Pods across multiple nodes.
	VictimPods []*core.Pod
}

No need to use it recover scheduler preempting resource

type PodScheduleResult

type PodScheduleResult struct {
	PodWaitInfo    *PodWaitInfo
	PodPreemptInfo *PodPreemptInfo
	PodBindInfo    *si.PodBindInfo
}

Notes:

  1. If the SchedulerAlgorithm found sufficient free resource, only PodBindInfo should be set. If the SchedulerAlgorithm found sufficient preemptible resource, only PodPreemptInfo should be set. Otherwise, only PodWaitInfo can be optionally set.
  2. The selected node in PodBindInfo requires:
  3. Must be within candidateNodes: All existing nodes which can be constructed from AddNode/DeleteNode. Otherwise, the Pod after bound will be probably deleted by the GarbageCollectionController.
  4. Better to be within suggestedNodes: The input parameter of Schedule(). Otherwise, the Pod after bound will not respect previous pod schedule decision from K8S Default Scheduler, i.e. this binding is incompatible with K8S Default Scheduler.

type PodScheduleStatus

type PodScheduleStatus struct {
	// The Pod which will be used in current PodState.
	// For example, in PodBinding state, it should be a Pod used to bind,
	// i.e. with all placements set in the Pod.
	Pod      *core.Pod
	PodState PodState
	// The already tried Pod binding attempts, i.e. the scheduled times for a Pod
	// in PodBinding state.
	PodBindAttempts   int32
	PodScheduleResult *PodScheduleResult
}

Used to track the PodScheduleResult

type PodScheduleStatuses

type PodScheduleStatuses map[types.UID]*PodScheduleStatus

PodUID -> PodScheduleStatus

type PodState

type PodState string
const (
	// Pod is waiting for preemptible or free resource to appear.
	// [StartState]
	// -> PodPreempting
	// -> PodBinding
	PodWaiting PodState = "Waiting"

	// Pod is waiting for the appeared preemptible resource to be free by preemption.
	// -> PodBinding
	// -> PodWaiting
	PodPreempting PodState = "Preempting"

	// Pod is binding on the free resource.
	// [AllocatedState]
	// -> PodBound
	PodBinding PodState = "Binding"

	// Pod is bound on the free resource.
	// [FinalState]
	// [AllocatedState]
	PodBound PodState = "Bound"
)

[AllocatedState]: The Pod is considered to be allocated from the scheduler view.

const PodUnknown PodState = "Unknown"

[VirtualState]: This state is not tracked in PodScheduleStatuses.

Pod is unknown for the scheduler, such as the Pod does not exist, completed or has not been informed to the scheduler.

A completed Pod is the same as a deleted Pod from the scheduler view and they will never be informed to the scheduler, thus they are rejected to be scheduled. However, the not yet informed not completed Pod will be eventually informed to the scheduler, then transition to not VirtualState, thus they are accepted to be scheduled.

This state can be transitioned from any state, but can only transition to: -> PodWaiting -> PodBound

type PodWaitInfo

type PodWaitInfo struct {
	// The reason why no preemptible or free resource to allocate the Pod now.
	Reason string
}

No need to use it recover scheduler waiting resource

type SchedulerAlgorithm

type SchedulerAlgorithm interface {
	// See details in SchedulingPhase and PodScheduleResult.
	Schedule(pod *core.Pod, suggestedNodes []string, phase SchedulingPhase) PodScheduleResult

	// Track all current Nodes in the whole cluster.
	AddNode(node *core.Node)
	UpdateNode(oldNode, newNode *core.Node)
	DeleteNode(node *core.Node)

	// Track all current unallocated and allocated Pods in the whole cluster.
	// Unallocated Pod includes both PodWaiting and PodPreempting Pods.
	AddUnallocatedPod(pod *core.Pod)
	DeleteUnallocatedPod(pod *core.Pod)
	// Allocated Pod includes both PodBound and PodBinding Pods.
	AddAllocatedPod(pod *core.Pod)
	DeleteAllocatedPod(pod *core.Pod)

	// Expose current scheduling status
	GetAllAffinityGroups() si.AffinityGroupList
	GetAffinityGroup(name string) si.AffinityGroup
	GetClusterStatus() si.ClusterStatus
	GetPhysicalClusterStatus() si.PhysicalClusterStatus
	GetAllVirtualClustersStatus() map[si.VirtualClusterName]si.VirtualClusterStatus
	GetVirtualClusterStatus(si.VirtualClusterName) si.VirtualClusterStatus
}

SchedulerAlgorithm is used to make the pod schedule decision based on its whole cluster scheduling view constructed from its Add/Update/Delete callbacks. Notes:

  1. Error should be delivered by panic and it will not change any state. For WebServer Callbacks, all Panics will be recovered as error responses, see HandleInformerPanic. For Informer Callbacks, only User Error Panics will be recovered as error logs, other Panics will crash the whole process, see HandleWebServerPanic.
  2. Should take all the input parameters as readonly and return pod schedule decision by PodScheduleResult.
  3. {Schedule, AddUnallocatedPod, DeleteUnallocatedPod, AddAllocatedPod, DeleteAllocatedPod} will never be executed concurrently for all pods.
  4. [Schedule -> (AddAllocatedPod) -> Schedule -> ...] is executed sequentially for all pods. I.e. the constructed scheduling view is already lock protected.
  5. [START -> AddAllocatedPod -> DeleteAllocatedPod -> END] is executed sequentially for one specific Pod. I.e. once a specific Pod is allocated by AddAllocatedPod, its placement will never be changed to another one.

type SchedulingPhase added in v0.3.1

type SchedulingPhase string
const (
	// The Schedule is called during filterRoutine:
	// The suggestedNodes contain all nodes that can fit the pod without any
	// lower priority Pods preempted.
	FilteringPhase SchedulingPhase = "Filtering"

	// The Schedule is called during preemptRoutine:
	// The suggestedNodes contain all nodes that can fit the pod after all
	// lower priority Pods preempted.
	PreemptingPhase SchedulingPhase = "Preempting"
)

Jump to

Keyboard shortcuts

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