Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device manager to scan resources.Requests #57278

Merged
merged 1 commit into from
Dec 18, 2017

Conversation

vikaschoudhary16
Copy link
Contributor

What this PR does / why we need it:
This PR makes device manager to scan resources.Requests from the container spec. Currently
it scans resources.Limits. For extended resources, it is not mandatory for resources.Limits to be present in the container spec and if Limits are present, validation logic ensures that Limits will always be equal to Requests.

Fixes #57276

Special notes for your reviewer:

Release note:

None

/sig node

/cc @ConnorDoyle @vishh @jiayingz @RenaudWasTaken @tengqm @resouer @mindprince

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. labels Dec 16, 2017
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 16, 2017
@k8s-ci-robot
Copy link
Contributor

@vikaschoudhary16: GitHub didn't allow me to request PR reviews from the following users: tengqm, RenaudWasTaken.

Note that only kubernetes members can review this PR, and authors cannot review their own PRs.

In response to this:

What this PR does / why we need it:
This PR makes device manager to scan resources.Requests from the container spec. Currently
it scans resources.Limits. For extended resources, it is not mandatory for resources.Limits to be present in the container spec and if Limits are present, validation logic ensures that Limits will always be equal to Requests.

Fixes #57276

Special notes for your reviewer:

Release note:

None

/sig node

/cc @ConnorDoyle @vishh @jiayingz @RenaudWasTaken @tengqm @resouer @mindprince

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@RenaudWasTaken
Copy link
Contributor

RenaudWasTaken commented Dec 16, 2017

@vikaschoudhary16 the issue @ConnorDoyle opened was about the fact that we don't scan Requests but we still have to scan Limits too :)

@ConnorDoyle
Copy link
Contributor

ConnorDoyle commented Dec 16, 2017

@RenaudWasTaken regarding

we still have to scan Limits

Per the docs, requests default to limits if those are explicitly defined. For example, the scheduler only inspects requests but it is able to properly place pods that only specify limit.

So, it appears that requests are guaranteed to be a subset of limits. You can verify the behavior like this:

$ kubectl create -f - <<POD
apiVersion: v1
kind: Pod
metadata:
  name: er-test
spec:
  containers:
  - image: busybox
    name: er-test
    resources:
      requests:
        cpu: 50m
      limits:
        cpu: 100m
        example.com/foo: 1
POD

Then fetch the same pod resource from the API server with kubectl:

$ kubectl get pod er-test -o json | jq ".spec.containers[0].resources"
{
  "limits": {
    "cpu": "100m",
    "example.com/foo": "1"
  },
  "requests": {
    "cpu": "50m",
    "example.com/foo": "1"
  }
}

In summary, I think it is safe to only inspect requests here and ignore limits. We will see any ER limit reflected in requests, and we are further guaranteed that ER limit is either undefined or equal to request.

@ConnorDoyle
Copy link
Contributor

Thanks for posting a PR for this so quickly!

@@ -550,7 +550,7 @@ func (m *ManagerImpl) allocateContainerResources(pod *v1.Pod, container *v1.Cont
podUID := string(pod.UID)
contName := container.Name
allocatedDevicesUpdated := false
for k, v := range container.Resources.Limits {
for k, v := range container.Resources.Requests {
Copy link
Contributor

Choose a reason for hiding this comment

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

@vikaschoudhary16 it's might not be obvious why we can safely ignore Limits. Could we add a comment near here explaining the rationale?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!

@RenaudWasTaken
Copy link
Contributor

@ConnorDoyle agreed but isn't the behavior undefined if someone sets requests and limits ? Should this error out ?

@ConnorDoyle
Copy link
Contributor

You can set both request and limit for extended resources, but they fail validation if they are not equal.

@ConnorDoyle
Copy link
Contributor

/assign

@ConnorDoyle
Copy link
Contributor

/approve
Will add LGTM after the requested comments have been added.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 17, 2017
@vikaschoudhary16
Copy link
Contributor Author

@ConnorDoyle Done. PTAL!

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 17, 2017
@@ -550,7 +550,10 @@ func (m *ManagerImpl) allocateContainerResources(pod *v1.Pod, container *v1.Cont
podUID := string(pod.UID)
contName := container.Name
allocatedDevicesUpdated := false
for k, v := range container.Resources.Limits {
// NOTE: Skipping the Resources.Lists is safe here because:
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Lists/Limits

for k, v := range container.Resources.Limits {
// NOTE: Skipping the Resources.Lists is safe here because:
// 1. If container Spec mentions Limits only, implicitly Requests, equal to Limits, get added to Spec.
// 2. If container Spec mentions Limits, which are greater than or less than Requests, will fail at validation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I can't recall we have validation to verify 2) , limits can be greater than requests by design in scheduler ... or I misunderstood the comment here?

Copy link
Contributor

@resouer resouer left a comment

Choose a reason for hiding this comment

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

I can confirm using requests here is safe and reasonable from scheduling aspect, so code lgtm, but comments may need update.

@@ -550,7 +550,10 @@ func (m *ManagerImpl) allocateContainerResources(pod *v1.Pod, container *v1.Cont
podUID := string(pod.UID)
contName := container.Name
allocatedDevicesUpdated := false
for k, v := range container.Resources.Limits {
// NOTE: Skipping the Resources.Lists is safe here because:
// 1. If container Spec mentions Limits only, implicitly Requests, equal to Limits, get added to Spec.
Copy link
Contributor

@resouer resouer Dec 18, 2017

Choose a reason for hiding this comment

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

The commas around equal to Limits confused me a little bit.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2017
@ConnorDoyle
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 18, 2017
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ConnorDoyle, vikaschoudhary16

Associated issue: #57276

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 0a55f41 into kubernetes:master Dec 18, 2017
@jiayingz
Copy link
Contributor

@vikaschoudhary16 we may consider to cherry-pick this PR to 1.9.1.

for k, v := range container.Resources.Limits {
// NOTE: Skipping the Resources.Limits is safe here because:
// 1. If container Spec mentions Limits only, implicitly Requests, equal to Limits, will get added to the Spec.
// 2. If container Spec mentions Limits, which are greater than or less than Requests, will fail at validation.
Copy link
Contributor

Choose a reason for hiding this comment

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

What if limits are not set? I think this change should validate if requests==limits prior to using requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vishh if requests != limits for ERs, it will fail here on validation step:
https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/validation/validation.go#L4380
And if limits are not set, then it should not be a problem because now with this change, requests are being scanned.

Or i missed your question?

Copy link
Contributor

@resouer resouer Dec 19, 2017

Choose a reason for hiding this comment

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

@vishh Yeah, I raised the same question before, while found that it is actually ensured by validation indeed.

That's why I suggested to update this comment to make it more clear. 😆

@vishh
Copy link
Contributor

vishh commented Dec 18, 2017

I'd appreciate if API behavioral changes are soaked for a bit before being merged.

@ConnorDoyle
Copy link
Contributor

This will be reverted, per discussion here: #57170 (comment)

vikaschoudhary16 added a commit to vikaschoudhary16/kubernetes that referenced this pull request Dec 22, 2017
k8s-github-robot pushed a commit that referenced this pull request Dec 25, 2017
Automatic merge from submit-queue (batch tested with PRs 57591, 57369). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Revert back #57278

**What this PR does / why we need it**:
This PR reverts back to behavior of scanning Limits.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Related #
#57276
#57170
**Special notes for your reviewer**:

**Release note**:

```release-note
None
```
/sig node

/cc @vishh @ConnorDoyle @jiayingz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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 "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants