Skip to content

Commit

Permalink
Fix --ignore-running unexpectedly deleting incomplete TaskRuns
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Sep 8, 2022
1 parent 3be28b5 commit 735d3bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
11 changes: 3 additions & 8 deletions pkg/cmd/taskrun/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,11 @@ func allTaskRunNames(cs *cli.Clients, keep, since int, ignoreRunning bool, label
if ignoreRunning {
var taskRunTmp = []v1beta1.TaskRun{}
for _, v := range taskRuns.Items {
if v.Status.Conditions == nil {
if v.Status.CompletionTime == nil {
// Skip TaskRuns without CompletionTimes as they have not finished running yet
continue
}
for _, v2 := range v.Status.Conditions {
if v2.Reason == "Running" || v2.Reason == "Pending" || v2.Reason == "Started" {
continue
}
taskRunTmp = append(taskRunTmp, v)
break
}
taskRunTmp = append(taskRunTmp, v)
}
taskRuns.Items = taskRunTmp
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/taskrun/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[3].pipelineClient,
inputStream: strings.NewReader("y"),
wantError: false,
want: "Are you sure you want to delete all TaskRuns in namespace \"ns\" (y/n): All 10 TaskRuns(Completed) deleted in namespace \"ns\"\n",
want: "Are you sure you want to delete all TaskRuns in namespace \"ns\" (y/n): All 9 TaskRuns(Completed) deleted in namespace \"ns\"\n",
},
{
name: "Delete all with -f",
Expand All @@ -589,7 +589,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[4].pipelineClient,
inputStream: nil,
wantError: false,
want: "All 10 TaskRuns(Completed) deleted in namespace \"ns\"\n",
want: "All 9 TaskRuns(Completed) deleted in namespace \"ns\"\n",
},
{
name: "Delete all keeping 2",
Expand Down Expand Up @@ -670,7 +670,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[0].pipelineClient,
inputStream: strings.NewReader("y"),
wantError: false,
want: "Are you sure you want to delete all TaskRuns related to ClusterTask \"random\" (y/n): All 6 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n",
want: "Are you sure you want to delete all TaskRuns related to ClusterTask \"random\" (y/n): All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n",
},
{
name: "Error from deleting TaskRun with non-existing ClusterTask",
Expand All @@ -697,7 +697,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[6].pipelineClient,
inputStream: nil,
wantError: false,
want: "6 expired Taskruns(Completed) has been deleted in namespace \"ns\", kept 4\n",
want: "6 expired Taskruns(Completed) has been deleted in namespace \"ns\", kept 3\n",
},
{
name: "Delete all Taskruns older than 60mn associated with random Task",
Expand Down Expand Up @@ -733,7 +733,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[9].pipelineClient,
inputStream: nil,
wantError: false,
want: "8 TaskRuns(Completed) has been deleted in namespace \"ns\", kept 2\n",
want: "7 TaskRuns(Completed) has been deleted in namespace \"ns\", kept 2\n",
},
{
name: "Delete all TaskRuns older than 60mn and keeping 2 TaskRuns associated with random Task",
Expand Down Expand Up @@ -787,7 +787,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[4].pipelineClient,
inputStream: nil,
wantError: false,
want: "All 4 TaskRuns deleted in namespace \"ns\"\n",
want: "All 5 TaskRuns deleted in namespace \"ns\"\n",
},
{
name: "Delete the Task present and give error for non-existent Task",
Expand Down Expand Up @@ -841,7 +841,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[14].pipelineClient,
inputStream: nil,
wantError: false,
want: "All 6 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n",
want: "All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n",
},
{
name: "Delete all of clustertask with explicit --ignore-running true",
Expand All @@ -850,7 +850,7 @@ func TestTaskRunDelete(t *testing.T) {
input: seeds[15].pipelineClient,
inputStream: nil,
wantError: false,
want: "All 6 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n",
want: "All 5 TaskRuns(Completed) associated with ClusterTask \"random\" deleted in namespace \"ns\"\n",
},
{
name: "Delete all of clustertask with --ignore-running false",
Expand Down

0 comments on commit 735d3bd

Please sign in to comment.