@@ -45,7 +45,7 @@ type CustomRunReconciler struct {
4545// generateBuildRun generates a BuildRun instance owned by the informed Tekton CustomRun object, the
4646// BuildRun name is randomly generated using the Run's name as base.
4747func (r * CustomRunReconciler ) generateBuildRun (
48- ctx context. Context ,
48+ logger logr. Logger ,
4949 customRun * tektonapibeta.CustomRun ,
5050) (* buildapi.BuildRun , error ) {
5151 br := buildapi.BuildRun {
@@ -64,6 +64,35 @@ func (r *CustomRunReconciler) generateBuildRun(
6464 Timeout : customRun .Spec .Timeout ,
6565 },
6666 }
67+
68+ for _ , workspaceBinding := range customRun .Spec .Workspaces {
69+ if workspaceBinding .Name == "shp-source" {
70+ br .Annotations = map [string ]string {
71+ "source-workspace" : "shp-source" ,
72+ }
73+
74+ // TODO use subPath as context directory
75+ } else {
76+ if workspaceBinding .SubPath != "" {
77+ // TODO should we fail ?
78+ logger .Info ("SubPath is ignored" , "namespace" , customRun .Namespace , "name" , customRun .Name , "workspace" , workspaceBinding .SubPath )
79+ }
80+
81+ br .Spec .Volumes = append (br .Spec .Volumes , buildapi.BuildVolume {
82+ Name : workspaceBinding .Name ,
83+ VolumeSource : corev1.VolumeSource {
84+ ConfigMap : workspaceBinding .ConfigMap ,
85+ CSI : workspaceBinding .CSI ,
86+ EmptyDir : workspaceBinding .EmptyDir ,
87+ PersistentVolumeClaim : workspaceBinding .PersistentVolumeClaim ,
88+ Projected : workspaceBinding .Projected ,
89+ Secret : workspaceBinding .Secret ,
90+ },
91+ })
92+ }
93+
94+ }
95+
6796 err := controllerutil .SetControllerReference (customRun , & br , r .Scheme )
6897 if err != nil {
6998 return nil , err
@@ -126,8 +155,8 @@ func (r *CustomRunReconciler) Reconcile(
126155) (ctrl.Result , error ) {
127156 logger := log .FromContext (ctx )
128157
129- var customRun tektonapibeta.CustomRun
130- err := r .Get (ctx , req .NamespacedName , & customRun )
158+ customRun := & tektonapibeta.CustomRun {}
159+ err := r .Get (ctx , req .NamespacedName , customRun )
131160 if err != nil {
132161 if ! errors .IsNotFound (err ) {
133162 logger .Error (err , "Unable to fetch Run" )
@@ -162,7 +191,7 @@ func (r *CustomRunReconciler) Reconcile(
162191 return Done ()
163192 }
164193
165- if br , err = r .generateBuildRun (ctx , & customRun ); err != nil {
194+ if br , err = r .generateBuildRun (logger , customRun ); err != nil {
166195 logger .V (0 ).Error (err , "Issuing BuildRun returned error" )
167196 return RequeueOnError (err )
168197 }
@@ -178,13 +207,13 @@ func (r *CustomRunReconciler) Reconcile(
178207 customRun .Status .StartTime = & now
179208
180209 // storing the ExtraFields on the Tekton Run instance status
181- if err = r .Client .Status ().Patch (ctx , & customRun , client .MergeFrom (originalCustomRun )); err != nil {
210+ if err = r .Client .Status ().Patch (ctx , customRun , client .MergeFrom (originalCustomRun )); err != nil {
182211 logger .V (0 ).Error (err , "trying to patch Tekton CustomRun status" )
183212 return RequeueOnError (err )
184213 }
185214 logger .V (0 ).Info ("Tekton CustomRun Status ExtraFields updated with BuildRun coordinates" )
186215
187- if err = r .Client . Create (ctx , br ); err != nil {
216+ if err = r .Create (ctx , br ); err != nil {
188217 logger .V (0 ).Error (err , "Trying to create a new BuildRun instance" )
189218 return RequeueOnError (err )
190219 }
@@ -194,7 +223,7 @@ func (r *CustomRunReconciler) Reconcile(
194223 logger .V (0 ).Info ("Retrieving BuildRun instance..." )
195224 // when the meta-information is populated, we need to extract the BuildRun name and retrieve
196225 // the object
197- if err = r .Client . Get (ctx , extraFields .GetNamespacedName (), br ); err != nil {
226+ if err = r .Get (ctx , extraFields .GetNamespacedName (), br ); err != nil {
198227 logger .V (0 ).Error (err , "Trying to retrieve BuildRun instance" )
199228 return RequeueOnError (err )
200229 }
@@ -204,16 +233,16 @@ func (r *CustomRunReconciler) Reconcile(
204233
205234 originalBr := br .DeepCopy ()
206235 br .Spec .State = buildapi .BuildRunRequestedStatePtr (buildapi .BuildRunStateCancel )
207- if err = r .Client . Patch (ctx , br , client .MergeFrom (originalBr )); err != nil {
236+ if err = r .Patch (ctx , br , client .MergeFrom (originalBr )); err != nil {
208237 logger .V (0 ).Error (err , "trying to patch BuildRun with cancellation state" )
209238 return RequeueOnError (err )
210239 }
211240 } else {
212241 // reflecting BuildRuns' status conditions on the Tekton Run owner instance
213- r .reflectBuildRunStatusOnTektonCustomRun (logger , & customRun , br )
242+ r .reflectBuildRunStatusOnTektonCustomRun (logger , customRun , br )
214243
215244 logger .V (0 ).Info ("Updating Tekton CustomRun instance status..." )
216- if err = r .Client .Status ().Patch (ctx , & customRun , client .MergeFrom (originalCustomRun )); err != nil {
245+ if err = r .Client .Status ().Patch (ctx , customRun , client .MergeFrom (originalCustomRun )); err != nil {
217246 logger .V (0 ).Error (err , "trying to patch Tekton CustomRun status" )
218247 return RequeueOnError (err )
219248 }
0 commit comments