mirror of https://github.com/k3s-io/k3s
Revert back #57278
parent
cdbfff0773
commit
8749c5c989
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue