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) } }