Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.38: cherry-pick] Use step.ImageID instead of looking into status.TaskSpec #5246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use step.ImageID instead of looking into status.TaskSpec
`tr.Status.TaskSpec.Steps` can be out-of-sync with
`tr.Status.Steps`. As we already have the image information (through
`ImageID`) in the struct be are getting from our iteration, we don't
need to look into another array, with the risk of getting a panic.

The same goes for sidecars.

We managed to get multiple panics on the controller prior to this change.

See #4952 for the initial implementation.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester authored and piyush-garg committed Aug 1, 2022
commit 17e17c545b4cc5b16f0acc290df7dc191652afd4
8 changes: 4 additions & 4 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,16 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1beta1.TaskRun) pkg
}

func (c *Reconciler) checkPodFailed(tr *v1beta1.TaskRun) (bool, v1beta1.TaskRunReason, string) {
for index, step := range tr.Status.Steps {
for _, step := range tr.Status.Steps {
if step.Waiting != nil && step.Waiting.Reason == "ImagePullBackOff" {
image := tr.Status.TaskSpec.Steps[index].Image
image := step.ImageID
message := fmt.Sprintf(`The step %q in TaskRun %q failed to pull the image %q. The pod errored with the message: "%s."`, step.Name, tr.Name, image, step.Waiting.Message)
return true, v1beta1.TaskRunReasonImagePullFailed, message
}
}
for index, sidecar := range tr.Status.Sidecars {
for _, sidecar := range tr.Status.Sidecars {
if sidecar.Waiting != nil && sidecar.Waiting.Reason == "ImagePullBackOff" {
image := tr.Status.TaskSpec.Sidecars[index].Image
image := sidecar.ImageID
message := fmt.Sprintf(`The sidecar %q in TaskRun %q failed to pull the image %q. The pod errored with the message: "%s."`, sidecar.Name, tr.Name, image, sidecar.Waiting.Message)
return true, v1beta1.TaskRunReasonImagePullFailed, message
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,7 @@ status:
steps:
- container: step-unnamed-0
name: unnamed-0
imageID: whatever
waiting:
message: Back-off pulling image "whatever"
reason: ImagePullBackOff
Expand Down Expand Up @@ -2211,6 +2212,7 @@ status:
startedAt: "2022-06-09T10:13:41Z"
- container: step-unnamed-1
name: unnamed-1
imageID: whatever
waiting:
message: Back-off pulling image "whatever"
reason: ImagePullBackOff
Expand Down