Skip to content

Commit

Permalink
Redesign PAC Resolver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piyush-garg authored and chmouel committed Sep 19, 2024
1 parent 6f16e11 commit d87fe97
Show file tree
Hide file tree
Showing 19 changed files with 810 additions and 344 deletions.
80 changes: 37 additions & 43 deletions pkg/matcher/annotation_tasks_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,60 +181,54 @@ func grabValuesFromAnnotations(annotations map[string]string, annotationReg stri
return ret, nil
}

// GetTaskFromAnnotations Get task remotely if they are on Annotations.
func (rt RemoteTasks) GetTaskFromAnnotations(ctx context.Context, annotations map[string]string) ([]*tektonv1.Task, error) {
ret := []*tektonv1.Task{}
tasks, err := grabValuesFromAnnotations(annotations, taskAnnotationsRegexp)
func GrabTasksFromAnnotations(annotations map[string]string) ([]string, error) {
return grabValuesFromAnnotations(annotations, taskAnnotationsRegexp)
}

func GrabPipelineFromAnnotations(annotations map[string]string) (string, error) {
pipelinesAnnotation, err := grabValuesFromAnnotations(annotations, pipelineAnnotationsRegexp)
if err != nil {
return nil, err
return "", err
}
for _, v := range tasks {
data, err := rt.getRemote(ctx, v, true, "task")
if err != nil {
return nil, fmt.Errorf("error getting remote task \"%s\": %w", v, err)
}
if data == "" {
return nil, fmt.Errorf("could not get remote task \"%s\": returning empty", v)
}

task, err := rt.convertTotask(ctx, v, data)
if err != nil {
return nil, err
}
ret = append(ret, task)
if len(pipelinesAnnotation) > 1 {
return "", fmt.Errorf("only one pipeline is allowed on remote resolution, we have received multiple of them: %+v", pipelinesAnnotation)
}
return ret, nil
if len(pipelinesAnnotation) == 0 {
return "", nil
}
return pipelinesAnnotation[0], nil
}

// GetPipelineFromAnnotations Get pipeline remotely if they are on Annotations
// TODO: merge in a generic between the two.
func (rt RemoteTasks) GetPipelineFromAnnotations(ctx context.Context, annotations map[string]string) (*tektonv1.Pipeline, error) {
ret := []*tektonv1.Pipeline{}
pipelinesAnnotation, err := grabValuesFromAnnotations(annotations, pipelineAnnotationsRegexp)
func (rt RemoteTasks) GetTaskFromAnnotationName(ctx context.Context, name string) (*tektonv1.Task, error) {
data, err := rt.getRemote(ctx, name, true, "task")
if err != nil {
return nil, fmt.Errorf("error getting remote task \"%s\": %w", name, err)
}
if data == "" {
return nil, fmt.Errorf("could not get remote task \"%s\": returning empty", name)
}

task, err := rt.convertTotask(ctx, name, data)
if err != nil {
return nil, err
}
if len(pipelinesAnnotation) > 1 {
return nil, fmt.Errorf("only one pipeline is allowed on remote resolution, we have received multiple of them: %+v", pipelinesAnnotation)
return task, nil
}

func (rt RemoteTasks) GetPipelineFromAnnotationName(ctx context.Context, name string) (*tektonv1.Pipeline, error) {
data, err := rt.getRemote(ctx, name, true, "pipeline")
if err != nil {
return nil, fmt.Errorf("error getting remote pipeline \"%s\": %w", name, err)
}
if len(pipelinesAnnotation) == 0 {
return nil, nil
if data == "" {
return nil, fmt.Errorf("could not get remote pipeline \"%s\": returning empty", name)
}
for _, v := range pipelinesAnnotation {
data, err := rt.getRemote(ctx, v, true, "pipeline")
if err != nil {
return nil, fmt.Errorf("error getting remote pipeline %s: %w", v, err)
}
if data == "" {
return nil, fmt.Errorf("could not get remote pipeline \"%s\": returning empty", v)
}
pipeline, err := rt.convertToPipeline(ctx, v, data)
if err != nil {
return nil, err
}
ret = append(ret, pipeline)

pipeline, err := rt.convertToPipeline(ctx, name, data)
if err != nil {
return nil, err
}
return ret[0], nil
return pipeline, nil
}

// getFileFromLocalFS get task locally if file exist
Expand Down
Loading

0 comments on commit d87fe97

Please sign in to comment.