//// pkg/controller/annotator/binding.go
// Binding is a concise struction of pod binding records,
// which consists of pod name, namespace name, node name and accurate timestamp.
// Note that we only record temporary Binding imformation.
type Binding struct {
Node string
Namespace string
PodName string
Timestamp int64
}
// BindingHeap is a Heap struction storing Binding imfromation.
type BindingHeap []*Binding
//// pkg/controller/annotator/node.go - annotateNodeHotValue()
func annotateNodeHotValue(kubeClient clientset.Interface, br *BindingRecords, node *v1.Node, policy policy.DynamicSchedulerPolicy) error {
var value int
// 遍历调度策略配置HotValue字段,根据每一个策略计算出来的pod数量/p.count作为热点值,并进行累加
for _, p := range policy.Spec.HotValue {
value += br.GetLastNodeBindingCount(node.Name, p.TimeRange.Duration) / p.Count
}
return patchNodeAnnotation(kubeClient, node, HotValueKey, strconv.Itoa(value))
}
//// pkg/controller/annotator/node.go - GetLastNodeBindingCount()
// 计算对应节点在最近一段时间调度的pod数量
func (br *BindingRecords) GetLastNodeBindingCount(node string, timeRange time.Duration) int {
br.rw.RLock()
defer br.rw.RUnlock()
cnt, timeline := 0, time.Now().UTC().Unix()-int64(timeRange.Seconds())
for _, binding := range *br.bindings {
if binding.Timestamp > timeline && binding.Node == node {
cnt++
}
}
klog.V(4).Infof("The total Binding count is %d, while node[%s] count is %d",
len(*br.bindings), node, cnt)
return cnt
}