From b23f7d4378ae96c35868ace157fe275ba972c38c Mon Sep 17 00:00:00 2001 From: assertion Date: Wed, 22 Jan 2020 13:23:44 +0800 Subject: [PATCH] fix updateTaskRunStatusForTimeout get pod switch/case may cause pod not deleted when taskRun timeout. --- pkg/reconciler/taskrun/taskrun.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index f7a69849b40..b7c8c185e2c 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -511,17 +511,14 @@ func (c *Reconciler) updateTaskRunStatusForTimeout(tr *v1alpha1.TaskRun) error { // // If there's no such Pod, there's nothing to delete. pod, err := getPod(tr, c.KubeClientSet) - switch { - case err == nil: - // Nothing to delete. - case err != nil: + if err != nil { + return err + } + + c.Logger.Infof("TaskRun %q has timed out, deleting pod", tr.Name) + if err := c.KubeClientSet.CoreV1().Pods(tr.Namespace).Delete(pod.Name, &metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) { + c.Logger.Errorf("Failed to terminate pod: %v", err) return err - default: - c.Logger.Infof("TaskRun %q has timed out, deleting pod", tr.Name) - if err := c.KubeClientSet.CoreV1().Pods(tr.Namespace).Delete(pod.Name, &metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) { - c.Logger.Errorf("Failed to terminate pod: %v", err) - return err - } } timeout := tr.Spec.Timeout.Duration