From 8749c5c989080acd3da8b04c93171b2dd19ada93 Mon Sep 17 00:00:00 2001 From: vikaschoudhary16 Date: Mon, 18 Dec 2017 23:31:07 -0500 Subject: [PATCH] Revert back #57278 --- pkg/kubelet/cm/deviceplugin/manager.go | 9 +++++---- pkg/kubelet/cm/deviceplugin/manager_test.go | 16 ++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/kubelet/cm/deviceplugin/manager.go b/pkg/kubelet/cm/deviceplugin/manager.go index 5e1137c114..df5e36e218 100644 --- a/pkg/kubelet/cm/deviceplugin/manager.go +++ b/pkg/kubelet/cm/deviceplugin/manager.go @@ -550,10 +550,11 @@ func (m *ManagerImpl) allocateContainerResources(pod *v1.Pod, container *v1.Cont podUID := string(pod.UID) contName := container.Name allocatedDevicesUpdated := false - // 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 { + // Extended resources are not allowed to be overcommitted. + // Since device plugin advertises extended resources, + // therefore Requests must be equal to Limits and iterating + // over the Limits should be sufficient. + for k, v := range container.Resources.Limits { resource := string(k) needed := int(v.Value()) glog.V(3).Infof("needs %d %s", needed, resource) diff --git a/pkg/kubelet/cm/deviceplugin/manager_test.go b/pkg/kubelet/cm/deviceplugin/manager_test.go index d7a032694c..de4c0264a0 100644 --- a/pkg/kubelet/cm/deviceplugin/manager_test.go +++ b/pkg/kubelet/cm/deviceplugin/manager_test.go @@ -366,7 +366,7 @@ func (m *MockEndpoint) allocate(devs []string) (*pluginapi.AllocateResponse, err return nil, nil } -func makePod(requests v1.ResourceList) *v1.Pod { +func makePod(limits v1.ResourceList) *v1.Pod { return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ UID: uuid.NewUUID(), @@ -375,7 +375,7 @@ func makePod(requests v1.ResourceList) *v1.Pod { Containers: []v1.Container{ { Resources: v1.ResourceRequirements{ - Requests: requests, + Limits: limits, }, }, }, @@ -616,7 +616,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) { { Name: string(uuid.NewUUID()), Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ + Limits: v1.ResourceList{ v1.ResourceName(res1.resourceName): res2.resourceQuantity, }, }, @@ -624,7 +624,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) { { Name: string(uuid.NewUUID()), Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ + Limits: v1.ResourceList{ v1.ResourceName(res1.resourceName): res1.resourceQuantity, }, }, @@ -634,7 +634,7 @@ func TestInitContainerDeviceAllocation(t *testing.T) { { Name: string(uuid.NewUUID()), Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ + Limits: 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{ - Requests: v1.ResourceList{ + Limits: v1.ResourceList{ v1.ResourceName(res1.resourceName): res2.resourceQuantity, v1.ResourceName(res2.resourceName): res2.resourceQuantity, }, @@ -664,6 +664,10 @@ func TestInitContainerDeviceAllocation(t *testing.T) { initCont2Devices := testManager.podDevices.containerDevices(podUID, initCont2, res1.resourceName) normalCont1Devices := testManager.podDevices.containerDevices(podUID, normalCont1, res1.resourceName) normalCont2Devices := testManager.podDevices.containerDevices(podUID, normalCont2, res1.resourceName) + as.Equal(1, initCont1Devices.Len()) + as.Equal(2, initCont2Devices.Len()) + as.Equal(1, normalCont1Devices.Len()) + as.Equal(1, normalCont2Devices.Len()) as.True(initCont2Devices.IsSuperset(initCont1Devices)) as.True(initCont2Devices.IsSuperset(normalCont1Devices)) as.True(initCont2Devices.IsSuperset(normalCont2Devices))