Skip to content

Commit

Permalink
fix: modify webhooks
Browse files Browse the repository at this point in the history
Signed-off-by: Rui-Gan <[email protected]>
  • Loading branch information
Rui-Gan committed Sep 29, 2024
1 parent 32dbd06 commit cd19935
Show file tree
Hide file tree
Showing 22 changed files with 1,178 additions and 877 deletions.
1 change: 1 addition & 0 deletions installer/helm/chart/volcano/config/volcano-admission.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#enableHierarchyCapacity: true
#resourceGroups:
#- resourceGroup: management # set the resource group name
# object:
Expand Down
3 changes: 3 additions & 0 deletions installer/helm/chart/volcano/templates/admission.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ rules:
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.volcano.sh"]
resources: ["podgroups"]
verbs: ["get", "list", "watch"]
- apiGroups: ["bus.volcano.sh"]
resources: ["commands"]
verbs: ["create"]

---
kind: ClusterRoleBinding
Expand Down
2 changes: 1 addition & 1 deletion installer/helm/chart/volcano/templates/scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ rules:
verbs: ["get", "list", "watch"]
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.volcano.sh"]
resources: ["queues"]
verbs: ["get", "list", "watch", "create", "delete"]
verbs: ["get", "list", "watch", "create", "delete", "update"]
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.volcano.sh"]
resources: ["queues/status"]
verbs: ["update"]
Expand Down
1 change: 1 addition & 0 deletions installer/helm/chart/volcano/templates/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ webhooks:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- queues
scope: '*'
Expand Down
7 changes: 6 additions & 1 deletion installer/volcano-development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ metadata:
namespace: volcano-system
data:
volcano-admission.conf: |
#enableHierarchyCapacity: true
#resourceGroups:
#- resourceGroup: management # set the resource group name
# object:
Expand Down Expand Up @@ -81,6 +82,9 @@ rules:
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.volcano.sh"]
resources: ["podgroups"]
verbs: ["get", "list", "watch"]
- apiGroups: ["bus.volcano.sh"]
resources: ["commands"]
verbs: ["create"]
---
# Source: volcano/templates/admission.yaml
kind: ClusterRoleBinding
Expand Down Expand Up @@ -4445,7 +4449,7 @@ rules:
verbs: ["get", "list", "watch"]
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.volcano.sh"]
resources: ["queues"]
verbs: ["get", "list", "watch", "create", "delete"]
verbs: ["get", "list", "watch", "create", "delete", "update"]
- apiGroups: ["scheduling.incubator.k8s.io", "scheduling.volcano.sh"]
resources: ["queues/status"]
verbs: ["update"]
Expand Down Expand Up @@ -5090,6 +5094,7 @@ webhooks:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- queues
scope: '*'
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/actions/preempt/preempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (pmpt *Action) preempt(
continue
}

victimsQueue := ssn.BuildVictimsPriorityQueue(victims, preemptor)
victimsQueue := ssn.BuildVictimsPriorityQueue(victims)
// Preempt victims for tasks, pick lowest priority task first.
preempted := api.EmptyResource()

Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/actions/reclaim/reclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (ra *Action) Execute(ssn *framework.Session) {
continue
}

victimsQueue := ssn.BuildVictimsPriorityQueue(victims, task)
victimsQueue := ssn.BuildVictimsPriorityQueue(victims)

resreq := task.InitResreq.Clone()
reclaimed := api.EmptyResource()
Expand Down
3 changes: 0 additions & 3 deletions pkg/scheduler/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ type LessFn func(interface{}, interface{}) bool
// CompareFn is the func declaration used by sort or priority queue.
type CompareFn func(interface{}, interface{}) int

// CompareFn is the func declaration used by sort or priority victims.
type VictimCompareFn func(interface{}, interface{}, interface{}) int

// ValidateFn is the func declaration used to check object's status.
type ValidateFn func(interface{}) bool

