@@ -27,6 +27,7 @@ import (
27
27
kfptaskClient "github.com/kubeflow/kfp-tekton/tekton-catalog/tekton-kfptask/pkg/client/clientset/versioned"
28
28
kfptaskListers "github.com/kubeflow/kfp-tekton/tekton-catalog/tekton-kfptask/pkg/client/listers/kfptask/v1alpha1"
29
29
"github.com/kubeflow/kfp-tekton/tekton-catalog/tekton-kfptask/pkg/common"
30
+ "github.com/kubeflow/pipelines/kubernetes_platform/go/kubernetesplatform"
30
31
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
31
32
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
32
33
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
@@ -135,13 +136,13 @@ var annotationToDrop = map[string]string{
135
136
}
136
137
137
138
// transite to next state based on current state
138
- func (kts * kfptaskFS ) next (executionID string , executorInput string , podSpecPatch string ) error {
139
+ func (kts * kfptaskFS ) next (executionID string , executorInput string , podSpecPatch string , executorConfig * kubernetesplatform. KubernetesExecutorConfig ) error {
139
140
kts .logger .Infof ("kts state is %s" , kts .state )
140
141
switch kts .state {
141
142
case StateInit :
142
143
// create the corresponding TaskRun CRD and start the task
143
144
// compose TaskRun
144
- tr , err := kts .constructTaskRun (executionID , executorInput , podSpecPatch )
145
+ tr , err := kts .constructTaskRun (executionID , executorInput , podSpecPatch , executorConfig )
145
146
if err != nil {
146
147
kts .logger .Infof ("Failed to construct a TaskRun:%v" , err )
147
148
kts .run .Status .MarkCustomRunFailed (kfptaskv1alpha1 .KfpTaskRunReasonInternalError .String (), "Failed to construct a TaskRun: %v" , err )
@@ -196,7 +197,47 @@ func (kts *kfptaskFS) next(executionID string, executorInput string, podSpecPatc
196
197
return nil
197
198
}
198
199
199
- func (kts * kfptaskFS ) constructTaskRun (executionID string , executorInput string , podSpecPatch string ) (* tektonv1.TaskRun , error ) {
200
+ // Extends the PodMetadata to include Kubernetes-specific executor config.
201
+ // Although the current podMetadata object is always empty, this function
202
+ // doesn't overwrite the existing podMetadata because for security reasons
203
+ // the existing podMetadata should have higher privilege than the user definition.
204
+ func extendPodMetadata (
205
+ podMetadata * metav1.ObjectMeta ,
206
+ kubernetesExecutorConfig * kubernetesplatform.KubernetesExecutorConfig ,
207
+ ) {
208
+ // Get pod metadata information
209
+ if kubernetesExecutorConfig .GetPodMetadata () != nil {
210
+ if kubernetesExecutorConfig .GetPodMetadata ().GetLabels () != nil {
211
+ if podMetadata .Labels == nil {
212
+ podMetadata .Labels = kubernetesExecutorConfig .GetPodMetadata ().GetLabels ()
213
+ } else {
214
+ podMetadata .Labels = extendMetadataMap (podMetadata .Labels , kubernetesExecutorConfig .GetPodMetadata ().GetLabels ())
215
+ }
216
+ }
217
+ if kubernetesExecutorConfig .GetPodMetadata ().GetAnnotations () != nil {
218
+ if podMetadata .Annotations == nil {
219
+ podMetadata .Annotations = kubernetesExecutorConfig .GetPodMetadata ().GetAnnotations ()
220
+ } else {
221
+ podMetadata .Annotations = extendMetadataMap (podMetadata .Annotations , kubernetesExecutorConfig .GetPodMetadata ().GetAnnotations ())
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ // Extends metadata map values, highPriorityMap should overwrites lowPriorityMap values
228
+ // The original Map inputs should have higher priority since its defined by admin
229
+ // TODO: Use maps.Copy after moving to go 1.21+
230
+ func extendMetadataMap (
231
+ highPriorityMap map [string ]string ,
232
+ lowPriorityMap map [string ]string ,
233
+ ) map [string ]string {
234
+ for k , v := range highPriorityMap {
235
+ lowPriorityMap [k ] = v
236
+ }
237
+ return lowPriorityMap
238
+ }
239
+
240
+ func (kts * kfptaskFS ) constructTaskRun (executionID string , executorInput string , podSpecPatch string , executorConfig * kubernetesplatform.KubernetesExecutorConfig ) (* tektonv1.TaskRun , error ) {
200
241
ktSpec , err := kts .reconciler .getKfpTaskSpec (kts .ctx , kts .run )
201
242
if err != nil {
202
243
return nil , err
@@ -235,6 +276,10 @@ func (kts *kfptaskFS) constructTaskRun(executionID string, executorInput string,
235
276
},
236
277
}
237
278
279
+ if executorConfig != nil {
280
+ extendPodMetadata (& tr .ObjectMeta , executorConfig )
281
+ }
282
+
238
283
if podSpecPatch != "" {
239
284
podSpec , err := parseTaskSpecPatch (podSpecPatch )
240
285
if err != nil {
@@ -312,7 +357,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, run *tektonv1beta1.Custo
312
357
return nil
313
358
}
314
359
if ktstate .isRunning () {
315
- return ktstate .next ("" , "" , "" )
360
+ return ktstate .next ("" , "" , "" , nil )
316
361
}
317
362
options , err := common .ParseParams (run )
318
363
if err != nil {
@@ -321,6 +366,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, run *tektonv1beta1.Custo
321
366
"Run can't be run because it has an invalid param - %v" , err )
322
367
return nil
323
368
}
369
+ executorConfig := common .GetKubernetesExecutorConfig (options )
324
370
325
371
runResults , runTask , executionID , executorInput , podSpecPatch , driverErr := common .ExecDriver (ctx , options )
326
372
if driverErr != nil {
@@ -341,7 +387,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, run *tektonv1beta1.Custo
341
387
return nil
342
388
}
343
389
344
- return ktstate .next (executionID , executorInput , podSpecPatch )
390
+ return ktstate .next (executionID , executorInput , podSpecPatch , executorConfig )
345
391
}
346
392
347
393
func (r * Reconciler ) FinalizeKind (ctx context.Context , run * tektonv1beta1.CustomRun ) reconciler.Event {
0 commit comments