// bindingCycle tries to bind an assumed Pod. func(sched *Scheduler) bindingCycle( ctx context.Context, // 调度上下文 state *framework.CycleState, // 调度周期状态 fwk framework.Framework, // 调度框架 scheduleResult ScheduleResult, // 调度结果 assumedPodInfo *framework.QueuedPodInfo, // 假定的 Pod 信息 start time.Time, // 绑定周期开始时间 podsToActivate *framework.PodsToActivate) *framework.Status { // 待激活的 Pods
assumedPod := assumedPodInfo.Pod // 获取假定的 Pod
// 运行 "permit" 插件,检查是否允许绑定操作 if status := fwk.WaitOnPermit(ctx, assumedPod); !status.IsSuccess() { return status }
// 运行 "prebind" 插件,执行绑定前的检查和操作 if status := fwk.RunPreBindPlugins(ctx, state, assumedPod, scheduleResult.SuggestedHost); !status.IsSuccess() { return status }
// 运行 "bind" 插件,实际执行 Pod 到节点的绑定操作 if status := sched.bind(ctx, fwk, assumedPod, scheduleResult.SuggestedHost, state); !status.IsSuccess() { return status }
// 日志记录 Pod 绑定成功的信息 klog.V(2).InfoS("Successfully bound pod to node", "pod", klog.KObj(assumedPod), "node", scheduleResult.SuggestedHost, "evaluatedNodes", scheduleResult.EvaluatedNodes, "feasibleNodes", scheduleResult.FeasibleNodes)
// 更新 Pod 调度的指标 metrics.PodScheduled(fwk.ProfileName(), metrics.SinceInSeconds(start)) metrics.PodSchedulingAttempts.Observe(float64(assumedPodInfo.Attempts)) metrics.PodSchedulingDuration.WithLabelValues(getAttemptsLabel(assumedPodInfo)).Observe(metrics.SinceInSeconds(assumedPodInfo.InitialAttemptTimestamp))
// WaitOnPermit will block, if the pod is a waiting pod, until the waiting pod is rejected or allowed. func(f *frameworkImpl) WaitOnPermit(ctx context.Context, pod *v1.Pod) *framework.Status { waitingPod := f.waitingPods.get(pod.UID) // 根据pod的id来查看其是否在等待队列中 if waitingPod == nil { returnnil// 如果不在等待队列中,直接返回 } defer f.waitingPods.remove(pod.UID) // 无论函数如何结束,都从等待列表中移除该 Pod
klog.V(4).InfoS("Pod waiting on permit", "pod", klog.KObj(pod)) // 日志记录 Pod 正在等待许可
// bind binds a pod to a given node defined in a binding object. // The precedence for binding is: (1) extenders and (2) framework plugins. // We expect this to run asynchronously, so we handle binding metrics internally. func(sched *Scheduler) bind(ctx context.Context, fwk framework.Framework, assumed *v1.Pod, targetNode string, state *framework.CycleState) (status *framework.Status) { deferfunc() { sched.finishBinding(fwk, assumed, targetNode, status) }()