diff --git a/pkg/kubelet/status/manager.go b/pkg/kubelet/status/manager.go index 662e111d55e..3cb3084ea6a 100644 --- a/pkg/kubelet/status/manager.go +++ b/pkg/kubelet/status/manager.go @@ -370,7 +370,10 @@ func (m *manager) syncPod(uid types.UID, status versionedPodStatus) { if err == nil { glog.V(3).Infof("Status for pod %q updated successfully: %+v", format.Pod(pod), status) m.apiStatusVersions[pod.UID] = status.version - + if kubepod.IsMirrorPod(pod) { + // We don't handle graceful deletion of mirror pods. + return + } if pod.DeletionTimestamp == nil { return } diff --git a/pkg/kubelet/status/manager_test.go b/pkg/kubelet/status/manager_test.go index 1b7e11f6e38..73fb5d43d83 100644 --- a/pkg/kubelet/status/manager_test.go +++ b/pkg/kubelet/status/manager_test.go @@ -84,14 +84,14 @@ func getRandomPodStatus() api.PodStatus { func verifyActions(t *testing.T, kubeClient client.Interface, expectedActions []testclient.Action) { actions := kubeClient.(*testclient.Fake).Actions() if len(actions) != len(expectedActions) { - t.Fatalf("unexpected actions, got: %s expected: %s", actions, expectedActions) + t.Fatalf("unexpected actions, got: %+v expected: %+v", actions, expectedActions) return } for i := 0; i < len(actions); i++ { e := expectedActions[i] a := actions[i] if !a.Matches(e.GetVerb(), e.GetResource()) || a.GetSubresource() != e.GetSubresource() { - t.Errorf("unexpected actions, got: %s expected: %s", actions, expectedActions) + t.Errorf("unexpected actions, got: %+v expected: %+v", actions, expectedActions) } } } @@ -714,3 +714,58 @@ func expectPodStatus(t *testing.T, m *manager, pod *api.Pod) api.PodStatus { } return status } + +func TestDeletePods(t *testing.T) { + pod := getTestPod() + // Set the deletion timestamp. + pod.DeletionTimestamp = new(unversioned.Time) + client := testclient.NewSimpleFake(pod) + m := newTestManager(client) + m.podManager.AddPod(pod) + + status := getRandomPodStatus() + now := unversioned.Now() + status.StartTime = &now + m.SetPodStatus(pod, status) + + m.testSyncBatch() + // Expect to see an delete action. + verifyActions(t, m.kubeClient, []testclient.Action{ + testclient.GetActionImpl{ActionImpl: testclient.ActionImpl{Verb: "get", Resource: "pods"}}, + testclient.UpdateActionImpl{ActionImpl: testclient.ActionImpl{Verb: "update", Resource: "pods", Subresource: "status"}}, + testclient.DeleteActionImpl{ActionImpl: testclient.ActionImpl{Verb: "delete", Resource: "pods"}}, + }) +} + +func TestDoNotDeleteMirrorPods(t *testing.T) { + staticPod := getTestPod() + staticPod.Annotations = map[string]string{kubetypes.ConfigSourceAnnotationKey: "file"} + mirrorPod := getTestPod() + mirrorPod.UID = "mirror-12345678" + mirrorPod.Annotations = map[string]string{ + kubetypes.ConfigSourceAnnotationKey: "api", + kubetypes.ConfigMirrorAnnotationKey: "mirror", + } + // Set the deletion timestamp. + mirrorPod.DeletionTimestamp = new(unversioned.Time) + client := testclient.NewSimpleFake(mirrorPod) + m := newTestManager(client) + m.podManager.AddPod(staticPod) + m.podManager.AddPod(mirrorPod) + // Verify setup. + assert.True(t, kubepod.IsStaticPod(staticPod), "SetUp error: staticPod") + assert.True(t, kubepod.IsMirrorPod(mirrorPod), "SetUp error: mirrorPod") + assert.Equal(t, m.podManager.TranslatePodUID(mirrorPod.UID), staticPod.UID) + + status := getRandomPodStatus() + now := unversioned.Now() + status.StartTime = &now + m.SetPodStatus(staticPod, status) + + m.testSyncBatch() + // Expect not to see an delete action. + verifyActions(t, m.kubeClient, []testclient.Action{ + testclient.GetActionImpl{ActionImpl: testclient.ActionImpl{Verb: "get", Resource: "pods"}}, + testclient.UpdateActionImpl{ActionImpl: testclient.ActionImpl{Verb: "update", Resource: "pods", Subresource: "status"}}, + }) +}