Skip to content

Commit

Permalink
allow pipeline runs whose task/custom runs have been deleted still ti…
Browse files Browse the repository at this point in the history
…meout

Back with PR 5134 Tekton started using the cancel function for cleaning up
underlying TaskRuns of PipelineRuns that are timing out, though separate
timeout functions were used (presumably in case the timeout behavior needed to be
tweaked from the cancel behavior later on).  Then, in PR 5288, improvements to
the baseline cancel function were made to still complete cancel processing of a
PipelineRun if the underlying TaskRuns were deleted.  However, that same accomodation
was not made for the timeout path.  This change addresses that, but still keeps the
timeout codepaths separate from the 'base' cancel codepaths.
  • Loading branch information
gabemontero committed Jan 24, 2024
1 parent 97ffba2 commit e79a236
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/reconciler/pipelinerun/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/reconciler/pipelinerun/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit e79a236

Please sign in to comment.