forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.go
641 lines (560 loc) · 20.3 KB
/
pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
/*
Copyright 2019 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package builder
import (
"time"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
// PipelineOp is an operation which modify a Pipeline struct.
type PipelineOp func(*v1alpha1.Pipeline)
// PipelineSpecOp is an operation which modify a PipelineSpec struct.
type PipelineSpecOp func(*v1alpha1.PipelineSpec)
// PipelineTaskOp is an operation which modify a PipelineTask struct.
type PipelineTaskOp func(*v1alpha1.PipelineTask)
// PipelineRunOp is an operation which modify a PipelineRun struct.
type PipelineRunOp func(*v1alpha1.PipelineRun)
// PipelineRunSpecOp is an operation which modify a PipelineRunSpec struct.
type PipelineRunSpecOp func(*v1alpha1.PipelineRunSpec)
// PipelineResourceOp is an operation which modify a PipelineResource struct.
type PipelineResourceOp func(*v1alpha1.PipelineResource)
// PipelineResourceBindingOp is an operation which modify a PipelineResourceBinding struct.
type PipelineResourceBindingOp func(*v1alpha1.PipelineResourceBinding)
// PipelineResourceSpecOp is an operation which modify a PipelineResourceSpec struct.
type PipelineResourceSpecOp func(*v1alpha1.PipelineResourceSpec)
// PipelineTaskInputResourceOp is an operation which modifies a PipelineTaskInputResource.
type PipelineTaskInputResourceOp func(*v1alpha1.PipelineTaskInputResource)
// PipelineRunStatusOp is an operation which modifies a PipelineRunStatus
type PipelineRunStatusOp func(*v1alpha1.PipelineRunStatus)
// PipelineTaskConditionOp is an operation which modifies a PipelineTaskCondition
type PipelineTaskConditionOp func(condition *v1alpha1.PipelineTaskCondition)
// Pipeline creates a Pipeline with default values.
// Any number of Pipeline modifier can be passed to transform it.
func Pipeline(name string, ops ...PipelineOp) *v1alpha1.Pipeline {
p := &v1alpha1.Pipeline{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
for _, op := range ops {
op(p)
}
return p
}
// PipelineNamespace sets the namespace on the Pipeline
func PipelineNamespace(namespace string) PipelineOp {
return func(t *v1alpha1.Pipeline) {
t.ObjectMeta.Namespace = namespace
}
}
// PipelineSpec sets the PipelineSpec to the Pipeline.
// Any number of PipelineSpec modifier can be passed to transform it.
func PipelineSpec(ops ...PipelineSpecOp) PipelineOp {
return func(p *v1alpha1.Pipeline) {
ps := &p.Spec
for _, op := range ops {
op(ps)
}
p.Spec = *ps
}
}
// PipelineCreationTimestamp sets the creation time of the pipeline
func PipelineCreationTimestamp(t time.Time) PipelineOp {
return func(p *v1alpha1.Pipeline) {
p.CreationTimestamp = metav1.Time{Time: t}
}
}
// PipelineDescription sets the description of the pipeline
func PipelineDescription(desc string) PipelineSpecOp {
return func(ps *v1alpha1.PipelineSpec) {
ps.Description = desc
}
}
// PipelineRunCancelled sets the status to cancel to the TaskRunSpec.
func PipelineRunCancelled(spec *v1alpha1.PipelineRunSpec) {
spec.Status = v1alpha1.PipelineRunSpecStatusCancelled
}
// PipelineDeclaredResource adds a resource declaration to the Pipeline Spec,
// with the specified name and type.
func PipelineDeclaredResource(name string, t v1alpha1.PipelineResourceType) PipelineSpecOp {
return func(ps *v1alpha1.PipelineSpec) {
r := v1alpha1.PipelineDeclaredResource{
Name: name,
Type: t,
}
ps.Resources = append(ps.Resources, r)
}
}
// PipelineParamSpec adds a param, with specified name and type, to the PipelineSpec.
// Any number of PipelineParamSpec modifiers can be passed to transform it.
func PipelineParamSpec(name string, pt v1alpha1.ParamType, ops ...ParamSpecOp) PipelineSpecOp {
return func(ps *v1alpha1.PipelineSpec) {
pp := &v1alpha1.ParamSpec{Name: name, Type: pt}
for _, op := range ops {
op(pp)
}
ps.Params = append(ps.Params, *pp)
}
}
// PipelineTask adds a PipelineTask, with specified name and task name, to the PipelineSpec.
// Any number of PipelineTask modifier can be passed to transform it.
func PipelineTask(name, taskName string, ops ...PipelineTaskOp) PipelineSpecOp {
return func(ps *v1alpha1.PipelineSpec) {
pTask := &v1alpha1.PipelineTask{
Name: name,
}
if taskName != "" {
pTask.TaskRef = &v1alpha1.TaskRef{
Name: taskName,
}
}
for _, op := range ops {
op(pTask)
}
ps.Tasks = append(ps.Tasks, *pTask)
}
}
// PipelineResult adds a PipelineResult, with specified name, value and description, to the PipelineSpec.
func PipelineResult(name, value, description string) PipelineSpecOp {
return func(ps *v1alpha1.PipelineSpec) {
pResult := &v1beta1.PipelineResult{
Name: name,
Value: value,
Description: description,
}
ps.Results = append(ps.Results, *pResult)
}
}
// PipelineRunResult adds a PipelineResultStatus, with specified name, value and description, to the PipelineRunStatusSpec.
func PipelineRunResult(name, value string) PipelineRunStatusOp {
return func(s *v1alpha1.PipelineRunStatus) {
pResult := &v1beta1.PipelineRunResult{
Name: name,
Value: value,
}
s.PipelineResults = append(s.PipelineResults, *pResult)
}
}
// PipelineTaskSpec sets the TaskSpec on a PipelineTask.
func PipelineTaskSpec(spec *v1alpha1.TaskSpec) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
pt.TaskSpec = spec
}
}
// Retries sets the number of retries on a PipelineTask.
func Retries(retries int) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
pt.Retries = retries
}
}
// RunAfter will update the provided Pipeline Task to indicate that it
// should be run after the provided list of Pipeline Task names.
func RunAfter(tasks ...string) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
pt.RunAfter = tasks
}
}
// PipelineTaskRefKind sets the TaskKind to the PipelineTaskRef.
func PipelineTaskRefKind(kind v1alpha1.TaskKind) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
pt.TaskRef.Kind = kind
}
}
// PipelineTaskParam adds a ResourceParam, with specified name and value, to the PipelineTask.
func PipelineTaskParam(name string, value string, additionalValues ...string) PipelineTaskOp {
arrayOrString := arrayOrString(value, additionalValues...)
return func(pt *v1alpha1.PipelineTask) {
pt.Params = append(pt.Params, v1alpha1.Param{
Name: name,
Value: *arrayOrString,
})
}
}
// From will update the provided PipelineTaskInputResource to indicate that it
// should come from tasks.
func From(tasks ...string) PipelineTaskInputResourceOp {
return func(r *v1alpha1.PipelineTaskInputResource) {
r.From = tasks
}
}
// PipelineTaskInputResource adds an input resource to the PipelineTask with the specified
// name, pointing at the declared resource.
// Any number of PipelineTaskInputResource modifies can be passed to transform it.
func PipelineTaskInputResource(name, resource string, ops ...PipelineTaskInputResourceOp) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
r := v1alpha1.PipelineTaskInputResource{
Name: name,
Resource: resource,
}
for _, op := range ops {
op(&r)
}
if pt.Resources == nil {
pt.Resources = &v1alpha1.PipelineTaskResources{}
}
pt.Resources.Inputs = append(pt.Resources.Inputs, r)
}
}
// PipelineTaskOutputResource adds an output resource to the PipelineTask with the specified
// name, pointing at the declared resource.
func PipelineTaskOutputResource(name, resource string) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
r := v1alpha1.PipelineTaskOutputResource{
Name: name,
Resource: resource,
}
if pt.Resources == nil {
pt.Resources = &v1alpha1.PipelineTaskResources{}
}
pt.Resources.Outputs = append(pt.Resources.Outputs, r)
}
}
// PipelineTaskCondition adds a condition to the PipelineTask with the
// specified conditionRef. Any number of PipelineTaskCondition modifiers can be passed
// to transform it
func PipelineTaskCondition(conditionRef string, ops ...PipelineTaskConditionOp) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
c := &v1alpha1.PipelineTaskCondition{
ConditionRef: conditionRef,
}
for _, op := range ops {
op(c)
}
pt.Conditions = append(pt.Conditions, *c)
}
}
// PipelineTaskConditionParam adds a parameter to a PipelineTaskCondition
func PipelineTaskConditionParam(name, val string) PipelineTaskConditionOp {
return func(condition *v1alpha1.PipelineTaskCondition) {
if condition.Params == nil {
condition.Params = []v1alpha1.Param{}
}
condition.Params = append(condition.Params, v1alpha1.Param{
Name: name,
Value: *arrayOrString(val),
})
}
}
// PipelineTaskConditionResource adds a resource to a PipelineTaskCondition
func PipelineTaskConditionResource(name, resource string, from ...string) PipelineTaskConditionOp {
return func(condition *v1alpha1.PipelineTaskCondition) {
if condition.Resources == nil {
condition.Resources = []v1alpha1.PipelineTaskInputResource{}
}
condition.Resources = append(condition.Resources, v1alpha1.PipelineTaskInputResource{
Name: name,
Resource: resource,
From: from,
})
}
}
// PipelineTaskWorkspaceBinding adds a workspace with the specified name, workspace and subpath on a PipelineTask.
func PipelineTaskWorkspaceBinding(name, workspace, subPath string) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
pt.Workspaces = append(pt.Workspaces, v1alpha1.WorkspacePipelineTaskBinding{
Name: name,
Workspace: workspace,
SubPath: subPath,
})
}
}
// PipelineTaskTimeout sets the timeout for the PipelineTask.
func PipelineTaskTimeout(duration time.Duration) PipelineTaskOp {
return func(pt *v1alpha1.PipelineTask) {
pt.Timeout = &metav1.Duration{Duration: duration}
}
}
// PipelineRun creates a PipelineRun with default values.
// Any number of PipelineRun modifier can be passed to transform it.
func PipelineRun(name string, ops ...PipelineRunOp) *v1alpha1.PipelineRun {
pr := &v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1alpha1.PipelineRunSpec{},
}
for _, op := range ops {
op(pr)
}
return pr
}
// PipelineRunNamespace sets the namespace on a PipelineRun.
func PipelineRunNamespace(namespace string) PipelineRunOp {
return func(t *v1alpha1.PipelineRun) {
t.ObjectMeta.Namespace = namespace
}
}
// PipelineRunSpec sets the PipelineRunSpec, references Pipeline with specified name, to the PipelineRun.
// Any number of PipelineRunSpec modifier can be passed to transform it.
func PipelineRunSpec(name string, ops ...PipelineRunSpecOp) PipelineRunOp {
return func(pr *v1alpha1.PipelineRun) {
prs := &pr.Spec
prs.PipelineRef = &v1alpha1.PipelineRef{
Name: name,
}
// Set a default timeout
prs.Timeout = &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute}
for _, op := range ops {
op(prs)
}
pr.Spec = *prs
}
}
// PipelineRunLabel adds a label to the PipelineRun.
func PipelineRunLabel(key, value string) PipelineRunOp {
return func(pr *v1alpha1.PipelineRun) {
if pr.ObjectMeta.Labels == nil {
pr.ObjectMeta.Labels = map[string]string{}
}
pr.ObjectMeta.Labels[key] = value
}
}
// PipelineRunAnnotation adds a annotation to the PipelineRun.
func PipelineRunAnnotation(key, value string) PipelineRunOp {
return func(pr *v1alpha1.PipelineRun) {
if pr.ObjectMeta.Annotations == nil {
pr.ObjectMeta.Annotations = map[string]string{}
}
pr.ObjectMeta.Annotations[key] = value
}
}
// PipelineRunResourceBinding adds bindings from actual instances to a Pipeline's declared resources.
func PipelineRunResourceBinding(name string, ops ...PipelineResourceBindingOp) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
r := &v1alpha1.PipelineResourceBinding{
Name: name,
}
for _, op := range ops {
op(r)
}
prs.Resources = append(prs.Resources, *r)
}
}
// PipelineResourceBindingRef set the ResourceRef name to the Resource called Name.
func PipelineResourceBindingRef(name string) PipelineResourceBindingOp {
return func(b *v1alpha1.PipelineResourceBinding) {
b.ResourceRef = &v1alpha1.PipelineResourceRef{
Name: name,
}
}
}
// PipelineResourceBindingResourceSpec set the PipelineResourceResourceSpec to the PipelineResourceBinding.
func PipelineResourceBindingResourceSpec(spec *v1alpha1.PipelineResourceSpec) PipelineResourceBindingOp {
return func(b *v1alpha1.PipelineResourceBinding) {
b.ResourceSpec = spec
}
}
// PipelineRunServiceAccountName sets the service account to the PipelineRunSpec.
func PipelineRunServiceAccountName(sa string) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
prs.ServiceAccountName = sa
}
}
// PipelineRunServiceAccountNameTask configures the service account for given Task in PipelineRun.
func PipelineRunServiceAccountNameTask(taskName, sa string) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
prs.ServiceAccountNames = append(prs.ServiceAccountNames, v1alpha1.PipelineRunSpecServiceAccountName{
TaskName: taskName,
ServiceAccountName: sa,
})
}
}
// PipelineRunParam add a param, with specified name and value, to the PipelineRunSpec.
func PipelineRunParam(name string, value string, additionalValues ...string) PipelineRunSpecOp {
arrayOrString := arrayOrString(value, additionalValues...)
return func(prs *v1alpha1.PipelineRunSpec) {
prs.Params = append(prs.Params, v1alpha1.Param{
Name: name,
Value: *arrayOrString,
})
}
}
// PipelineRunTimeout sets the timeout to the PipelineRunSpec.
func PipelineRunTimeout(duration time.Duration) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
prs.Timeout = &metav1.Duration{Duration: duration}
}
}
// PipelineRunNilTimeout sets the timeout to nil on the PipelineRunSpec
func PipelineRunNilTimeout(prs *v1alpha1.PipelineRunSpec) {
prs.Timeout = nil
}
// PipelineRunNodeSelector sets the Node selector to the PipelineRunSpec.
func PipelineRunNodeSelector(values map[string]string) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
if prs.PodTemplate == nil {
prs.PodTemplate = &v1alpha1.PodTemplate{}
}
prs.PodTemplate.NodeSelector = values
}
}
// PipelineRunTolerations sets the Node selector to the PipelineRunSpec.
func PipelineRunTolerations(values []corev1.Toleration) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
if prs.PodTemplate == nil {
prs.PodTemplate = &v1alpha1.PodTemplate{}
}
prs.PodTemplate.Tolerations = values
}
}
// PipelineRunAffinity sets the affinity to the PipelineRunSpec.
func PipelineRunAffinity(affinity *corev1.Affinity) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
if prs.PodTemplate == nil {
prs.PodTemplate = &v1alpha1.PodTemplate{}
}
prs.PodTemplate.Affinity = affinity
}
}
// PipelineRunPipelineSpec adds a PipelineSpec to the PipelineRunSpec.
// Any number of PipelineSpec modifiers can be passed to transform it.
func PipelineRunPipelineSpec(ops ...PipelineSpecOp) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
ps := &v1alpha1.PipelineSpec{}
prs.PipelineRef = nil
for _, op := range ops {
op(ps)
}
prs.PipelineSpec = ps
}
}
// PipelineRunStatus sets the PipelineRunStatus to the PipelineRun.
// Any number of PipelineRunStatus modifier can be passed to transform it.
func PipelineRunStatus(ops ...PipelineRunStatusOp) PipelineRunOp {
return func(pr *v1alpha1.PipelineRun) {
s := &v1alpha1.PipelineRunStatus{}
for _, op := range ops {
op(s)
}
pr.Status = *s
}
}
// PipelineRunStatusCondition adds a StatusCondition to the TaskRunStatus.
func PipelineRunStatusCondition(condition apis.Condition) PipelineRunStatusOp {
return func(s *v1alpha1.PipelineRunStatus) {
s.Conditions = append(s.Conditions, condition)
}
}
// PipelineRunStartTime sets the start time to the PipelineRunStatus.
func PipelineRunStartTime(startTime time.Time) PipelineRunStatusOp {
return func(s *v1alpha1.PipelineRunStatus) {
s.StartTime = &metav1.Time{Time: startTime}
}
}
// PipelineRunCompletionTime sets the completion time to the PipelineRunStatus.
func PipelineRunCompletionTime(t time.Time) PipelineRunStatusOp {
return func(s *v1alpha1.PipelineRunStatus) {
s.CompletionTime = &metav1.Time{Time: t}
}
}
// PipelineRunTaskRunsStatus sets the status of TaskRun to the PipelineRunStatus.
func PipelineRunTaskRunsStatus(taskRunName string, status *v1alpha1.PipelineRunTaskRunStatus) PipelineRunStatusOp {
return func(s *v1alpha1.PipelineRunStatus) {
if s.TaskRuns == nil {
s.TaskRuns = make(map[string]*v1alpha1.PipelineRunTaskRunStatus)
}
s.TaskRuns[taskRunName] = status
}
}
// PipelineResource creates a PipelineResource with default values.
// Any number of PipelineResource modifier can be passed to transform it.
func PipelineResource(name string, ops ...PipelineResourceOp) *v1alpha1.PipelineResource {
resource := &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
for _, op := range ops {
op(resource)
}
return resource
}
// PipelineResourceNamespace sets the namespace on a PipelineResource.
func PipelineResourceNamespace(namespace string) PipelineResourceOp {
return func(t *v1alpha1.PipelineResource) {
t.ObjectMeta.Namespace = namespace
}
}
// PipelineResourceSpec set the PipelineResourceSpec, with specified type, to the PipelineResource.
// Any number of PipelineResourceSpec modifier can be passed to transform it.
func PipelineResourceSpec(resourceType v1alpha1.PipelineResourceType, ops ...PipelineResourceSpecOp) PipelineResourceOp {
return func(r *v1alpha1.PipelineResource) {
spec := &r.Spec
spec.Type = resourceType
for _, op := range ops {
op(spec)
}
r.Spec = *spec
}
}
// PipelineResourceDescription sets the description of the pipeline resource
func PipelineResourceDescription(desc string) PipelineResourceSpecOp {
return func(spec *v1alpha1.PipelineResourceSpec) {
spec.Description = desc
}
}
// PipelineResourceSpecParam adds a ResourceParam, with specified name and value, to the PipelineResourceSpec.
func PipelineResourceSpecParam(name, value string) PipelineResourceSpecOp {
return func(spec *v1alpha1.PipelineResourceSpec) {
spec.Params = append(spec.Params, v1alpha1.ResourceParam{
Name: name,
Value: value,
})
}
}
// PipelineResourceSpecSecretParam adds a SecretParam, with specified fieldname, secretKey and secretName, to the PipelineResourceSpec.
func PipelineResourceSpecSecretParam(fieldname, secretName, secretKey string) PipelineResourceSpecOp {
return func(spec *v1alpha1.PipelineResourceSpec) {
spec.SecretParams = append(spec.SecretParams, v1alpha1.SecretParam{
FieldName: fieldname,
SecretKey: secretKey,
SecretName: secretName,
})
}
}
// PipelineWorkspaceDeclaration adds a Workspace to the workspaces listed in the pipeline spec.
func PipelineWorkspaceDeclaration(names ...string) PipelineSpecOp {
return func(spec *v1alpha1.PipelineSpec) {
for _, name := range names {
spec.Workspaces = append(spec.Workspaces, v1alpha1.PipelineWorkspaceDeclaration{Name: name})
}
}
}
// PipelineRunWorkspaceBindingEmptyDir adds an EmptyDir Workspace to the workspaces of a pipelinerun spec.
func PipelineRunWorkspaceBindingEmptyDir(name string) PipelineRunSpecOp {
return func(spec *v1alpha1.PipelineRunSpec) {
spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{
Name: name,
EmptyDir: &corev1.EmptyDirVolumeSource{},
})
}
}
// PipelineRunWorkspaceBindingVolumeClaimTemplate adds an VolumeClaimTemplate Workspace to the workspaces of a pipelineRun spec.
func PipelineRunWorkspaceBindingVolumeClaimTemplate(name string, claimName string, subPath string) PipelineRunSpecOp {
return func(spec *v1alpha1.PipelineRunSpec) {
spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{
Name: name,
SubPath: subPath,
VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: claimName,
},
Spec: corev1.PersistentVolumeClaimSpec{},
},
})
}
}