Skip to content

Commit

Permalink
Add Metadata Support
Browse files Browse the repository at this point in the history
  • Loading branch information
austinzhao-go committed May 2, 2022
1 parent 68f2a66 commit 1358a6b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
8 changes: 7 additions & 1 deletion pkg/apis/pipeline/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ type PipelineTaskRunSpec struct {
StepOverrides []TaskRunStepOverride `json:"stepOverrides,omitempty"`
// +listType=atomic
SidecarOverrides []TaskRunSidecarOverride `json:"sidecarOverrides,omitempty"`

// +optional
Metadata PipelineTaskMetadata `json:"metadata,omitempty"`
}

// GetTaskRunSpec returns the task specific spec for a given
Expand All @@ -601,3 +604,7 @@ func (pr *PipelineRun) GetTaskRunSpec(pipelineTaskName string) PipelineTaskRunSp
}
return s
}

func (ptrs *PipelineTaskRunSpec) PipelineTaskRunSpecMetadata() PipelineTaskMetadata {
return ptrs.Metadata
}
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,10 @@
"description": "PipelineTaskRunSpec can be used to configure specific specs for a concrete Task",
"type": "object",
"properties": {
"metadata": {
"default": {},
"$ref": "#/definitions/v1beta1.PipelineTaskMetadata"
},
"pipelineTaskName": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,23 +1008,28 @@ func combineTaskRunAndTaskSpecLabels(pr *v1beta1.PipelineRun, pipelineTask *v1be
}

func combineTaskRunAndTaskSpecAnnotations(pr *v1beta1.PipelineRun, pipelineTask *v1beta1.PipelineTask) map[string]string {
var tsAnnotations map[string]string
trAnnotations := getTaskrunAnnotations(pr)
annotations := make(map[string]string)

taskRunSpec := pr.GetTaskRunSpec(pipelineTask.Name)
addAnnotationsByPrecedence(annotations, taskRunSpec.PipelineTaskRunSpecMetadata().Annotations)

addAnnotationsByPrecedence(annotations, getTaskrunAnnotations(pr))

if pipelineTask.TaskSpec != nil {
tsAnnotations = pipelineTask.TaskSpecMetadata().Annotations
addAnnotationsByPrecedence(annotations, pipelineTask.TaskSpecMetadata().Annotations)
}

// annotations from TaskRun takes higher precedence over the ones specified in Pipeline through TaskSpec
// initialize annotations with TaskRun annotations
annotations := trAnnotations
for key, value := range tsAnnotations {
// add annotations from TaskSpec if the annotation does not exist
return annotations
}

// Metadata Precedence Order: PipelineTaskRunSpec > PipelineRun > PipelineTaskSpec
func addAnnotationsByPrecedence(annotations map[string]string, addedAnnotations map[string]string) {
for key, value := range addedAnnotations {
// add new annotations if the key not exists in current ones
if _, ok := annotations[key]; !ok {
annotations[key] = value
}
}
return annotations
}

// getFinallyTaskRunTimeout returns the timeout to set when creating the ResolvedPipelineRunTask, which is a finally Task.
Expand Down

0 comments on commit 1358a6b

Please sign in to comment.