-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conversion_test.go
1042 lines (969 loc) · 31.5 KB
/
conversion_test.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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//go:build e2e
// +build e2e
/*
Copyright 2022 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 test
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/tektoncd/pipeline/pkg/apis/config"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/parse"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
knativetest "knative.dev/pkg/test"
"knative.dev/pkg/test/helpers"
)
var (
ReleaseAnnotation = "pipeline.tekton.dev/release"
TaskRunsAnnotationKey = "tekton.dev/v1beta1TaskRuns"
RunsAnnotationKey = "tekton.dev/v1beta1Runs"
// embedded-status is required for testing pipelineRunStatus
fullEmbeddedGate = map[string]string{
"embedded-status": "full",
}
// json value in the Annotation map is ignored due to incomparable generated fields
ignoreJSONAnnotationValue = func(k, v interface{}) bool {
return k == TaskRunsAnnotationKey || k == RunsAnnotationKey
}
// release Annotation is ignored when populated by TaskRuns
ignoreReleaseAnnotation = func(k string, v string) bool {
return k == ReleaseAnnotation
}
filterLabels = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Labels")
filterPodGenreatedName = cmpopts.IgnoreFields(v1beta1.TaskRunStatusFields{}, "PodName")
filterV1TaskRunStatus = cmpopts.IgnoreFields(v1.TaskRunStatusFields{}, "StartTime", "CompletionTime")
filterV1PipelineRunStatus = cmpopts.IgnoreFields(v1.PipelineRunStatusFields{}, "StartTime", "CompletionTime")
filterV1beta1TaskRunStatus = cmpopts.IgnoreFields(v1beta1.TaskRunStatusFields{}, "StartTime", "CompletionTime")
filterV1beta1PipelineRunStatus = cmpopts.IgnoreFields(v1beta1.PipelineRunStatusFields{}, "StartTime", "CompletionTime")
filterContainerStateTerminated = cmpopts.IgnoreFields(corev1.ContainerStateTerminated{}, "StartedAt", "FinishedAt", "ContainerID", "Message")
filterV1StepState = cmpopts.IgnoreFields(v1.StepState{}, "Name", "ImageID", "Container")
filterV1beta1StepState = cmpopts.IgnoreFields(v1beta1.StepState{}, "Name", "ImageID", "ContainerName")
filterJSONAnnotationsStrings = cmpopts.IgnoreMapEntries(ignoreJSONAnnotationValue)
filterReleaseAnnotation = cmpopts.IgnoreMapEntries(ignoreReleaseAnnotation)
filterMetadata = []cmp.Option{filterTypeMeta, filterObjectMeta}
filterV1TaskRunFields = []cmp.Option{filterTypeMeta, filterObjectMeta, filterLabels, filterCondition, filterReleaseAnnotation, filterV1TaskRunStatus, filterContainerStateTerminated, filterV1StepState}
filterV1beta1TaskRunFields = []cmp.Option{filterTypeMeta, filterObjectMeta, filterLabels, filterV1beta1TaskRunStatus, filterCondition, filterReleaseAnnotation, filterContainerStateTerminated, filterV1beta1StepState}
filterV1PipelineRunFields = []cmp.Option{filterTypeMeta, filterObjectMeta, filterLabels, filterCondition, filterV1PipelineRunStatus, filterJSONAnnotationsStrings}
filterV1beta1PipelineRunFields = []cmp.Option{filterTypeMeta, filterObjectMeta, filterLabels, filterCondition, filterV1beta1PipelineRunStatus, filterV1beta1TaskRunStatus, filterV1beta1StepState, filterContainerStateTerminated}
filterTaskRunStatusAnnotationsFields = []cmp.Option{filterV1beta1TaskRunStatus, filterCondition, filterContainerStateTerminated, filterV1beta1StepState, filterPodGenreatedName}
v1beta1TaskYaml = `
metadata:
name: %s
namespace: %s
spec:
steps:
- name: step
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
command: ['/bin/bash']
args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key']
workingDir: /dir
env:
- name: MY_VAR1
value: foo
resources:
inputs:
- name: workspace
resource: source-repo
outputs:
- name: workspace
resource: source-repo
volumeMounts:
- name: messages
mountPath: /messages
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 2000
timeout: 60s
secret:
secretName: test-ssh-credentials
onError: continue
stepTemplate:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
command: ['/bin/bash']
env:
- name: QUX
value: original
args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key']
workingDir: /dir
env:
- name: MY_VAR1
value: foo
resources:
inputs:
- name: workspaces
resource: source-repo
outputs:
- name: workspace
resource: source-repo
volumeMounts:
- name: messages
mountPath: /messages
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 2000
sidecars:
- name: server
image: alpine/git:v2.26.2
command: ['/bin/bash']
args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key']
workingDir: /dir
env:
- name: MY_VAR1
value: foo
resources:
inputs:
- name: workspace
resource: source-repo
outputs:
- name: workspace
resource: source-repo
volumeMounts:
- name: messages
mountPath: /messages
readinessProbe:
periodSeconds: 1
securityContext:
runAsUser: 0
volumeMounts:
- name: messages
mountPath: /messages
script: echo test
volumes:
- name: messages
emptyDir: {}
params:
- name: PARAM
description: param des
type: string
default: "1"
workspaces:
- name: workspace
description: description
mountPath: /foo
readOnly: true
optional: true
resources:
inputs:
- name: git-repo
type: git
description: "The input is code from a git repository"
optional: true
outputs:
- name: optionalimage
type: image
description: "The output is a Docker image"
optional: true
`
v1TaskYaml = `
metadata:
name: %s
namespace: %s
annotations: {
tekton.dev/v1beta1Resources: '{"inputs":[{"name":"git-repo","type":"git","description":"The input is code from a git repository","optional":true}],"outputs":[{"name":"optionalimage","type":"image","description":"The output is a Docker image","optional":true}]}'
}
spec:
steps:
- name: step
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
command: ['/bin/bash']
args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key']
workingDir: /dir
env:
- name: MY_VAR1
value: foo
resources:
inputs:
- name: workspace
resource: source-repo
outputs:
- name: workspace
resource: source-repo
volumeMounts:
- name: messages
mountPath: /messages
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 2000
timeout: 60s
secret:
secretName: test-ssh-credentials
onError: continue
stepTemplate:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
command: ['/bin/bash']
env:
- name: QUX
value: original
args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key']
workingDir: /dir
env:
- name: MY_VAR1
value: foo
volumeMounts:
- name: messages
mountPath: /messages
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 2000
sidecars:
- name: server
image: alpine/git:v2.26.2
command: ['/bin/bash']
args: ['-c', 'gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key']
workingDir: /dir
env:
- name: MY_VAR1
value: foo
resources:
inputs:
- name: workspace
resource: source-repo
outputs:
- name: workspace
resource: source-repo
readinessProbe:
periodSeconds: 1
volumeMounts:
- name: messages
mountPath: /messages
securityContext:
runAsUser: 0
script: echo test
volumes:
- name: messages
emptyDir: {}
params:
- name: PARAM
description: param des
type: string
default: "1"
workspaces:
- name: workspace
description: description
mountPath: /foo
readOnly: true
optional: true
`
v1beta1PipelineYaml = `
metadata:
name: %s
namespace: %s
spec:
description: foo
tasks:
- name: generate-result
taskRef:
kind: Task
name: generate-result
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
timeouts:
pipeline: 1h30m
tasks: 1h15m
taskSpec:
params:
- name: task1-result
value: task1-val
steps:
- image: alpine
onError: continue
name: exit-with-255
script: |
exit 255
timeout: 60s
podTemplate:
securityContext:
fsGroup: 65532
workspaces:
- name: password-vault
finally:
- name: echo-status
params:
- name: echoStatus
value: "status"
taskSpec:
params:
- name: echoStatus
type: string
steps:
- name: verify-status
image: ubuntu
script: |
if [ $(params.echoStatus) == "Succeeded" ]
then
echo " Good night! echoed successfully"
fi
resources:
- name: source-repo
type: git
`
v1PipelineYaml = `
metadata:
name: %s
namespace: %s
annotations: {
tekton.dev/v1beta1Resources: '[{"name":"source-repo","type":"git"}]'
}
spec:
description: foo
tasks:
- name: generate-result
taskRef:
kind: Task
name: generate-result
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
timeouts:
pipeline: 1h30m
tasks: 1h15m
taskSpec:
params:
- name: task1-result
value: task1-val
steps:
- image: alpine
onError: continue
name: exit-with-255
script: |
exit 255
timeout: 60s
podTemplate:
securityContext:
fsGroup: 65532
workspaces:
- name: password-vault
finally:
- name: echo-status
params:
- name: echoStatus
value: "status"
taskSpec:
params:
- name: echoStatus
type: string
steps:
- name: verify-status
image: ubuntu
script: |
if [ $(params.echoStatus) == "Succeeded" ]
then
echo " Good night! echoed successfully"
fi
`
v1beta1TaskRunYaml = `
metadata:
name: %s
namespace: %s
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
taskSpec:
resources:
inputs:
- name: skaffold
type: git
outputs:
- name: skaffoldout
type: git
steps:
- name: echo
image: ubuntu
script: |
#!/usr/bin/env bash
echo "Hello World!"
workspaces:
- name: output
timeout: 20s
workspaces:
- name: output
emptyDir: {}
podTemplate:
securityContext:
fsGroup: 65532
resources:
inputs:
- name: skaffold
resourceSpec:
type: git
params:
- name: revision
value: v0.32.0
- name: url
value: https://github.com/GoogleContainerTools/skaffold
outputs:
- name: skaffoldout
resourceSpec:
type: git
params:
- name: revision
value: v0.32.0
- name: url
value: https://github.com/GoogleContainerTools/skaffold
`
v1beta1TaskRunExpectedYaml = `
metadata:
name: %s
namespace: %s
annotations: {}
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
timeout: 60s
podTemplate:
securityContext:
fsGroup: 65532
taskSpec:
steps:
- computeResources: {}
image: ubuntu
name: echo
script: |
#!/usr/bin/env bash
echo "Hello World!"
workspaces:
- name: output
workspaces:
- emptyDir: {}
name: output
status:
conditions:
- reason: Succeeded
status: "True"
type: Succeeded
podName: %s-pod
taskSpec:
steps:
- computeResources: {}
image: ubuntu
name: echo
script: |
#!/usr/bin/env bash
echo "Hello World!"
workspaces:
- name: output
workspaces:
- name: output
steps:
- container: echo
name: echo
terminated:
reason: Completed
`
v1TaskRunYaml = `
metadata:
name: %s
namespace: %s
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
timeout: 60s
podTemplate:
securityContext:
fsGroup: 65532
workspaces:
- emptyDir: {}
name: output
taskSpec:
steps:
- computeResources: {}
image: ubuntu
name: echo
script: |
#!/usr/bin/env bash
echo "Hello World!"
workspaces:
- name: output
`
v1TaskRunExpectedYaml = `
metadata:
name: %s
namespace: %s
annotations: {
tekton.dev/v1beta1Resources: '{"inputs":[{"name":"skaffold","resourceSpec":{"type":"git","params":[{"name":"revision","value":"v0.32.0"},{"name":"url","value":"https://github.com/GoogleContainerTools/skaffold"}]}}],"outputs":[{"name":"skaffoldout","resourceSpec":{"type":"git","params":[{"name":"revision","value":"v0.32.0"},{"name":"url","value":"https://github.com/GoogleContainerTools/skaffold"}]}}]}',
tekton.dev/v1beta1ResourcesResult: '[{"key":"commit","value":"6ed7aad5e8a36052ee5f6079fc91368e362121f7","resourceName":"skaffold"},{"key":"url","value":"https://github.com/GoogleContainerTools/skaffold","resourceName":"skaffold"}]',
}
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
timeout: 20s
podTemplate:
securityContext:
fsGroup: 65532
workspaces:
- emptyDir: {}
name: output
taskSpec:
steps:
- computeResources: {}
image: ubuntu
name: echo
script: |
#!/usr/bin/env bash
echo "Hello World!"
workspaces:
- name: output
status:
conditions:
- reason: Succeeded
status: "True"
type: Succeeded
podName: %s-pod
taskSpec:
steps:
- computeResources: {}
image: ubuntu
name: echo
script: |
#!/usr/bin/env bash
echo "Hello World!"
workspaces:
- name: output
steps:
- container: step-create-dir-skaffoldout
name: create-dir-skaffoldout
terminated:
reason: Completed
- container: git-source-skaffold
name: git-source-skaffold
terminated:
reason: Completed
- container: step-echo
name: step-echo
terminated:
reason: Completed
`
v1beta1PipelineRunYaml = `
metadata:
name: %s
namespace: %s
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
serviceAccountName: default
workspaces:
- name: password-vault
secret:
secretName: secret-password
timeout: 60s
pipelineSpec:
tasks:
- name: fetch-secure-data
taskSpec:
steps:
- name: fetch-and-write-secure
image: ubuntu
script: echo hello
resources:
- name: pipeline-git
type: git
resources:
- name: pipeline-git
resourceSpec:
type: git
params:
- name: revision
value: main
- name: url
value: https://github.com/tektoncd/pipeline
`
v1beta1PipelineRunExpectedYaml = `
metadata:
name: %s
namespace: %s
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
timeouts:
pipeline: 60s
workspaces:
- name: password-vault
secret:
secretName: secret-password
serviceAccountName: default
pipelineSpec:
tasks:
- name: fetch-secure-data
taskSpec:
steps:
- name: fetch-and-write-secure
image: ubuntu
script: echo hello
status:
conditions:
- type: Succeeded
status: "True"
reason: "Succeeded"
pipelineSpec:
tasks:
- name: fetch-secure-data
taskSpec:
name: cluster-task-pipeline-4
steps:
- name: "fetch-and-write-secure"
image: "ubuntu"
script: "echo hello"
taskRuns:
%s-fetch-secure-data:
pipelineTaskName: fetch-secure-data
status:
conditions:
- reason: Succeeded
status: "True"
type: Succeeded
podName: %s-fetch-secure-data-pod
steps:
- container: step-fetch-and-write-secure
imageID: docker.io/library/ubuntu@sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6e4ca954d47caebca4005c2
name: fetch-and-write-secure
terminated:
containerID: containerd://07b57fc6fd515e6d1d0de27149c60be9149697207aedc130dd0d284fce6df3fd
exitCode: 0
finishedAt: "2022-12-07T15:56:32Z"
reason: Completed
startedAt: "2022-12-07T15:56:32Z"
taskSpec:
steps:
- name: "fetch-and-write-secure"
image: "ubuntu"
script: "echo hello"
`
v1PipelineRunYaml = `
metadata:
name: %s
namespace: %s
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
pipelineSpec:
tasks:
- name: fetch-secure-data
taskSpec:
steps:
- name: fetch-and-write-secure
image: ubuntu
script: echo hello
timeouts:
pipeline: 60s
workspaces:
- name: password-vault
secret:
secretName: secret-password
taskRunTemplate: {
serviceAccountName: default
}
`
v1PipelineRunExpectedYaml = `
metadata:
name: %s
namespace: %s
annotations: {
tekton.dev/v1beta1Resources: '[{"name":"pipeline-git","resourceSpec":{"type":"git","params":[{"name":"revision","value":"main"},{"name":"url","value":"https://github.com/tektoncd/pipeline"}]}}]',
tekton.dev/v1beta1TaskRuns: '{"%s-fetch-secure-data":{"pipelineTaskName":"fetch-secure-data","status":{"conditions":[{"type":"Succeeded","status":"True","reason":"Succeeded","message":"All Steps have completed executing"}],"podName":"%s-fetch-secure-data-pod","steps":[{"terminated":{"exitCode":0,"reason":"Completed","containerID":"containerd://978666d35ed0e20f370227a0a4c3048ef6ec59a3ad5a2f5d83a3210099a9108f"},"name":"fetch-and-write-secure","container":"step-fetch-and-write-secure","imageID":"docker.io/library/ubuntu@sha256:4b1d0c4a2d2aaf63b37111f34eb9fa89fa1bf53dd6e4ca954d47caebca4005c2"}],"taskSpec":{"steps":[{"name":"fetch-and-write-secure","image":"ubuntu","resources":{},"script":"echo hello"}]}}}}',
}
spec:
params:
- name: STRING_LENGTH
value: 1
type: string
pipelineSpec:
tasks:
- name: fetch-secure-data
taskSpec:
steps:
- name: fetch-and-write-secure
image: ubuntu
script: echo hello
timeouts:
pipeline: 60s
workspaces:
- name: password-vault
secret:
secretName: secret-password
taskRunTemplate: {
serviceAccountName: default
}
status:
conditions:
- type: Succeeded
status: "True"
reason: "Succeeded"
pipelineSpec:
tasks:
- name: fetch-secure-data
taskSpec:
name: cluster-task-pipeline-4
steps:
- name: "fetch-and-write-secure"
image: "ubuntu"
script: "echo hello"
childReferences:
- typeMeta:
kind: TaskRun
apiVersion: tekton.dev/v1beta1
name: %s-fetch-secure-data
pipelineTaskName: fetch-secure-data
`
taskRunsKey = "%s-fetch-secure-data"
trStatusExpected = &v1beta1.PipelineRunTaskRunStatus{
PipelineTaskName: "fetch-secure-data",
Status: &v1beta1.TaskRunStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Status: "True",
Type: "Succeeded",
Reason: "Succeeded",
}},
},
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
PodName: "-fetch-secure-data-pod",
Steps: []v1beta1.StepState{{
Name: "fetch-and-write-secure",
ContainerState: corev1.ContainerState{Terminated: &corev1.ContainerStateTerminated{Reason: "Completed"}},
}},
TaskSpec: &v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Name: "fetch-and-write-secure", Image: "ubuntu", Script: "echo hello"}},
},
},
},
}
)
// TestTaskCRDConversion first creates a v1beta1 Task CRD using v1beta1Clients and
// requests it by v1Clients to compare with v1 if the conversion has been
// correctly executed by the webhook. And then it creates the v1 Task CRD using v1Clients
// and requests it by v1beta1Clients to compare with v1beta1.
func TestTaskCRDConversion(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
t.Parallel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)
v1beta1TaskName := helpers.ObjectNameForTest(t)
v1beta1Task := parse.MustParseV1beta1Task(t, fmt.Sprintf(v1beta1TaskYaml, v1beta1TaskName, namespace))
v1TaskExpected := parse.MustParseV1Task(t, fmt.Sprintf(v1TaskYaml, v1beta1TaskName, namespace))
if _, err := c.V1beta1TaskClient.Create(ctx, v1beta1Task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1beta1 Task: %s", err)
}
v1TaskGot, err := c.V1TaskClient.Get(ctx, v1beta1TaskName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1 Task for %s: %s", v1beta1TaskName, err)
}
if d := cmp.Diff(v1TaskExpected, v1TaskGot, filterMetadata...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
v1TaskName := helpers.ObjectNameForTest(t)
v1Task := parse.MustParseV1Task(t, fmt.Sprintf(v1TaskYaml, v1TaskName, namespace))
v1beta1TaskExpected := parse.MustParseV1beta1Task(t, fmt.Sprintf(v1beta1TaskYaml, v1TaskName, namespace))
if _, err := c.V1TaskClient.Create(ctx, v1Task, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1beta1 Task: %s", err)
}
v1beta1TaskGot, err := c.V1beta1TaskClient.Get(ctx, v1TaskName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1beta1 Task for %s: %s", v1TaskName, err)
}
if d := cmp.Diff(v1beta1TaskExpected, v1beta1TaskGot, filterMetadata...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
}
// TestTaskRunCRDConversion first creates a v1beta1 TaskRun CRD using v1beta1Clients
// and requests it by v1Clients to compare with v1 if the conversion has been correctly
// executed by the webhook. And then it creates the v1 TaskRun CRD using v1Clients
// and requests it by v1beta1Clients to compare with v1beta1.
func TestTaskRunCRDConversion(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
t.Parallel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)
v1beta1TaskRunName := helpers.ObjectNameForTest(t)
v1beta1TaskRun := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(v1beta1TaskRunYaml, v1beta1TaskRunName, namespace))
v1TaskRunExpected := parse.MustParseV1TaskRun(t, fmt.Sprintf(v1TaskRunExpectedYaml, v1beta1TaskRunName, namespace, v1beta1TaskRunName))
if _, err := c.V1beta1TaskRunClient.Create(ctx, v1beta1TaskRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1beta1 TaskRun: %s", err)
}
if err := WaitForTaskRunState(ctx, c, v1beta1TaskRunName, Succeed(v1beta1TaskRunName), v1beta1TaskRunName, "v1beta1"); err != nil {
t.Fatalf("Failed waiting for v1beta1 TaskRun done: %v", err)
}
v1TaskRunGot, err := c.V1TaskRunClient.Get(ctx, v1beta1TaskRunName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1 TaskRun for %s: %s", v1beta1TaskRunName, err)
}
if d := cmp.Diff(v1TaskRunExpected, v1TaskRunGot, filterV1TaskRunFields...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
v1TaskRunName := helpers.ObjectNameForTest(t)
v1TaskRun := parse.MustParseV1TaskRun(t, fmt.Sprintf(v1TaskRunYaml, v1TaskRunName, namespace))
v1beta1TaskRunExpected := parse.MustParseV1beta1TaskRun(t, fmt.Sprintf(v1beta1TaskRunExpectedYaml, v1TaskRunName, namespace, v1TaskRunName))
if _, err := c.V1TaskRunClient.Create(ctx, v1TaskRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1 TaskRun: %s", err)
}
if err := WaitForTaskRunState(ctx, c, v1TaskRunName, Succeed(v1TaskRunName), v1TaskRunName, "v1"); err != nil {
t.Fatalf("Failed waiting for v1 TaskRun done: %v", err)
}
v1beta1TaskRunGot, err := c.V1beta1TaskRunClient.Get(ctx, v1TaskRunName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1beta1 TaskRun for %s: %s", v1TaskRunName, err)
}
if d := cmp.Diff(v1beta1TaskRunExpected, v1beta1TaskRunGot, filterV1beta1TaskRunFields...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
}
// TestPipelineCRDConversion first creates a v1beta1 Pipeline CRD using v1beta1Clients and
// requests it by v1Clients to compare with v1 if the conversion has been
// correctly executed by the webhook. And then it creates the v1 Pipeline CRD using v1Clients
// and requests it by v1beta1Clients to compare with v1beta1.
func TestPipelineCRDConversion(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
t.Parallel()
c, namespace := setup(ctx, t)
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)
v1beta1PipelineName := helpers.ObjectNameForTest(t)
v1beta1Pipeline := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(v1beta1PipelineYaml, v1beta1PipelineName, namespace))
v1PipelineExpected := parse.MustParseV1Pipeline(t, fmt.Sprintf(v1PipelineYaml, v1beta1PipelineName, namespace))
if _, err := c.V1beta1PipelineClient.Create(ctx, v1beta1Pipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1beta1 Pipeline: %s", err)
}
v1PipelineGot, err := c.V1PipelineClient.Get(ctx, v1beta1PipelineName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1 Pipeline for %s: %s", v1beta1PipelineName, err)
}
if d := cmp.Diff(v1PipelineGot, v1PipelineExpected, filterMetadata...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
v1PipelineName := helpers.ObjectNameForTest(t)
v1Pipeline := parse.MustParseV1Pipeline(t, fmt.Sprintf(v1PipelineYaml, v1PipelineName, namespace))
v1beta1PipelineExpected := parse.MustParseV1beta1Pipeline(t, fmt.Sprintf(v1beta1PipelineYaml, v1PipelineName, namespace))
if _, err := c.V1PipelineClient.Create(ctx, v1Pipeline, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1 Pipeline: %s", err)
}
v1beta1PipelineGot, err := c.V1beta1PipelineClient.Get(ctx, v1PipelineName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1beta1 Pipeline for %s: %s", v1PipelineName, err)
}
if d := cmp.Diff(v1beta1PipelineExpected, v1beta1PipelineGot, filterMetadata...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
}
// TestPipelineRunCRDConversion first creates a v1beta1 PipelineRun CRD using v1beta1Clients and
// requests it by v1Clients to compare with v1 if the conversion has been
// correctly executed by the webhook. And then it creates the v1 PipelineRun CRD using v1Clients
// and requests it by v1beta1Clients to compare with v1beta1.
func TestPipelineRunCRDConversion(t *testing.T) {
ctx := withFullEmbeddedStatus(context.Background())
ctx, cancel := context.WithCancel(ctx)
defer cancel()
t.Parallel()
c, namespace := setup(ctx, t, requireAnyGate(fullEmbeddedGate))
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf)
defer tearDown(ctx, t, c, namespace)
v1beta1ToV1PipelineRunName := helpers.ObjectNameForTest(t)
v1beta1PipelineRun := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(v1beta1PipelineRunYaml, v1beta1ToV1PipelineRunName, namespace))
v1PipelineRunExpected := parse.MustParseV1PipelineRun(t, fmt.Sprintf(v1PipelineRunExpectedYaml, v1beta1ToV1PipelineRunName, namespace, v1beta1ToV1PipelineRunName, v1beta1ToV1PipelineRunName, v1beta1ToV1PipelineRunName))
if _, err := c.V1beta1PipelineRunClient.Create(ctx, v1beta1PipelineRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1beta1 PipelineRun: %s", err)
}
if err := WaitForPipelineRunState(ctx, c, v1beta1ToV1PipelineRunName, timeout, Succeed(v1beta1ToV1PipelineRunName), v1beta1ToV1PipelineRunName, "v1beta1"); err != nil {
t.Fatalf("Failed waiting for v1beta1 PipelineRun done: %v", err)
}
v1PipelineRunGot, err := c.V1PipelineRunClient.Get(ctx, v1beta1ToV1PipelineRunName, metav1.GetOptions{})
if err != nil {
t.Fatalf("Couldn't get expected v1 PipelineRun for %s: %s", v1beta1ToV1PipelineRunName, err)
}
if d := cmp.Diff(v1PipelineRunExpected, v1PipelineRunGot, filterV1PipelineRunFields...); d != "" {
t.Fatalf("-want, +got: %v", d)
}
// Annotations is Map[string]string which cannot be compared by fields so it first ignored
// in comparing the v1 converted PipelineRun above and then validated
if err := validatePipelineRunTaskRunStatusAnnotations(v1beta1ToV1PipelineRunName, v1PipelineRunGot.ObjectMeta.Annotations); err != nil {
t.Fatalf("Failed validating `status.taskRuns`: %s", err)
}
v1ToV1beta1PRName := helpers.ObjectNameForTest(t)
v1PipelineRun := parse.MustParseV1PipelineRun(t, fmt.Sprintf(v1PipelineRunYaml, v1ToV1beta1PRName, namespace))
v1beta1PipelineRunExpected := parse.MustParseV1beta1PipelineRun(t, fmt.Sprintf(v1beta1PipelineRunExpectedYaml, v1ToV1beta1PRName, namespace, v1ToV1beta1PRName, v1ToV1beta1PRName))
if _, err := c.V1PipelineRunClient.Create(ctx, v1PipelineRun, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create v1 PipelineRun: %s", err)
}