mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-31 08:36:16 +00:00
Merge pull request #15799 from dchen1107/podstatus
Auto commit by PR queue bot
This commit is contained in:
@@ -2513,7 +2513,11 @@ func GetPhase(spec *api.PodSpec, info []api.ContainerStatus) api.PodPhase {
|
||||
failed++
|
||||
}
|
||||
} else if containerStatus.State.Waiting != nil {
|
||||
waiting++
|
||||
if containerStatus.LastTerminationState.Terminated != nil {
|
||||
stopped++
|
||||
} else {
|
||||
waiting++
|
||||
}
|
||||
} else {
|
||||
unknown++
|
||||
}
|
||||
|
@@ -1462,6 +1462,27 @@ func TestMakeEnvironmentVariables(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func waitingState(cName string) api.ContainerStatus {
|
||||
return api.ContainerStatus{
|
||||
Name: cName,
|
||||
State: api.ContainerState{
|
||||
Waiting: &api.ContainerStateWaiting{},
|
||||
},
|
||||
}
|
||||
}
|
||||
func waitingStateWithLastTermination(cName string) api.ContainerStatus {
|
||||
return api.ContainerStatus{
|
||||
Name: cName,
|
||||
State: api.ContainerState{
|
||||
Waiting: &api.ContainerStateWaiting{},
|
||||
},
|
||||
LastTerminationState: api.ContainerState{
|
||||
Terminated: &api.ContainerStateTerminated{
|
||||
ExitCode: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
func runningState(cName string) api.ContainerStatus {
|
||||
return api.ContainerStatus{
|
||||
Name: cName,
|
||||
@@ -1566,6 +1587,32 @@ func TestPodPhaseWithRestartAlways(t *testing.T) {
|
||||
api.PodPending,
|
||||
"mixed state #2 with restart always",
|
||||
},
|
||||
{
|
||||
&api.Pod{
|
||||
Spec: desiredState,
|
||||
Status: api.PodStatus{
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
runningState("containerA"),
|
||||
waitingState("containerB"),
|
||||
},
|
||||
},
|
||||
},
|
||||
api.PodPending,
|
||||
"mixed state #3 with restart always",
|
||||
},
|
||||
{
|
||||
&api.Pod{
|
||||
Spec: desiredState,
|
||||
Status: api.PodStatus{
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
runningState("containerA"),
|
||||
waitingStateWithLastTermination("containerB"),
|
||||
},
|
||||
},
|
||||
},
|
||||
api.PodRunning,
|
||||
"backoff crashloop container with restart always",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if status := GetPhase(&test.pod.Spec, test.pod.Status.ContainerStatuses); status != test.status {
|
||||
@@ -1654,6 +1701,19 @@ func TestPodPhaseWithRestartNever(t *testing.T) {
|
||||
api.PodPending,
|
||||
"mixed state #2 with restart never",
|
||||
},
|
||||
{
|
||||
&api.Pod{
|
||||
Spec: desiredState,
|
||||
Status: api.PodStatus{
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
runningState("containerA"),
|
||||
waitingState("containerB"),
|
||||
},
|
||||
},
|
||||
},
|
||||
api.PodPending,
|
||||
"mixed state #3 with restart never",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if status := GetPhase(&test.pod.Spec, test.pod.Status.ContainerStatuses); status != test.status {
|
||||
@@ -1742,6 +1802,32 @@ func TestPodPhaseWithRestartOnFailure(t *testing.T) {
|
||||
api.PodPending,
|
||||
"mixed state #2 with restart onfailure",
|
||||
},
|
||||
{
|
||||
&api.Pod{
|
||||
Spec: desiredState,
|
||||
Status: api.PodStatus{
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
runningState("containerA"),
|
||||
waitingState("containerB"),
|
||||
},
|
||||
},
|
||||
},
|
||||
api.PodPending,
|
||||
"mixed state #3 with restart onfailure",
|
||||
},
|
||||
{
|
||||
&api.Pod{
|
||||
Spec: desiredState,
|
||||
Status: api.PodStatus{
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
runningState("containerA"),
|
||||
waitingStateWithLastTermination("containerB"),
|
||||
},
|
||||
},
|
||||
},
|
||||
api.PodRunning,
|
||||
"backoff crashloop container with restart onfailure",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if status := GetPhase(&test.pod.Spec, test.pod.Status.ContainerStatuses); status != test.status {
|
||||
|
Reference in New Issue
Block a user