Skip to content

Commit

Permalink
Add tests covering startup probe without readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyx committed Jun 18, 2020
1 parent aa348b1 commit 681202a
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions pkg/kubelet/prober/prober_manager_test.go
Expand Up @@ -256,6 +256,20 @@ func TestUpdatePodStatus(t *testing.T) {
Running: &v1.ContainerStateRunning{},
},
}
notStartedNoReadiness := v1.ContainerStatus{
Name: "not_started_container_no_readiness",
ContainerID: "test://not_started_container_no_readiness_id",
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
}
startedNoReadiness := v1.ContainerStatus{
Name: "started_container_no_readiness",
ContainerID: "test://started_container_no_readiness_id",
State: v1.ContainerState{
Running: &v1.ContainerStateRunning{},
},
}
terminated := v1.ContainerStatus{
Name: "terminated_container",
ContainerID: "test://terminated_container_id",
Expand All @@ -266,7 +280,7 @@ func TestUpdatePodStatus(t *testing.T) {
podStatus := v1.PodStatus{
Phase: v1.PodRunning,
ContainerStatuses: []v1.ContainerStatus{
unprobed, probedReady, probedPending, probedUnready, terminated,
unprobed, probedReady, probedPending, probedUnready, notStartedNoReadiness, startedNoReadiness, terminated,
},
}

Expand All @@ -275,24 +289,29 @@ func TestUpdatePodStatus(t *testing.T) {

// Setup probe "workers" and cached results.
m.workers = map[probeKey]*worker{
{testPodUID, unprobed.Name, liveness}: {},
{testPodUID, probedReady.Name, readiness}: {},
{testPodUID, probedPending.Name, readiness}: {},
{testPodUID, probedUnready.Name, readiness}: {},
{testPodUID, terminated.Name, readiness}: {},
{testPodUID, unprobed.Name, liveness}: {},
{testPodUID, probedReady.Name, readiness}: {},
{testPodUID, probedPending.Name, readiness}: {},
{testPodUID, probedUnready.Name, readiness}: {},
{testPodUID, notStartedNoReadiness.Name, startup}: {},
{testPodUID, startedNoReadiness.Name, startup}: {},
{testPodUID, terminated.Name, readiness}: {},
}
m.readinessManager.Set(kubecontainer.ParseContainerID(probedReady.ContainerID), results.Success, &v1.Pod{})
m.readinessManager.Set(kubecontainer.ParseContainerID(probedUnready.ContainerID), results.Failure, &v1.Pod{})
m.startupManager.Set(kubecontainer.ParseContainerID(startedNoReadiness.ContainerID), results.Success, &v1.Pod{})
m.readinessManager.Set(kubecontainer.ParseContainerID(terminated.ContainerID), results.Success, &v1.Pod{})

m.UpdatePodStatus(testPodUID, &podStatus)

expectedReadiness := map[probeKey]bool{
{testPodUID, unprobed.Name, readiness}: true,
{testPodUID, probedReady.Name, readiness}: true,
{testPodUID, probedPending.Name, readiness}: false,
{testPodUID, probedUnready.Name, readiness}: false,
{testPodUID, terminated.Name, readiness}: false,
{testPodUID, unprobed.Name, readiness}: true,
{testPodUID, probedReady.Name, readiness}: true,
{testPodUID, probedPending.Name, readiness}: false,
{testPodUID, probedUnready.Name, readiness}: false,
{testPodUID, notStartedNoReadiness.Name, readiness}: false,
{testPodUID, startedNoReadiness.Name, readiness}: true,
{testPodUID, terminated.Name, readiness}: false,
}
for _, c := range podStatus.ContainerStatuses {
expected, ok := expectedReadiness[probeKey{testPodUID, c.Name, readiness}]
Expand Down

0 comments on commit 681202a

Please sign in to comment.