Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Take init containers into account when getting pod resource request #638

Merged
merged 1 commit into from
Mar 16, 2019

Conversation

hex108
Copy link
Contributor

@hex108 hex108 commented Mar 13, 2019

What this PR does / why we need it:
Take init containers into account when getting pod resource request. The code refers k8s.io/kubernetes/pkg/scheduler/algorithm/predicates/predicates.go#GetResourceRequest.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Release note:

Take init containers into account when getting pod resource request

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 13, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 13, 2019
@k82cn
Copy link
Contributor

k82cn commented Mar 14, 2019

/approve

LGTM overall, let's get it merged when CI is happy :)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hex108, k82cn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 14, 2019
@hex108
Copy link
Contributor Author

hex108 commented Mar 15, 2019

@k82cn I'll look into it.

I checked the code of k8s scheduler again, and found it only consider init containers' resource request for the predicate PodFitsResource, it will not calculate them when adding it to node's total requested resource. Need we be consistent with this behavior?

Another question: is there any reason to use float64 instead of int64 to record pod resource?

@k82cn
Copy link
Contributor

k82cn commented Mar 15, 2019

Need we be consistent with this behavior?

Yes; we allocate resources in allocate action so PodFitsResource is not necessary; but initContainer is still necessary :)

Another question: is there any reason to use float64 instead of int64 to record pod resource?

We used to use CPU instead of MillCPU, so float64 is there.

@hex108 hex108 force-pushed the init_container branch 3 times, most recently from 691f73f to 6de00e0 Compare March 15, 2019 02:40
@hex108
Copy link
Contributor Author

hex108 commented Mar 15, 2019

Need we be consistent with this behavior?

Yes; we allocate resources in allocate action so PodFitsResource is not necessary; but initContainer is still necessary :)

Addressed. PTAL.

Another question: is there any reason to use float64 instead of int64 to record pod resource?

We used to use CPU instead of MillCPU, so float64 is there.

Get it. Thanks.

@@ -141,9 +141,10 @@ func (alloc *allocateAction) Execute(ssn *framework.Session) {
}
}
selectedNodes := util.SelectBestNode(nodeScores)
req := api.GetPodResourceRequest(task.Pod)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task.Resreq already includes initContainer, why do we need to re-calculate it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task.Resreq is calculated by GetPodResourceWithoutInitContainers, it does not contain initContainer. We only need consider initContainer when Allocate, do I understand it correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need Resreq in reclaim, preemption and backfill. And predicates&priorities will use Pods instead of task info :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm.... can we update task.Resreq directly, so we do not need to update different actions :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it at first time. However a lot of functions(e.g. jobinfo.AddTaskInfo, NodeInfo.AddTaskInfo) will use task.Resq that does not contain init container. Maybe we could add another variable ResqWithInitContainers in TaskInfo?

Copy link
Contributor

@k82cn k82cn Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, prefer to update related code to consider initContainer :)

hm.... maybe we need to distinguish them. In nodeInfo, it's not necessary to consider initContainer if it's in running state.

@hex108 hex108 force-pushed the init_container branch 2 times, most recently from ee19552 to 5bd2487 Compare March 15, 2019 08:44
// To be consistent with kubernetes default scheduler, ResreqWithInitContainers is only used for predicates
// of actions (e.g.allocate, backfill, preempt, reclaim), please use Resreq for other cases.
Resreq *Resource
ResreqWithInitContainers *Resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about InitResreq? The Resreq is the resource that used when task running; and the InitResreq is the resource that used to launch a task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it is shorter :) Addressed.

@k82cn
Copy link
Contributor

k82cn commented Mar 15, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 15, 2019
Priority: 1,
Pod: pod,
Resreq: req,
InitResreq: initResreq,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to update Clone() :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for it, forget to run test. Updated.

@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 15, 2019
@hex108
Copy link
Contributor Author

hex108 commented Mar 15, 2019

/retest

@hex108
Copy link
Contributor Author

hex108 commented Mar 15, 2019

Test errors are because namespace test is not deleted.

@k82cn
Copy link
Contributor

k82cn commented Mar 16, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 16, 2019
@k8s-ci-robot k8s-ci-robot merged commit 5132fca into kubernetes-retired:master Mar 16, 2019
@hex108 hex108 deleted the init_container branch March 17, 2019 07:27
k8s-ci-robot added a commit that referenced this pull request Mar 29, 2019
…#642-#638-#645-#647-#651-#652-#655-#658-#649-#660-#666-#671-#673-upstream-release-0.4

Automated cherry pick of #643: Return err in Allocate if any error occurs #642: Add event when task is scheduled #638: Take init containers into account when getting pod resource #645: Order task by CreationTimestamp first, then by UID #647: In allocate, skip adding Job if its queue is not found #651: Return err in functions of session.go if any error occurs #652: Change run option SchedulePeriod's type to make it clear #655: Do graceful eviction using default policy #658: Address helm install error in tutorial.md #649: Preempt lowest priority task first #660: Fix sub exception in reclaim and preempt #666: Fix wrong caculation for deserved in proportion plugin #671: Change base image to alphine to reduce image size #673: Do not create PodGroup and Job for task whose scheduler is
kevin-wangzefeng pushed a commit to kevin-wangzefeng/scheduler that referenced this pull request Jun 28, 2019
Take init containers into account when getting pod resource request
kevin-wangzefeng pushed a commit to kevin-wangzefeng/scheduler that referenced this pull request Jun 28, 2019
Take init containers into account when getting pod resource request
kevin-wangzefeng pushed a commit to kevin-wangzefeng/scheduler that referenced this pull request Jun 28, 2019
Take init containers into account when getting pod resource request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants