Skip to content

Commit d87fe97

Browse files
piyush-gargchmouel
authored andcommitted
Redesign PAC Resolver
This will redesign resolver to work with multiple edge case scenarios. Previously pac resolver was filtering pipelinerun based on annotations but it was resolving all pipelines in .tekton dir leading to resolving unnecessary pipelines and other issue was it was storing task based on task name, instead of annotation name and version, so different version of task were not used across pipelineruns in .tekton dir Now with new design we are first filtering pipelinerun based on annotations, and then processing all pipelineruns one by one and only resolving pipeline related to these pipelineruns. Also we are now maintaining map of tasks with name and version at event level to not re fetch the task and now inline spec replacement in pipelinerun is done one by one so respective task as mentioned in annotation with name and version is used Also before filtering the pipelineruns, we should make sure that no two pipelineruns exists with same name in .tekton dir Added tests for the three scenarios
1 parent 6f16e11 commit d87fe97

19 files changed

+810
-344
lines changed

pkg/matcher/annotation_tasks_install.go

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -181,60 +181,54 @@ func grabValuesFromAnnotations(annotations map[string]string, annotationReg stri
181181
return ret, nil
182182
}
183183

184-
// GetTaskFromAnnotations Get task remotely if they are on Annotations.
185-
func (rt RemoteTasks) GetTaskFromAnnotations(ctx context.Context, annotations map[string]string) ([]*tektonv1.Task, error) {
186-
ret := []*tektonv1.Task{}
187-
tasks, err := grabValuesFromAnnotations(annotations, taskAnnotationsRegexp)
184+
func GrabTasksFromAnnotations(annotations map[string]string) ([]string, error) {
185+
return grabValuesFromAnnotations(annotations, taskAnnotationsRegexp)
186+
}
187+
188+
func GrabPipelineFromAnnotations(annotations map[string]string) (string, error) {
189+
pipelinesAnnotation, err := grabValuesFromAnnotations(annotations, pipelineAnnotationsRegexp)
188190
if err != nil {
189-
return nil, err
191+
return "", err
190192
}
191-
for _, v := range tasks {
192-
data, err := rt.getRemote(ctx, v, true, "task")
193-
if err != nil {
194-
return nil, fmt.Errorf("error getting remote task \"%s\": %w", v, err)
195-
}
196-
if data == "" {
197-
return nil, fmt.Errorf("could not get remote task \"%s\": returning empty", v)
198-
}
199-
200-
task, err := rt.convertTotask(ctx, v, data)
201-
if err != nil {
202-
return nil, err
203-
}
204-
ret = append(ret, task)
193+
if len(pipelinesAnnotation) > 1 {
194+
return "", fmt.Errorf("only one pipeline is allowed on remote resolution, we have received multiple of them: %+v", pipelinesAnnotation)
205195
}
206-
return ret, nil
196+
if len(pipelinesAnnotation) == 0 {
197+
return "", nil
198+
}
199+
return pipelinesAnnotation[0], nil
207200
}
208201

209-
// GetPipelineFromAnnotations Get pipeline remotely if they are on Annotations
210-
// TODO: merge in a generic between the two.
211-
func (rt RemoteTasks) GetPipelineFromAnnotations(ctx context.Context, annotations map[string]string) (*tektonv1.Pipeline, error) {
212-
ret := []*tektonv1.Pipeline{}
213-
pipelinesAnnotation, err := grabValuesFromAnnotations(annotations, pipelineAnnotationsRegexp)
202+
func (rt RemoteTasks) GetTaskFromAnnotationName(ctx context.Context, name string) (*tektonv1.Task, error) {
203+
data, err := rt.getRemote(ctx, name, true, "task")
204+
if err != nil {
205+
return nil, fmt.Errorf("error getting remote task \"%s\": %w", name, err)
206+
}
207+
if data == "" {
208+
return nil, fmt.Errorf("could not get remote task \"%s\": returning empty", name)
209+
}
210+
211+
task, err := rt.convertTotask(ctx, name, data)
214212
if err != nil {
215213
return nil, err
216214
}
217-
if len(pipelinesAnnotation) > 1 {
218-
return nil, fmt.Errorf("only one pipeline is allowed on remote resolution, we have received multiple of them: %+v", pipelinesAnnotation)
215+
return task, nil
216+
}
217+
218+
func (rt RemoteTasks) GetPipelineFromAnnotationName(ctx context.Context, name string) (*tektonv1.Pipeline, error) {
219+
data, err := rt.getRemote(ctx, name, true, "pipeline")
220+
if err != nil {
221+
return nil, fmt.Errorf("error getting remote pipeline \"%s\": %w", name, err)
219222
}
220-
if len(pipelinesAnnotation) == 0 {
221-
return nil, nil
223+
if data == "" {
224+
return nil, fmt.Errorf("could not get remote pipeline \"%s\": returning empty", name)
222225
}
223-
for _, v := range pipelinesAnnotation {
224-
data, err := rt.getRemote(ctx, v, true, "pipeline")
225-
if err != nil {
226-
return nil, fmt.Errorf("error getting remote pipeline %s: %w", v, err)
227-
}
228-
if data == "" {
229-
return nil, fmt.Errorf("could not get remote pipeline \"%s\": returning empty", v)
230-
}
231-
pipeline, err := rt.convertToPipeline(ctx, v, data)
232-
if err != nil {
233-
return nil, err
234-
}
235-
ret = append(ret, pipeline)
226+
227+
pipeline, err := rt.convertToPipeline(ctx, name, data)
228+
if err != nil {
229+
return nil, err
236230
}
237-
return ret[0], nil
231+
return pipeline, nil
238232
}
239233

240234
// getFileFromLocalFS get task locally if file exist

0 commit comments

Comments
 (0)