diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index 3f55b20243a..f6e68f0a244 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -2849,11 +2849,17 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineTaskRunSpec(ref common.ReferenceCa }, }, }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata"), + }, + }, }, }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride"}, } } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go index d06a7f57006..d7d8c64ed0f 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go @@ -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 @@ -601,3 +604,8 @@ func (pr *PipelineRun) GetTaskRunSpec(pipelineTaskName string) PipelineTaskRunSp } return s } + +// PipelineTaskRunSpecMetadata returns Metadata field of PipelineTaskRunSpec +func (ptrs *PipelineTaskRunSpec) PipelineTaskRunSpecMetadata() PipelineTaskMetadata { + return ptrs.Metadata +} diff --git a/pkg/apis/pipeline/v1beta1/swagger.json b/pkg/apis/pipeline/v1beta1/swagger.json index 92af2a98c73..e352a339731 100644 --- a/pkg/apis/pipeline/v1beta1/swagger.json +++ b/pkg/apis/pipeline/v1beta1/swagger.json @@ -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" }, diff --git a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go index 983a234151b..72635ce1975 100644 --- a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go @@ -1212,6 +1212,7 @@ func (in *PipelineTaskRunSpec) DeepCopyInto(out *PipelineTaskRunSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + in.Metadata.DeepCopyInto(&out.Metadata) return } diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index e8947b9b0a7..e326807a2da 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -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.