mirror of https://github.com/k3s-io/k3s
Don't handle graceful deletion of mirror pods in status manager
parent
810544633e
commit
f1535a0d4c
|
@ -370,7 +370,10 @@ func (m *manager) syncPod(uid types.UID, status versionedPodStatus) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
glog.V(3).Infof("Status for pod %q updated successfully: %+v", format.Pod(pod), status)
|
glog.V(3).Infof("Status for pod %q updated successfully: %+v", format.Pod(pod), status)
|
||||||
m.apiStatusVersions[pod.UID] = status.version
|
m.apiStatusVersions[pod.UID] = status.version
|
||||||
|
if kubepod.IsMirrorPod(pod) {
|
||||||
|
// We don't handle graceful deletion of mirror pods.
|
||||||
|
return
|
||||||
|
}
|
||||||
if pod.DeletionTimestamp == nil {
|
if pod.DeletionTimestamp == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,14 +84,14 @@ func getRandomPodStatus() api.PodStatus {
|
||||||
func verifyActions(t *testing.T, kubeClient client.Interface, expectedActions []testclient.Action) {
|
func verifyActions(t *testing.T, kubeClient client.Interface, expectedActions []testclient.Action) {
|
||||||
actions := kubeClient.(*testclient.Fake).Actions()
|
actions := kubeClient.(*testclient.Fake).Actions()
|
||||||
if len(actions) != len(expectedActions) {
|
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
|
return
|
||||||
}
|
}
|
||||||
for i := 0; i < len(actions); i++ {
|
for i := 0; i < len(actions); i++ {
|
||||||
e := expectedActions[i]
|
e := expectedActions[i]
|
||||||
a := actions[i]
|
a := actions[i]
|
||||||
if !a.Matches(e.GetVerb(), e.GetResource()) || a.GetSubresource() != e.GetSubresource() {
|
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
|
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"}},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue