diff --git a/pkg/reconciler/pipelinerun/timeout.go b/pkg/reconciler/pipelinerun/timeout.go index 32a1da8ae7d..8ae29a62d30 100644 --- a/pkg/reconciler/pipelinerun/timeout.go +++ b/pkg/reconciler/pipelinerun/timeout.go @@ -27,6 +27,7 @@ import ( "go.uber.org/zap" "gomodules.xyz/jsonpatch/v2" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" @@ -92,6 +93,17 @@ func timeoutPipelineRun(ctx context.Context, logger *zap.SugaredLogger, pr *v1.P func timeoutCustomRun(ctx context.Context, customRunName string, namespace string, clientSet clientset.Interface) error { _, err := clientSet.TektonV1beta1().CustomRuns(namespace).Patch(ctx, customRunName, types.JSONPatchType, timeoutCustomRunPatchBytes, metav1.PatchOptions{}, "") + if errors.IsNotFound(err) { + return nil + } + return err +} + +func timeoutTaskRun(ctx context.Context, taskRunName string, namespace string, clientSet clientset.Interface) error { + _, err := clientSet.TektonV1().TaskRuns(namespace).Patch(ctx, taskRunName, types.JSONPatchType, timeoutTaskRunPatchBytes, metav1.PatchOptions{}, "") + if errors.IsNotFound(err) { + return nil + } return err } @@ -112,7 +124,7 @@ func timeoutPipelineTasksForTaskNames(ctx context.Context, logger *zap.SugaredLo for _, taskRunName := range trNames { logger.Infof("patching TaskRun %s for timeout", taskRunName) - if _, err := clientSet.TektonV1().TaskRuns(pr.Namespace).Patch(ctx, taskRunName, types.JSONPatchType, timeoutTaskRunPatchBytes, metav1.PatchOptions{}, ""); err != nil { + if err := timeoutTaskRun(ctx, taskRunName, pr.Namespace, clientSet); err != nil { errs = append(errs, fmt.Errorf("failed to patch TaskRun `%s` with timeout: %w", taskRunName, err).Error()) continue } diff --git a/pkg/reconciler/pipelinerun/timeout_test.go b/pkg/reconciler/pipelinerun/timeout_test.go index 0b65cf08f35..a369aeee268 100644 --- a/pkg/reconciler/pipelinerun/timeout_test.go +++ b/pkg/reconciler/pipelinerun/timeout_test.go @@ -59,6 +59,23 @@ func TestTimeoutPipelineRun(t *testing.T) { taskRuns: []*v1.TaskRun{ {ObjectMeta: metav1.ObjectMeta{Name: "t1"}}, }, + }, { + name: "multiple-runs-missing", + pipelineRun: &v1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{Name: "test-pipeline-run-timedout"}, + Spec: v1.PipelineRunSpec{}, + Status: v1.PipelineRunStatus{PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{{ + TypeMeta: runtime.TypeMeta{Kind: taskRun}, + Name: "t1", + PipelineTaskName: "task-1", + }, { + TypeMeta: runtime.TypeMeta{Kind: customRun}, + Name: "t2", + PipelineTaskName: "task-2", + }}, + }}, + }, }, { name: "multiple-taskruns", pipelineRun: &v1.PipelineRun{