mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 03:08:15 +00:00
kubelet: Fix race when KillPod followed by IsPodPendingTermination
Ensures the pod to be pending termination or be killed, after (*podKillerWithChannel).KillPod has been returned, by limiting one request per pod in (*podKillerWithChannel).KillPod.
This commit is contained in:
@@ -500,6 +500,39 @@ func TestSyncPodsDeletesWhenSourcesAreReady(t *testing.T) {
|
||||
fakeRuntime.AssertKilledPods([]string{"12345678"})
|
||||
}
|
||||
|
||||
func TestKillPodFollwedByIsPodPendingTermination(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||
defer testKubelet.Cleanup()
|
||||
defer testKubelet.kubelet.podKiller.Close()
|
||||
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
|
||||
|
||||
pod := &kubecontainer.Pod{
|
||||
ID: "12345678",
|
||||
Name: "foo",
|
||||
Namespace: "new",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{Name: "bar"},
|
||||
},
|
||||
}
|
||||
|
||||
fakeRuntime := testKubelet.fakeRuntime
|
||||
fakeContainerManager := testKubelet.fakeContainerManager
|
||||
fakeContainerManager.PodContainerManager.AddPodFromCgroups(pod) // add pod to mock cgroup
|
||||
fakeRuntime.PodList = []*containertest.FakePod{
|
||||
{Pod: pod},
|
||||
}
|
||||
|
||||
kl := testKubelet.kubelet
|
||||
kl.podKiller.KillPod(&kubecontainer.PodPair{
|
||||
APIPod: nil,
|
||||
RunningPod: pod,
|
||||
})
|
||||
|
||||
if !(kl.podKiller.IsPodPendingTerminationByUID(pod.ID) || fakeRuntime.AssertKilledPods([]string{"12345678"}) == nil) {
|
||||
t.Fatal("Race condition: When KillPod is complete, the pod should be pending termination or be killed")
|
||||
}
|
||||
}
|
||||
|
||||
type testNodeLister struct {
|
||||
nodes []*v1.Node
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user