-
Notifications
You must be signed in to change notification settings - Fork 48
/
priorities.go
38 lines (31 loc) · 1.15 KB
/
priorities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"log"
"math/rand"
extender "k8s.io/kube-scheduler/extender/v1"
)
// It'd better to only define one custom priority per extender
// as current extender interface only supports one single weight mapped to one extender
// and also it returns HostPriorityList, rather than []HostPriorityList
const (
// lucky priority gives a random [0, extender.MaxPriority] score
// currently extender.MaxPriority is 10
luckyPrioMsg = "pod %v/%v is lucky to get score %v\n"
)
// it's webhooked to pkg/scheduler/core/generic_scheduler.go#prioritizeNodes()
// you can't see existing scores calculated so far by default scheduler
// instead, scores output by this function will be added back to default scheduler
func prioritize(args extender.ExtenderArgs) *extender.HostPriorityList {
pod := args.Pod
nodes := args.Nodes.Items
hostPriorityList := make(extender.HostPriorityList, len(nodes))
for i, node := range nodes {
score := rand.Int63n(extender.MaxExtenderPriority + 1)
log.Printf(luckyPrioMsg, pod.Name, pod.Namespace, score)
hostPriorityList[i] = extender.HostPriority{
Host: node.Name,
Score: score,
}
}
return &hostPriorityList
}