Fix PodScheduled bug for static pod.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2018-03-21 23:33:44 +00:00
parent 092f1d52a7
commit 19a1bd8b99
3 changed files with 85 additions and 25 deletions

View File

@@ -798,6 +798,67 @@ func TestDoNotDeleteMirrorPods(t *testing.T) {
verifyActions(t, m, []core.Action{getAction(), updateAction()})
}
func TestUpdateLastTransitionTime(t *testing.T) {
old := metav1.Now()
for desc, test := range map[string]struct {
condition *v1.PodCondition
oldCondition *v1.PodCondition
expectUpdate bool
}{
"should do nothing if no corresponding condition": {
expectUpdate: false,
},
"should update last transition time if no old condition": {
condition: &v1.PodCondition{
Type: "test-type",
Status: v1.ConditionTrue,
},
oldCondition: nil,
expectUpdate: true,
},
"should update last transition time if condition is changed": {
condition: &v1.PodCondition{
Type: "test-type",
Status: v1.ConditionTrue,
},
oldCondition: &v1.PodCondition{
Type: "test-type",
Status: v1.ConditionFalse,
LastTransitionTime: old,
},
expectUpdate: true,
},
"should keep last transition time if condition is not changed": {
condition: &v1.PodCondition{
Type: "test-type",
Status: v1.ConditionFalse,
},
oldCondition: &v1.PodCondition{
Type: "test-type",
Status: v1.ConditionFalse,
LastTransitionTime: old,
},
expectUpdate: false,
},
} {
t.Logf("TestCase %q", desc)
status := &v1.PodStatus{}
oldStatus := &v1.PodStatus{}
if test.condition != nil {
status.Conditions = []v1.PodCondition{*test.condition}
}
if test.oldCondition != nil {
oldStatus.Conditions = []v1.PodCondition{*test.oldCondition}
}
updateLastTransitionTime(status, oldStatus, "test-type")
if test.expectUpdate {
assert.True(t, status.Conditions[0].LastTransitionTime.After(old.Time))
} else if test.condition != nil {
assert.Equal(t, old, status.Conditions[0].LastTransitionTime)
}
}
}
func getAction() core.GetAction {
return core.GetActionImpl{ActionImpl: core.ActionImpl{Verb: "get", Resource: schema.GroupVersionResource{Resource: "pods"}}}
}