@@ -36,7 +36,7 @@ import (
36
36
taskrunresources "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
37
37
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
38
38
"github.com/tektoncd/pipeline/pkg/system"
39
- test "github.com/tektoncd/pipeline/test"
39
+ "github.com/tektoncd/pipeline/test"
40
40
"github.com/tektoncd/pipeline/test/diff"
41
41
"github.com/tektoncd/pipeline/test/names"
42
42
"go.uber.org/zap"
@@ -3037,3 +3037,117 @@ func TestUpdatePipelineRunStatusFromTaskRuns(t *testing.T) {
3037
3037
})
3038
3038
}
3039
3039
}
3040
+
3041
+ // this test validates pipeline task metadata is embedded into task run
3042
+ func TestReconcile_PipelineTaskMetadata (t * testing.T ) {
3043
+ names .TestingSeed ()
3044
+
3045
+ prs := []* v1beta1.PipelineRun {
3046
+ tb .PipelineRun ("test-pipeline-run-success" ,
3047
+ tb .PipelineRunNamespace ("foo" ),
3048
+ tb .PipelineRunSpec ("test-pipeline" ),
3049
+ ),
3050
+ }
3051
+ ps := []* v1beta1.Pipeline {
3052
+ tb .Pipeline ("test-pipeline" ,
3053
+ tb .PipelineNamespace ("foo" ),
3054
+ tb .PipelineSpec (
3055
+ tb .PipelineTask ("task-without-metadata" , "" ,
3056
+ tb .PipelineTaskSpec (& v1beta1.TaskSpec {
3057
+ Steps : []v1beta1.Step {{Container : corev1.Container {
3058
+ Name : "mystep" ,
3059
+ Image : "myimage" }}},
3060
+ }),
3061
+ ),
3062
+ tb .PipelineTask ("task-with-metadata" , "" ,
3063
+ tb .PipelineTaskSpec (& v1beta1.TaskSpec {
3064
+ Steps : []v1beta1.Step {{Container : corev1.Container {
3065
+ Name : "mystep" ,
3066
+ Image : "myimage" }}},
3067
+ }),
3068
+ tb .PipelineTaskMetadata (metav1.ObjectMeta {
3069
+ Name : "foo" ,
3070
+ Labels : map [string ]string {"label1" : "labelvalue1" , "label2" : "labelvalue2" },
3071
+ Annotations : map [string ]string {"annotation1" : "value1" , "annotation2" : "value2" }}),
3072
+ ),
3073
+ ),
3074
+ ),
3075
+ }
3076
+
3077
+ d := test.Data {
3078
+ PipelineRuns : prs ,
3079
+ Pipelines : ps ,
3080
+ Tasks : nil ,
3081
+ ClusterTasks : nil ,
3082
+ PipelineResources : nil ,
3083
+ }
3084
+
3085
+ testAssets , cancel := getPipelineRunController (t , d )
3086
+ defer cancel ()
3087
+ c := testAssets .Controller
3088
+ clients := testAssets .Clients
3089
+
3090
+ if err := c .Reconciler .Reconcile (context .Background (), "foo/test-pipeline-run-success" ); err != nil {
3091
+ t .Fatalf ("Error reconciling: %s" , err )
3092
+ }
3093
+
3094
+ if len (clients .Pipeline .Actions ()) == 0 {
3095
+ t .Fatalf ("Expected client to have been used to create a TaskRun but it wasn't" )
3096
+ }
3097
+
3098
+ // Check that the PipelineRun was reconciled correctly
3099
+ reconciledRun , err := clients .Pipeline .TektonV1beta1 ().PipelineRuns ("foo" ).Get ("test-pipeline-run-success" , metav1.GetOptions {})
3100
+ if err != nil {
3101
+ t .Fatalf ("Somehow had error getting reconciled run out of fake client: %s" , err )
3102
+ }
3103
+
3104
+ actualTaskRun := make (map [string ]* v1beta1.TaskRun )
3105
+ for _ , a := range clients .Pipeline .Actions () {
3106
+ if a .GetResource ().Resource == "taskruns" {
3107
+ t := a .(ktesting.CreateAction ).GetObject ().(* v1beta1.TaskRun )
3108
+ actualTaskRun [t .Name ] = t
3109
+ }
3110
+ }
3111
+
3112
+ // Check that the expected TaskRun was created
3113
+ if len (actualTaskRun ) != 2 {
3114
+ t .Errorf ("Expected two TaskRuns to be created, but found %d TaskRuns." , len (actualTaskRun ))
3115
+ }
3116
+
3117
+ expectedTaskRun := make (map [string ]* v1beta1.TaskRun )
3118
+ expectedTaskRun ["test-pipeline-run-success-task-with-metadata-mz4c7" ] = tb .TaskRun (
3119
+ "test-pipeline-run-success-task-with-metadata-mz4c7" ,
3120
+ tb .TaskRunNamespace ("foo" ),
3121
+ tb .TaskRunOwnerReference ("PipelineRun" , "test-pipeline-run-success" ,
3122
+ tb .OwnerReferenceAPIVersion ("tekton.dev/v1beta1" ),
3123
+ tb .Controller , tb .BlockOwnerDeletion ),
3124
+ tb .TaskRunLabel ("tekton.dev/pipeline" , "test-pipeline" ),
3125
+ tb .TaskRunLabel ("tekton.dev/pipelineRun" , "test-pipeline-run-success" ),
3126
+ tb .TaskRunLabel (pipeline .GroupName + pipeline .PipelineTaskLabelKey , "task-with-metadata" ),
3127
+ tb .TaskRunLabel ("label1" , "labelvalue1" ),
3128
+ tb .TaskRunLabel ("label2" , "labelvalue2" ),
3129
+ tb .TaskRunAnnotation ("annotation1" , "value1" ),
3130
+ tb .TaskRunAnnotation ("annotation2" , "value2" ),
3131
+ tb .TaskRunSpec (tb .TaskRunTaskSpec (tb .Step ("myimage" , tb .StepName ("mystep" )))),
3132
+ )
3133
+
3134
+ expectedTaskRun ["test-pipeline-run-success-task-without-metadata-9l9zj" ] = tb .TaskRun (
3135
+ "test-pipeline-run-success-task-without-metadata-9l9zj" ,
3136
+ tb .TaskRunNamespace ("foo" ),
3137
+ tb .TaskRunOwnerReference ("PipelineRun" , "test-pipeline-run-success" ,
3138
+ tb .OwnerReferenceAPIVersion ("tekton.dev/v1beta1" ),
3139
+ tb .Controller , tb .BlockOwnerDeletion ),
3140
+ tb .TaskRunLabel ("tekton.dev/pipeline" , "test-pipeline" ),
3141
+ tb .TaskRunLabel ("tekton.dev/pipelineRun" , "test-pipeline-run-success" ),
3142
+ tb .TaskRunLabel (pipeline .GroupName + pipeline .PipelineTaskLabelKey , "task-without-metadata" ),
3143
+ tb .TaskRunSpec (tb .TaskRunTaskSpec (tb .Step ("myimage" , tb .StepName ("mystep" )))),
3144
+ )
3145
+
3146
+ if d := cmp .Diff (actualTaskRun , expectedTaskRun ); d != "" {
3147
+ t .Fatalf ("Expected TaskRuns to match, but got a mismatch: %s" , d )
3148
+ }
3149
+
3150
+ if len (reconciledRun .Status .TaskRuns ) != 2 {
3151
+ t .Errorf ("Expected PipelineRun status to include both TaskRun status items that can run immediately: %v" , reconciledRun .Status .TaskRuns )
3152
+ }
3153
+ }
0 commit comments