Skip to content

Commit

Permalink
Fix TestTaskRunRetry for k8s 1.22.9 and later
Browse files Browse the repository at this point in the history
We just switched to k8s 1.22.9 on CI last night, and `TestTaskRunRetry` started failing. After a bunch of investigation, I determined this was due to kubernetes/kubernetes#108366, which went into k8s 1.22.9. This resulted in the `pod.Status.Phase` that `TestTaskRunRetry` expected to be updated instantly having a delay. I could have fixed this with a sleep, but decided verifying that each container in the pod had terminated with the expected exit code was cleaner.

Backported from b5ea3e9

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer authored and tekton-robot committed Jul 21, 2022
1 parent 0d8b26a commit 13f9c0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions test/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@ spec:
if _, found := podNames[p.Name]; !found {
t.Errorf("BUG: TaskRunStatus.RetriesStatus did not report pod name %q", p.Name)
}
if p.Status.Phase != corev1.PodFailed {
t.Errorf("BUG: Pod %q is not failed: %v", p.Name, p.Status.Phase)
// Check each container in the pod, rather than the phase, since the phase doesn't update to a terminal state instantly.
// See https://github.com/kubernetes/kubernetes/pull/108366
for _, c := range p.Status.ContainerStatuses {
if c.State.Terminated == nil {
t.Errorf("BUG: Container %s in pod %s is not terminated", c.Name, p.Name)
} else if c.State.Terminated.ExitCode != 1 {
t.Errorf("BUG: Container %s in pod %s has exit code %d, expected 1", c.Name, p.Name, c.State.Terminated.ExitCode)
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/v1alpha1/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,14 @@ spec:
if _, found := podNames[p.Name]; !found {
t.Errorf("BUG: TaskRunStatus.RetriesStatus did not report pod name %q", p.Name)
}
if p.Status.Phase != corev1.PodFailed {
t.Errorf("BUG: Pod %q is not failed: %v", p.Name, p.Status.Phase)
// Check each container in the pod, rather than the phase, since the phase doesn't update to a terminal state instantly.
// See https://github.com/kubernetes/kubernetes/pull/108366
for _, c := range p.Status.ContainerStatuses {
if c.State.Terminated == nil {
t.Errorf("BUG: Container %s in pod %s is not terminated", c.Name, p.Name)
} else if c.State.Terminated.ExitCode != 1 {
t.Errorf("BUG: Container %s in pod %s has exit code %d, expected 1", c.Name, p.Name, c.State.Terminated.ExitCode)
}
}
}
}
Expand Down

0 comments on commit 13f9c0f

Please sign in to comment.