Expand Down
88 changes: 42 additions & 46 deletions pkg/scheduler/framework/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,22 @@ type Session struct {
Configurations []conf.Configuration
NodeList []*api.NodeInfo

plugins map[string]Plugin
eventHandlers []*EventHandler
jobOrderFns map[string]api.CompareFn
queueOrderFns map[string]api.CompareFn
taskOrderFns map[string]api.CompareFn
victimJobOrderFns map[string]api.VictimCompareFn
victimTaskOrderFns map[string]api.VictimCompareFn
clusterOrderFns map[string]api.CompareFn
predicateFns map[string]api.PredicateFn
prePredicateFns map[string]api.PrePredicateFn
bestNodeFns map[string]api.BestNodeFn
nodeOrderFns map[string]api.NodeOrderFn
batchNodeOrderFns map[string]api.BatchNodeOrderFn
nodeMapFns map[string]api.NodeMapFn
nodeReduceFns map[string]api.NodeReduceFn
preemptableFns map[string]api.EvictableFn
reclaimableFns map[string]api.EvictableFn
overusedFns map[string]api.ValidateFn
plugins map[string]Plugin
eventHandlers []*EventHandler
jobOrderFns map[string]api.CompareFn
queueOrderFns map[string]api.CompareFn
taskOrderFns map[string]api.CompareFn
clusterOrderFns map[string]api.CompareFn
predicateFns map[string]api.PredicateFn
prePredicateFns map[string]api.PrePredicateFn
bestNodeFns map[string]api.BestNodeFn
nodeOrderFns map[string]api.NodeOrderFn
batchNodeOrderFns map[string]api.BatchNodeOrderFn
nodeMapFns map[string]api.NodeMapFn
nodeReduceFns map[string]api.NodeReduceFn
preemptableFns map[string]api.EvictableFn
reclaimableFns map[string]api.EvictableFn
overusedFns map[string]api.ValidateFn
// preemptiveFns means whether current queue can reclaim from other queue,
// while reclaimableFns means whether current queue's resources can be reclaimed.
preemptiveFns map[string]api.ValidateWithCandidateFn
Expand Down Expand Up @@ -126,34 +124,32 @@ func openSession(cache cache.Cache) *Session {
RevocableNodes: map[string]*api.NodeInfo{},
Queues: map[api.QueueID]*api.QueueInfo{},

plugins: map[string]Plugin{},
jobOrderFns: map[string]api.CompareFn{},
queueOrderFns: map[string]api.CompareFn{},
taskOrderFns: map[string]api.CompareFn{},
victimJobOrderFns: map[string]api.VictimCompareFn{},
victimTaskOrderFns: map[string]api.VictimCompareFn{},
clusterOrderFns: map[string]api.CompareFn{},
predicateFns: map[string]api.PredicateFn{},
prePredicateFns: map[string]api.PrePredicateFn{},
bestNodeFns: map[string]api.BestNodeFn{},
nodeOrderFns: map[string]api.NodeOrderFn{},
batchNodeOrderFns: map[string]api.BatchNodeOrderFn{},
nodeMapFns: map[string]api.NodeMapFn{},
nodeReduceFns: map[string]api.NodeReduceFn{},
preemptableFns: map[string]api.EvictableFn{},
reclaimableFns: map[string]api.EvictableFn{},
overusedFns: map[string]api.ValidateFn{},
preemptiveFns: map[string]api.ValidateWithCandidateFn{},
allocatableFns: map[string]api.AllocatableFn{},
jobReadyFns: map[string]api.ValidateFn{},
jobPipelinedFns: map[string]api.VoteFn{},
jobValidFns: map[string]api.ValidateExFn{},
jobEnqueueableFns: map[string]api.VoteFn{},
jobEnqueuedFns: map[string]api.JobEnqueuedFn{},
targetJobFns: map[string]api.TargetJobFn{},
reservedNodesFns: map[string]api.ReservedNodesFn{},
victimTasksFns: map[string][]api.VictimTasksFn{},
jobStarvingFns: map[string]api.ValidateFn{},
plugins: map[string]Plugin{},
jobOrderFns: map[string]api.CompareFn{},
queueOrderFns: map[string]api.CompareFn{},
taskOrderFns: map[string]api.CompareFn{},
clusterOrderFns: map[string]api.CompareFn{},
predicateFns: map[string]api.PredicateFn{},
prePredicateFns: map[string]api.PrePredicateFn{},
bestNodeFns: map[string]api.BestNodeFn{},
nodeOrderFns: map[string]api.NodeOrderFn{},
batchNodeOrderFns: map[string]api.BatchNodeOrderFn{},
nodeMapFns: map[string]api.NodeMapFn{},
nodeReduceFns: map[string]api.NodeReduceFn{},
preemptableFns: map[string]api.EvictableFn{},
reclaimableFns: map[string]api.EvictableFn{},
overusedFns: map[string]api.ValidateFn{},
preemptiveFns: map[string]api.ValidateWithCandidateFn{},
allocatableFns: map[string]api.AllocatableFn{},
jobReadyFns: map[string]api.ValidateFn{},
jobPipelinedFns: map[string]api.VoteFn{},
jobValidFns: map[string]api.ValidateExFn{},
jobEnqueueableFns: map[string]api.VoteFn{},
jobEnqueuedFns: map[string]api.JobEnqueuedFn{},
targetJobFns: map[string]api.TargetJobFn{},
reservedNodesFns: map[string]api.ReservedNodesFn{},
victimTasksFns: map[string][]api.VictimTasksFn{},
jobStarvingFns: map[string]api.ValidateFn{},
}

snapshot := cache.Snapshot()
Expand Down
64 changes: 8 additions & 56 deletions pkg/scheduler/framework/session_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ func (ssn *Session) AddTaskOrderFn(name string, cf api.CompareFn) {
ssn.taskOrderFns[name] = cf
}

// AddVictimJobOrderFn add victimjoborder function
func (ssn *Session) AddVictimJobOrderFn(name string, vcf api.VictimCompareFn) {
ssn.victimJobOrderFns[name] = vcf
}

// AddVictimTaskOrderFn add victimtaskorder function
func (ssn *Session) AddVictimTaskOrderFn(name string, vcf api.VictimCompareFn) {
ssn.victimTaskOrderFns[name] = vcf
}

// AddPreemptableFn add preemptable function
func (ssn *Session) AddPreemptableFn(name string, cf api.EvictableFn) {
ssn.preemptableFns[name] = cf
Expand Down Expand Up @@ -555,29 +545,6 @@ func (ssn *Session) JobOrderFn(l, r interface{}) bool {
return lv.CreationTimestamp.Before(&rv.CreationTimestamp)
}

// VictimJobOrderFn invoke victimjoborder function of the plugins
func (ssn *Session) VictimJobOrderFn(l, r, preemptor interface{}) bool {
for _, tier := range ssn.Tiers {
for _, plugin := range tier.Plugins {
jof, found := ssn.victimJobOrderFns[plugin.Name]
if !found {
continue
}
if j := jof(l, r, preemptor); j != 0 {
return j < 0
}
}
}

lv := l.(*api.JobInfo)
rv := r.(*api.JobInfo)
if lv.Queue != rv.Queue {
return !ssn.QueueOrderFn(ssn.Queues[lv.Queue], ssn.Queues[rv.Queue])
}

return !ssn.JobOrderFn(l, r)
}

// ClusterOrderFn invoke ClusterOrderFn function of the plugins
func (ssn *Session) ClusterOrderFn(l, r interface{}) bool {
for _, tier := range ssn.Tiers {
Expand Down Expand Up @@ -659,23 +626,6 @@ func (ssn *Session) TaskOrderFn(l, r interface{}) bool {
return helpers.CompareTask(lv, rv)
}

// VictimTaskOrderFn invoke victimtaskorder function of the plugins
func (ssn *Session) VictimTaskOrderFn(l, r, preemptor interface{}) bool {
for _, tier := range ssn.Tiers {
for _, plugin := range tier.Plugins {
tof, found := ssn.victimTaskOrderFns[plugin.Name]
if !found {
continue
}
if j := tof(l, r, preemptor); j != 0 {
return j < 0
}
}
}

return !ssn.TaskOrderFn(l, r)
}

// PredicateFn invoke predicate function of the plugins
func (ssn *Session) PredicateFn(task *api.TaskInfo, node *api.NodeInfo) error {
for _, tier := range ssn.Tiers {
Expand Down Expand Up @@ -841,19 +791,21 @@ func (ssn *Session) NodeOrderReduceFn(task *api.TaskInfo, pluginNodeScoreMap map
// BuildVictimsPriorityQueue returns a priority queue with victims sorted by:
// if victims has same job id, sorted by !ssn.TaskOrderFn
// if victims has different job id, sorted by !ssn.JobOrderFn
func (ssn *Session) BuildVictimsPriorityQueue(victims []*api.TaskInfo, preemptor *api.TaskInfo) *util.PriorityQueue {
func (ssn *Session) BuildVictimsPriorityQueue(victims []*api.TaskInfo) *util.PriorityQueue {
victimsQueue := util.NewPriorityQueue(func(l, r interface{}) bool {
lv := l.(*api.TaskInfo)
rv := r.(*api.TaskInfo)
if lv.Job == rv.Job {
return ssn.VictimTaskOrderFn(l, r, preemptor)
return !ssn.TaskOrderFn(l, r)
}

preemptorJob := ssn.Jobs[preemptor.Job]
lvJob := ssn.Jobs[lv.Job]
rvJob := ssn.Jobs[rv.Job]
lvJob, lvJobFound := ssn.Jobs[lv.Job]
rvJob, rvJobFound := ssn.Jobs[rv.Job]
if lvJobFound && rvJobFound && lvJob.Queue != rvJob.Queue {
return !ssn.QueueOrderFn(ssn.Queues[lvJob.Queue], ssn.Queues[rvJob.Queue])
}

return ssn.VictimJobOrderFn(lvJob, rvJob, preemptorJob)
return !ssn.JobOrderFn(lvJob, rvJob)
})
for _, victim := range victims {
victimsQueue.Push(victim)
Expand Down
Loading

0 comments on commit cd19935

Please sign in to comment.