Merge pull request #57278 from vikaschoudhary16/limit

Automatic merge from submit-queue. 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>.

Fix device manager to scan resources.Requests

**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**:

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

/cc @ConnorDoyle @vishh @jiayingz @RenaudWasTaken @tengqm @resouer @mindprince
This commit is contained in:
Kubernetes Submit Queue 2017-12-17 23:43:59 -08:00 committed by GitHub
commit 0a55f4105c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -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.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.
for k, v := range container.Resources.Requests {
resource := string(k)
needed := int(v.Value())
glog.V(3).Infof("needs %d %s", needed, resource)

View File

@ -366,7 +366,7 @@ func (m *MockEndpoint) allocate(devs []string) (*pluginapi.AllocateResponse, err
return nil, nil
}
func makePod(limits v1.ResourceList) *v1.Pod {
func makePod(requests v1.ResourceList) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
UID: uuid.NewUUID(),
@ -375,7 +375,7 @@ func makePod(limits v1.ResourceList) *v1.Pod {
Containers: []v1.Container{
{
Resources: v1.ResourceRequirements{
Limits: limits,
Requests: requests,
},
},
},
@ -616,7 +616,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
{
Name: string(uuid.NewUUID()),
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
Requests: v1.ResourceList{
v1.ResourceName(res1.resourceName): res2.resourceQuantity,
},
},
@ -624,7 +624,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
{
Name: string(uuid.NewUUID()),
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
Requests: v1.ResourceList{
v1.ResourceName(res1.resourceName): res1.resourceQuantity,
},
},
@ -634,7 +634,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
{
Name: string(uuid.NewUUID()),
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
Requests: v1.ResourceList{
v1.ResourceName(res1.resourceName): res2.resourceQuantity,
v1.ResourceName(res2.resourceName): res2.resourceQuantity,
},
@ -643,7 +643,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
{
Name: string(uuid.NewUUID()),
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
Requests: v1.ResourceList{
v1.ResourceName(res1.resourceName): res2.resourceQuantity,
v1.ResourceName(res2.resourceName): res2.resourceQuantity,
},