Skip to content

Commit

Permalink
Merge pull request #675 from opendevstack/fix/parallel-run-after
Browse files Browse the repository at this point in the history
Set dependency on start task for all parallel tasks
  • Loading branch information
michaelsauter authored Mar 3, 2023
2 parents 9d70081 + 7d020a9 commit 4cac16c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ listed in the changelog.

- Setup of secrets during `install.sh` does not work if secret contains `/` ([#670](https://github.com/opendevstack/ods-pipeline/issues/670))
- `ods-start` is unable to cleanup workspace for some storage configurations due to changes in `ods-package-image` ([#672](https://github.com/opendevstack/ods-pipeline/issues/672))
- `runAfter: [start]` not set for all parallel tasks ([#671](https://github.com/opendevstack/ods-pipeline/issues/671))

## [0.10.0] - 2023-02-27

Expand Down
10 changes: 9 additions & 1 deletion internal/manager/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,16 @@ func assemblePipelineSpec(cfg PipelineConfig, taskKind tekton.TaskKind, taskSuff
tektonStringParam("version", "$(params.version)"),
},
})

if len(cfg.Tasks) > 0 {
cfg.Tasks[0].RunAfter = append(cfg.Tasks[0].RunAfter, "start")
// Add "start" to runAfter of the first configured task, and to each further task
// that does not set runAfter until we hit a task that does.
for i := range cfg.Tasks {
if i > 0 && len(cfg.Tasks[i].RunAfter) > 0 {
break
}
cfg.Tasks[i].RunAfter = append(cfg.Tasks[i].RunAfter, "start")
}
tasks = append(tasks, cfg.Tasks...)
}

Expand Down
68 changes: 68 additions & 0 deletions internal/manager/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,71 @@ func TestAssemblePipeline(t *testing.T) {
t.Fatalf("expected (-want +got):\n%s", diff)
}
}

func TestTasksRunAfterInjection(t *testing.T) {
tests := map[string]struct {
cfgTasks []tekton.PipelineTask
want []tekton.PipelineTask
}{
"one build task": {
cfgTasks: []tekton.PipelineTask{
{Name: "build"},
{Name: "package-image", RunAfter: []string{"build"}},
},
want: []tekton.PipelineTask{
{Name: "start"},
{Name: "build", RunAfter: []string{"start"}},
{Name: "package-image", RunAfter: []string{"build"}},
},
},
"parallel build tasks": {
cfgTasks: []tekton.PipelineTask{
{Name: "build-one"},
{Name: "build-two"},
{Name: "package-image", RunAfter: []string{"build-one", "build-two"}},
},
want: []tekton.PipelineTask{
{Name: "start"},
{Name: "build-one", RunAfter: []string{"start"}},
{Name: "build-two", RunAfter: []string{"start"}},
{Name: "package-image", RunAfter: []string{"build-one", "build-two"}},
},
},
"no configured tasks": {
cfgTasks: []tekton.PipelineTask{},
want: []tekton.PipelineTask{
{Name: "start"},
},
},
"only parallel tasks": {
cfgTasks: []tekton.PipelineTask{
{Name: "build-one"},
{Name: "build-two"},
},
want: []tekton.PipelineTask{
{Name: "start"},
{Name: "build-one", RunAfter: []string{"start"}},
{Name: "build-two", RunAfter: []string{"start"}},
},
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
cfg := PipelineConfig{Tasks: tc.cfgTasks}
got := assemblePipelineSpec(cfg, tekton.NamespacedTaskKind, "")
wantRunAfter := [][]string{}
for _, task := range tc.want {
wantRunAfter = append(wantRunAfter, task.RunAfter)
}
gotRunAfter := [][]string{}
for _, task := range got.Tasks {
gotRunAfter = append(gotRunAfter, task.RunAfter)
}
if diff := cmp.Diff(wantRunAfter, gotRunAfter); diff != "" {
t.Fatalf("expected (-want +got):\n%s", diff)
}
})
}

}

0 comments on commit 4cac16c

Please sign in to comment.