mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Add tests to reproduce the issue and verify the fix.
This commit is contained in:
parent
1b8f851979
commit
6f46780cbf
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user