Code change:
Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, ID:    "1876", }, <ins> }, }, // maxContainerCount applies per container.. { containers: []docker.APIContainers{ </ins> { // pod infra container <del> Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, ID:    "2876", </del> <ins> Names: []string{"/k8s_POD_foo2.new.test_.beefbeef_40"}, ID:    "1706", </ins> }, { // pod infra container <del> Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, ID:    "3876", </del> <ins> Names: []string{"/k8s_POD_foo2.new.test_.beefbeef_40"}, ID:    "2706", </ins> }, { // pod infra container <del> Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, ID:    "4876", </del> <ins> Names: []string{"/k8s_POD_foo2.new.test_.beefbeef_40"}, ID:    "3706", </ins> }, { // pod infra container Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, <del> ID:    "5876", </del> <ins> ID:    "1876", </ins> }, { // pod infra container Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, <del> ID:    "6876", </del> <ins> ID:    "2876", </ins> }, { // pod infra container Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, <del> ID:    "7876", </del> <ins> ID:    "3876", </ins> }, }, containerDetails: map[string]*docker.Container{ <del> "1876": { </del> <ins> "1706": { </ins> State: docker.State{ <del> Running: true, </del> <ins> Running: false, </ins> }, <del> ID:      "1876", </del> <ins> ID:      "1706", </ins> Created: time.Now(), }, <del> "2876": { </del> <ins> "1876": { </ins> State: docker.State{ Running: false, }, <del> ID:      "2876", </del> <ins> ID:      "1876", </ins> Created: time.Now(), }, }, <del> expectedRemoved: []string{"2876"}, }, { containers: []docker.APIContainers{ { // pod infra container Names: []string{"/k8s_POD_foo.new.test_.deadbeef_42"}, ID:    "1876", }, }, </del> <ins> expectedRemoved: []string{"1706", "1876"}, </ins> }, } for _, test := range tests { kubelet, fakeDocker := newTestKubelet(t) <del> kubelet.maxContainerCount = 5 </del> <ins> kubelet.maxContainerCount = 2 </ins> fakeDocker.ContainerList = test.containers fakeDocker.ContainerMap = test.containerDetails fakeDocker.Container = &docker.Container{ID: "error", Created: time.Now()}

Related discussion:
text: Successfully ran containers with "onFailure" restartPolicy are restarting after purging oldest docker containers. Kubelet purges/removes oldest containers periodically from docker. After purging, we loose the exit code and history of previously ran containers and restart containers as if they were never run.
Thanks & I can help fix this. Let me know. Thanks
Thanks for reporting Just to make sure I understand the issue: You ran some containers with an "onFailure" restartPolicy. When the Kubelet purged old containers the container was restarted (unexpectedly).
Ah, after reading again I think the issue is that after the containers are purged, when the container exits successfully it get restarted although it shouldn't. Is that correct?
After reading through the code I found a bug in the implementation that is most likely causing this error. Should have a PR soon.
Yes. Correct. After initial container run, it should never be run again, since it already ran to completion. Will wait for your PR.
PR is out. This should fix the issue. Feel free to test if you can :)