tektoncd / pipeline

A cloud-native Pipeline resource.
https://tekton.dev
Apache License 2.0
8.35k stars 1.76k forks source link

Index out of range panic in CheckMissingResultReferences when references are missing #8083

Open jbelldev opened 5 days ago

jbelldev commented 5 days ago

When a PipelineRun lacks references (possibly TaskRun), it can cause the tekton-pipelines-controller pod to crash due to a runtime panic triggered by accessing a non-existing element in an array.

Expected Behavior

Controller should handle missing references gracefully, without crashing.

Actual Behavior

Pod crashes with following logs:

panic: runtime error: index out of range [0] with length 0 goroutine 382 [running]: github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources.CheckMissingResultReferences({0xc03072cd00, 0xf, 0x44775a0?}, {0xc037fdfe30, 0x2, 0x0?}) /go/src/github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go:801 +0x27b github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun.(Reconciler).runNextSchedulableTask(0xc0007ec240, {0x2ce3ce8, 0xc056ddfa10}, 0xc056de8480, 0xc048d0ed08) /go/src/github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/pipelinerun.go:841 +0x329 github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun.(Reconciler).reconcile(0xc0007ec240, {0x2ce3ce8, 0xc056ddf980}, 0xc056de8480, 0x44775a0?, 0xc056116a80) /go/src/github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/pipelinerun.go:773 +0x4775 github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun.(Reconciler).ReconcileKind(0xc0007ec240, {0x2ce3ce8, 0xc056ddf650}, 0xc056de8480) /go/src/github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/pipelinerun.go:265 +0x1132 github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1/pipelinerun.(reconcilerImpl).Reconcile(0xc000756640, {0x2ce3ce8, 0xc056ddf560}, {0xc0514bf180, 0x45}) /go/src/github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1/pipelinerun/reconciler.go:236 +0x53b knative.dev/pkg/controller.(Impl).processNextWorkItem(0xc000751e60) /go/src/github.com/tektoncd/pipeline/vendor/knative.dev/pkg/controller/controller.go:542 +0x4ad knative.dev/pkg/controller.(Impl).RunContext.func3() /go/src/github.com/tektoncd/pipeline/vendor/knative.dev/pkg/controller/controller.go:491 +0x59 created by knative.dev/pkg/controller.(*Impl).RunContext in goroutine 234 /go/src/github.com/tektoncd/pipeline/vendor/knative.dev/pkg/controller/controller.go:489 +0x349

Steps to Reproduce the Problem

  1. Create PipelineRun without task runs (have not yet confirmed)
  2. Observe a crash in tekton-pipelines-controller related to index out of range error

Additional Info

Issue appears to be in the these lines of CheckMissingResultReferences, which assumes there will be at least one reference to each.

...
customRun := referencedPipelineTask.CustomRuns[0] 
...
taskRun := referencedPipelineTask.TaskRuns[0]
...

A basic length check may be needed either, though notably the former is first checked for a CustomRun reference and might be skipped over if empty.

$ omc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.14.27   True        False         6d      Cluster version is 4.14.27
$ tkn version
Client version: 0.33.0
Chains version: v0.20.1
Pipeline version: v0.59.0
Triggers version: v0.26.2
Operator version: devel

Related to https://issues.redhat.com/browse/SRVKP-5770