kubelet_test: Fix TestHandlePodCleanups

This commit is contained in:
Geonju Kim 2021-02-11 17:20:48 +09:00
parent fc4a29da2c
commit 256447a349

View File

@ -409,7 +409,7 @@ func TestSyncPodsStartPod(t *testing.T) {
fakeRuntime.AssertStartedPods([]string{string(pods[0].UID)}) fakeRuntime.AssertStartedPods([]string{string(pods[0].UID)})
} }
func TestSyncPodsDeletesWhenSourcesAreReadyPerQOS(t *testing.T) { func TestHandlePodCleanupsPerQOS(t *testing.T) {
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */) testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
go testKubelet.kubelet.podKiller.PerformPodKillingWork() go testKubelet.kubelet.podKiller.PerformPodKillingWork()
defer testKubelet.Cleanup() defer testKubelet.Cleanup()
@ -432,7 +432,6 @@ func TestSyncPodsDeletesWhenSourcesAreReadyPerQOS(t *testing.T) {
} }
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
kubelet.cgroupsPerQOS = true // enable cgroupsPerQOS to turn on the cgroups cleanup kubelet.cgroupsPerQOS = true // enable cgroupsPerQOS to turn on the cgroups cleanup
kubelet.sourcesReady = config.NewSourcesReady(func(_ sets.String) bool { return true })
// HandlePodCleanups gets called every 2 seconds within the Kubelet's // HandlePodCleanups gets called every 2 seconds within the Kubelet's
// housekeeping routine. This test registers the pod, removes the unwanted pod, then calls into // housekeeping routine. This test registers the pod, removes the unwanted pod, then calls into
@ -602,33 +601,31 @@ func TestDispatchWorkOfActivePod(t *testing.T) {
} }
} }
func TestSyncPodsDeletesWhenSourcesAreReady(t *testing.T) { func TestHandlePodCleanups(t *testing.T) {
ready := false
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */) testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
defer testKubelet.Cleanup() defer testKubelet.Cleanup()
fakeRuntime := testKubelet.fakeRuntime defer testKubelet.kubelet.podKiller.Close()
kubelet := testKubelet.kubelet
kubelet.sourcesReady = config.NewSourcesReady(func(_ sets.String) bool { return ready })
fakeRuntime.PodList = []*containertest.FakePod{ pod := &kubecontainer.Pod{
{Pod: &kubecontainer.Pod{
ID: "12345678", ID: "12345678",
Name: "foo", Name: "foo",
Namespace: "new", Namespace: "new",
Containers: []*kubecontainer.Container{ Containers: []*kubecontainer.Container{
{Name: "bar"}, {Name: "bar"},
}, },
}},
} }
kubelet.HandlePodCleanups()
// Sources are not ready yet. Don't remove any pods.
fakeRuntime.AssertKilledPods([]string{})
ready = true fakeRuntime := testKubelet.fakeRuntime
kubelet.HandlePodCleanups() fakeRuntime.PodList = []*containertest.FakePod{
{Pod: pod},
}
kubelet := testKubelet.kubelet
// Sources are ready. Remove unwanted pods. kubelet.HandlePodCleanups()
time.Sleep(2 * time.Second)
// assert that unwanted pods were killed
fakeRuntime.AssertKilledPods([]string{"12345678"}) fakeRuntime.AssertKilledPods([]string{"12345678"})
} }