mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Merge pull request #18240 from timstclair/readiness
Update PodReady condition when updating container readiness
This commit is contained in:
@@ -1909,119 +1909,6 @@ func TestPodPhaseWithRestartOnFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func getReadyStatus(cName string) api.ContainerStatus {
|
||||
return api.ContainerStatus{
|
||||
Name: cName,
|
||||
Ready: true,
|
||||
}
|
||||
}
|
||||
func getNotReadyStatus(cName string) api.ContainerStatus {
|
||||
return api.ContainerStatus{
|
||||
Name: cName,
|
||||
Ready: false,
|
||||
}
|
||||
}
|
||||
func getReadyCondition(status api.ConditionStatus, reason, message string) []api.PodCondition {
|
||||
return []api.PodCondition{{
|
||||
Type: api.PodReady,
|
||||
Status: status,
|
||||
Reason: reason,
|
||||
Message: message,
|
||||
}}
|
||||
}
|
||||
|
||||
func TestGetPodReadyCondition(t *testing.T) {
|
||||
tests := []struct {
|
||||
spec *api.PodSpec
|
||||
containerStatuses []api.ContainerStatus
|
||||
podPhase api.PodPhase
|
||||
expected []api.PodCondition
|
||||
}{
|
||||
{
|
||||
spec: nil,
|
||||
containerStatuses: nil,
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "UnknownContainerStatuses", ""),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{},
|
||||
containerStatuses: []api.ContainerStatus{},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionTrue, "", ""),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "1234"},
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "ContainersNotReady", "containers with unknown status: [1234]"),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "1234"},
|
||||
{Name: "5678"},
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{
|
||||
getReadyStatus("1234"),
|
||||
getReadyStatus("5678"),
|
||||
},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionTrue, "", ""),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "1234"},
|
||||
{Name: "5678"},
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{
|
||||
getReadyStatus("1234"),
|
||||
},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "ContainersNotReady", "containers with unknown status: [5678]"),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "1234"},
|
||||
{Name: "5678"},
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{
|
||||
getReadyStatus("1234"),
|
||||
getNotReadyStatus("5678"),
|
||||
},
|
||||
podPhase: api.PodRunning,
|
||||
expected: getReadyCondition(api.ConditionFalse, "ContainersNotReady", "containers with unready status: [5678]"),
|
||||
},
|
||||
{
|
||||
spec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "1234"},
|
||||
},
|
||||
},
|
||||
containerStatuses: []api.ContainerStatus{
|
||||
getNotReadyStatus("1234"),
|
||||
},
|
||||
podPhase: api.PodSucceeded,
|
||||
expected: getReadyCondition(api.ConditionFalse, "PodCompleted", ""),
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
condition := getPodReadyCondition(test.spec, test.containerStatuses, test.podPhase)
|
||||
if !reflect.DeepEqual(condition, test.expected) {
|
||||
t.Errorf("On test case %v, expected:\n%+v\ngot\n%+v\n", i, test.expected, condition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecInContainerNoSuchPod(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t)
|
||||
kubelet := testKubelet.kubelet
|
||||
|
||||
Reference in New Issue
Block a user