mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #96781 from fighterhit/fix-kukelet-device-plugin-bug
Fix: kubelet return error when device plugin sets PreStartRequired true while creating pods with 0 resource
This commit is contained in:
commit
06a7e2bacf
@ -940,9 +940,9 @@ func (m *ManagerImpl) GetDeviceRunContainerOptions(pod *v1.Pod, container *v1.Co
|
|||||||
podUID := string(pod.UID)
|
podUID := string(pod.UID)
|
||||||
contName := container.Name
|
contName := container.Name
|
||||||
needsReAllocate := false
|
needsReAllocate := false
|
||||||
for k := range container.Resources.Limits {
|
for k, v := range container.Resources.Limits {
|
||||||
resource := string(k)
|
resource := string(k)
|
||||||
if !m.isDevicePluginResource(resource) {
|
if !m.isDevicePluginResource(resource) || v.Value() == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := m.callPreStartContainerIfNeeded(podUID, contName, resource)
|
err := m.callPreStartContainerIfNeeded(podUID, contName, resource)
|
||||||
|
@ -976,6 +976,21 @@ func TestDevicePreStartContainer(t *testing.T) {
|
|||||||
as.Equal(len(runContainerOpts.Devices), len(expectedResp.Devices))
|
as.Equal(len(runContainerOpts.Devices), len(expectedResp.Devices))
|
||||||
as.Equal(len(runContainerOpts.Mounts), len(expectedResp.Mounts))
|
as.Equal(len(runContainerOpts.Mounts), len(expectedResp.Mounts))
|
||||||
as.Equal(len(runContainerOpts.Envs), len(expectedResp.Envs))
|
as.Equal(len(runContainerOpts.Envs), len(expectedResp.Envs))
|
||||||
|
|
||||||
|
pod2 := makePod(v1.ResourceList{
|
||||||
|
v1.ResourceName(res1.resourceName): *resource.NewQuantity(int64(0), resource.DecimalSI)})
|
||||||
|
activePods = append(activePods, pod2)
|
||||||
|
podsStub.updateActivePods(activePods)
|
||||||
|
err = testManager.Allocate(pod2, &pod2.Spec.Containers[0])
|
||||||
|
as.Nil(err)
|
||||||
|
_, err = testManager.GetDeviceRunContainerOptions(pod2, &pod2.Spec.Containers[0])
|
||||||
|
as.Nil(err)
|
||||||
|
select {
|
||||||
|
case <-time.After(time.Millisecond):
|
||||||
|
t.Log("When pod resourceQuantity is 0, PreStartContainer RPC stub will be skipped")
|
||||||
|
case <-ch:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResetExtendedResource(t *testing.T) {
|
func TestResetExtendedResource(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user