Skip to content

Commit 3997b0a

Browse files
committed
fix: prevent inconsistencies when assembling base taskURLs
The base URL for relative tasks was determined by iterating over the fetchedResourcesForEvent map, which stores pipeline URLs as keys. However, since maps are unordered in Go, this can result in inconsistent behavior when multiple remote pipelines exist for the same Event (i.e., when >2 PipelineRuns are triggered). This change ensures that the base URL is consistent per PipelineRun.
1 parent b658ee8 commit 3997b0a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pkg/resolve/remote.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ func alreadyFetchedResource[T NamedItem](resources map[string]T, resourceName st
2121
return false
2222
}
2323

24-
func createTaskURL(pipelines map[string]*tektonv1.Pipeline, tasks []string) ([]string, error) {
24+
func createTaskURL(eventPipelines map[string]*tektonv1.Pipeline, pipeline *tektonv1.Pipeline, tasks []string) ([]string, error) {
2525
var pURL *url.URL
2626
var err error
27-
for p := range pipelines {
28-
pURL, err = url.Parse(p)
27+
for ep := range eventPipelines {
28+
// ensure the URL to be parsed matches the
29+
// remote pipeline of the current PipelineRun
30+
if eventPipelines[ep] != pipeline {
31+
continue
32+
}
33+
pURL, err = url.Parse(ep)
2934
if err != nil {
3035
return tasks, err
3136
}
3237
pPath := strings.SplitAfter(pURL.Path, "/")
3338
// pop the pipeline target path from the URL
3439
pPath = pPath[:len(pPath)-1]
35-
36-
var newPath string
37-
for _, v := range pPath {
38-
newPath += v
39-
}
40-
pURL.Path = newPath
40+
pURL.Path = strings.Join(pPath, "")
4141
}
4242
taskURLS := make([]string, len(tasks))
4343
for i, t := range tasks {
@@ -133,7 +133,7 @@ func resolveRemoteResources(ctx context.Context, rt *matcher.RemoteTasks, types
133133
return []*tektonv1.PipelineRun{}, fmt.Errorf("error getting remote task from pipeline annotations: %w", err)
134134
}
135135
// check for relative task references and assemble FQDNs
136-
pipelineTasks, err = createTaskURL(fetchedResourcesForEvent.Pipelines, pipelineTasks)
136+
pipelineTasks, err = createTaskURL(fetchedResourcesForEvent.Pipelines, fetchedResourcesForPipelineRun.Pipeline, pipelineTasks)
137137
if err != nil {
138138
return []*tektonv1.PipelineRun{}, err
139139
}

0 commit comments

Comments
 (0)