Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEP-0090: Resolve PipelineTask with Custom Task #5048

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type ResolvedPipelineTask struct {
CustomTask bool
RunName string
Run *v1alpha1.Run
RunNames []string
Runs []*v1alpha1.Run
PipelineTask *v1beta1.PipelineTask
ResolvedTaskResources *resources.ResolvedTaskResources
Expand Down Expand Up @@ -525,6 +526,15 @@ func ResolvePipelineTask(
}
rpt.CustomTask = isCustomTask(ctx, rpt)
switch {
case rpt.IsCustomTask() && rpt.IsMatrixed():
jerop marked this conversation as resolved.
Show resolved Hide resolved
rpt.RunNames = getNamesOfRuns(pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name, pipelineTask.GetMatrixCombinationsCount())
for _, runName := range rpt.RunNames {
run, err := getRun(runName)
if err != nil && !kerrors.IsNotFound(err) {
return nil, fmt.Errorf("error retrieving Run %s: %w", runName, err)
}
rpt.Runs = append(rpt.Runs, run)
}
case rpt.IsCustomTask():
rpt.RunName = getRunName(pipelineRun.Status.Runs, pipelineRun.Status.ChildReferences, pipelineTask.Name, pipelineRun.Name)
run, err := getRun(rpt.RunName)
Expand Down
100 changes: 100 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,106 @@ func TestResolvePipelineRunTask_WithMatrix(t *testing.T) {
}
}

func TestResolvePipelineRunTask_WithMatrixedCustomTask(t *testing.T) {
pipelineRunName := "pipelinerun"
pipelineTaskName := "pipelinetask"

pr := v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: pipelineRunName,
},
}

var runs []*v1alpha1.Run
var runNames []string
runsMap := map[string]*v1alpha1.Run{}
for i := 0; i < 9; i++ {
runName := fmt.Sprintf("%s-%s-%d", pipelineRunName, pipelineTaskName, i)
run := &v1alpha1.Run{
ObjectMeta: metav1.ObjectMeta{
Name: runName,
},
}
runs = append(runs, run)
runNames = append(runNames, runName)
runsMap[runName] = run
}

pts := []v1beta1.PipelineTask{{
Name: "pipelinetask",
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Example",
Name: "my-task",
},
Matrix: []v1beta1.Param{{
Name: "platform",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}},
}},
}, {
Name: "pipelinetask",
TaskRef: &v1beta1.TaskRef{
APIVersion: "example.dev/v0",
Kind: "Example",
Name: "my-task",
},
Matrix: []v1beta1.Param{{
Name: "platform",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"linux", "mac", "windows"}},
}, {
Name: "browsers",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"chrome", "safari", "firefox"}},
}},
}}

getTask := func(ctx context.Context, name string) (v1beta1.TaskObject, error) { return task, nil }
getTaskRun := func(name string) (*v1beta1.TaskRun, error) { return &trs[0], nil }
getRun := func(name string) (*v1alpha1.Run, error) { return runsMap[name], nil }

for _, tc := range []struct {
name string
pt v1beta1.PipelineTask
want *ResolvedPipelineTask
}{{
name: "custom task with matrix - single parameter",
lbernick marked this conversation as resolved.
Show resolved Hide resolved
pt: pts[0],
want: &ResolvedPipelineTask{
CustomTask: true,
RunNames: runNames[:3],
Runs: runs[:3],
PipelineTask: &pts[0],
},
}, {
name: "custom task with matrix - multiple parameters",
pt: pts[1],
want: &ResolvedPipelineTask{
CustomTask: true,
RunNames: runNames,
Runs: runs,
PipelineTask: &pts[1],
},
}} {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
cfg := config.NewStore(logtesting.TestLogger(t))
cfg.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName()},
Data: map[string]string{
"enable-api-fields": "alpha",
},
})
ctx = cfg.ToContext(ctx)
rpt, err := ResolvePipelineTask(ctx, pr, getTask, getTaskRun, getRun, tc.pt, nil)
if err != nil {
t.Fatalf("Did not expect error when resolving PipelineRun: %v", err)
}
if d := cmp.Diff(tc.want, rpt); d != "" {
t.Errorf("Did not get expected ResolvedPipelineTask with Matrix and Custom Task: %s", diff.PrintWantGot(d))
}
})
}
}

func TestIsSuccessful(t *testing.T) {
for _, tc := range []struct {
name string
Expand Down