internal

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 12 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 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 could be *core.Node or cache.DeletedFinalStateUnknown.

func ToPod

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

obj could be *core.Pod or cache.DeletedFinalStateUnknown.

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 passed by panic
  2. Should not assume previous succeeded operation also has been successfully executed by K8S Default Scheduler.

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 preemptable 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 preemptable or free resource to appear.
	// [StartState]
	// -> PodPreempting
	// -> PodBinding
	PodWaiting PodState = "Waiting"

	// Pod is waiting for the appeared preemptable 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 {
	// NodeName ->  The reason why the node cannot be used for the Pod to allocate.
	FailedNodeReasons map[string]string
}

No need to use it recover scheduler waiting resource

type SchedulerAlgorithm

type SchedulerAlgorithm interface {
	// See details in PodScheduleResult.
	Schedule(pod *core.Pod, suggestedNodes []string) 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 allocated Pods in the whole cluster.
	// Allocated Pod includes both PodBound and PodBinding Pods.
	AddAllocatedPod(pod *core.Pod)
	DeleteAllocatedPod(pod *core.Pod)
}

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 passed by panic
  2. Should take all the input parameters as readonly and return pod schedule decision by PodScheduleResult.
  3. {Schedule, 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.

Jump to

Keyboard shortcuts

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