Look for requested resources in the Requests

pull/6/head
vikaschoudhary16 2017-12-16 15:13:34 -05:00
parent 6b03a43b76
commit bf1fb46347
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,
},