Skip to content

Commit

Permalink
Merge pull request #309 from wangyuqing4/resource
Browse files Browse the repository at this point in the history
calc PGMinResources for Resources.Limits
  • Loading branch information
volcano-sh-bot authored Jul 9, 2019
2 parents b3112a7 + 29c3b21 commit 7b1aefe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/job/job_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (cc *Controller) calcPGMinResources(job *vkv1.Job) *v1.ResourceList {
}
podCnt++
for _, c := range task.Template.Spec.Containers {
addResourceList(minAvailableTasksRes, c.Resources.Requests)
addResourceList(minAvailableTasksRes, c.Resources.Requests, c.Resources.Limits)
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/controllers/job/job_controller_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,23 @@ func applyPolicies(job *vkv1.Job, req *apis.Request) vkv1.Action {
return vkv1.SyncJobAction
}

func addResourceList(list, new v1.ResourceList) {
for name, quantity := range new {
func addResourceList(list, req, limit v1.ResourceList) {
for name, quantity := range req {
if value, ok := list[name]; !ok {
list[name] = *quantity.Copy()
} else {
value.Add(quantity)
list[name] = value
}
}

// If Requests is omitted for a container,
// it defaults to Limits if that is explicitly specified.
for name, quantity := range limit {
if _, ok := list[name]; !ok {
list[name] = *quantity.Copy()
}
}
}

//TaskPriority structure
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/job/job_controller_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func TestAddResourceList(t *testing.T) {
}

for _, testcase := range testcases {
addResourceList(testcase.List, testcase.New)
addResourceList(testcase.List, testcase.New, nil)
}
}

Expand Down

0 comments on commit 7b1aefe

Please sign in to comment.