From 29c3b213c4303c70bd153f7bf8afae4f66a08898 Mon Sep 17 00:00:00 2001 From: "wangyuqing (C)" Date: Tue, 9 Jul 2019 09:49:05 +0800 Subject: [PATCH] calc PGMinResources for Resources.Limits --- pkg/controllers/job/job_controller_actions.go | 2 +- pkg/controllers/job/job_controller_util.go | 12 ++++++++++-- pkg/controllers/job/job_controller_util_test.go | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/controllers/job/job_controller_actions.go b/pkg/controllers/job/job_controller_actions.go index 6e17e631b0..8d4b156958 100644 --- a/pkg/controllers/job/job_controller_actions.go +++ b/pkg/controllers/job/job_controller_actions.go @@ -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) } } } diff --git a/pkg/controllers/job/job_controller_util.go b/pkg/controllers/job/job_controller_util.go index 75aa604857..0dee416156 100644 --- a/pkg/controllers/job/job_controller_util.go +++ b/pkg/controllers/job/job_controller_util.go @@ -176,8 +176,8 @@ 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 { @@ -185,6 +185,14 @@ func addResourceList(list, new v1.ResourceList) { 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 diff --git a/pkg/controllers/job/job_controller_util_test.go b/pkg/controllers/job/job_controller_util_test.go index cb63ae51ab..afd5337606 100644 --- a/pkg/controllers/job/job_controller_util_test.go +++ b/pkg/controllers/job/job_controller_util_test.go @@ -642,7 +642,7 @@ func TestAddResourceList(t *testing.T) { } for _, testcase := range testcases { - addResourceList(testcase.List, testcase.New) + addResourceList(testcase.List, testcase.New, nil) } }