forked from argoproj/argo-workflows
/
validate_test.go
2410 lines (2213 loc) · 57.6 KB
/
validate_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
package validate
import (
"testing"
"github.com/stretchr/testify/assert"
apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
fakewfclientset "github.com/argoproj/argo/pkg/client/clientset/versioned/fake"
"github.com/argoproj/argo/test"
"github.com/argoproj/argo/workflow/common"
"github.com/argoproj/argo/workflow/templateresolution"
)
var wfClientset = fakewfclientset.NewSimpleClientset()
var wftmplGetter = templateresolution.WrapWorkflowTemplateInterface(wfClientset.ArgoprojV1alpha1().WorkflowTemplates(metav1.NamespaceDefault))
var cwftmplGetter = templateresolution.WrapClusterWorkflowTemplateInterface(wfClientset.ArgoprojV1alpha1().ClusterWorkflowTemplates())
func createWorkflowTemplate(yamlStr string) error {
wftmpl := unmarshalWftmpl(yamlStr)
_, err := wfClientset.ArgoprojV1alpha1().WorkflowTemplates(metav1.NamespaceDefault).Create(wftmpl)
if err != nil && apierr.IsAlreadyExists(err) {
return nil
}
return err
}
// validate is a test helper to accept Workflow YAML as a string and return
// its validation result.
func validate(yamlStr string) (*wfv1.WorkflowConditions, error) {
wf := unmarshalWf(yamlStr)
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{})
}
// validateWorkflowTemplate is a test helper to accept WorkflowTemplate YAML as a string and return
// its validation result.
func validateWorkflowTemplate(yamlStr string) error {
wftmpl := unmarshalWftmpl(yamlStr)
_, err := ValidateWorkflowTemplate(wftmplGetter, cwftmplGetter, wftmpl)
return err
}
func unmarshalWf(yamlStr string) *wfv1.Workflow {
var wf wfv1.Workflow
err := yaml.Unmarshal([]byte(yamlStr), &wf)
if err != nil {
panic(err)
}
return &wf
}
func unmarshalWftmpl(yamlStr string) *wfv1.WorkflowTemplate {
var wftmpl wfv1.WorkflowTemplate
err := yaml.Unmarshal([]byte(yamlStr), &wftmpl)
if err != nil {
panic(err)
}
return &wftmpl
}
const invalidErr = "is invalid"
var unknownField = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
unknown_field: ""
`
func TestUnknownField(t *testing.T) {
t.Skip("Cannot detect unknown fields yet")
_, err := validate(unknownField)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "invalid keys: unknown_field")
}
}
var dupTemplateNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
- name: whalesay
container:
image: docker/whalesay:latest
`
var dupInputNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
inputs:
parameters:
- name: dup
value: "value"
- name: dup
value: "value"
container:
image: docker/whalesay:latest
`
var emptyName = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
inputs:
parameters:
- name: ""
value: "value"
container:
image: docker/whalesay:latest
`
func TestDuplicateOrEmptyNames(t *testing.T) {
_, err := validate(dupTemplateNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "not unique")
}
_, err = validate(dupInputNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "not unique")
}
_, err = validate(emptyName)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "name is required")
}
}
var unresolvedInput = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:{{inputs.parameters.unresolved}}
`
var unresolvedOutput = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: unresolved-output-steps
templates:
- name: whalesay
container:
image: docker/whalesay:latest
- name: unresolved-output-steps
steps:
- - name: whalesay
template: whalesay
outputs:
parameters:
- name: unresolved
valueFrom:
parameter: "{{steps.whalesay.outputs.parameters.unresolved}}"
`
func TestUnresolved(t *testing.T) {
_, err := validate(unresolvedInput)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "failed to resolve")
}
_, err = validate(unresolvedOutput)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "failed to resolve")
}
}
var ioArtifactPaths = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-path-placeholders-
spec:
entrypoint: head-lines
arguments:
parameters:
- name: lines-count
value: 3
artifacts:
- name: text
raw:
data: |
1
2
3
4
5
templates:
- name: head-lines
inputs:
parameters:
- name: lines-count
artifacts:
- name: text
path: /inputs/text/data
outputs:
parameters:
- name: actual-lines-count
valueFrom:
path: /outputs/actual-lines-count/data
artifacts:
- name: text
path: /outputs/text/data
container:
image: busybox
command: [sh, -c, 'head -n {{inputs.parameters.lines-count}} <"{{inputs.artifacts.text.path}}" | tee "{{outputs.artifacts.text.path}}" | wc -l > "{{outputs.parameters.actual-lines-count.path}}"']
`
func TestResolveIOArtifactPathPlaceholders(t *testing.T) {
_, err := validate(ioArtifactPaths)
assert.NoError(t, err)
}
var outputParameterPath = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: get-current-date-
spec:
entrypoint: get-current-date
templates:
- name: get-current-date
outputs:
parameters:
- name: current-date
valueFrom:
path: /tmp/current-date
container:
image: busybox
command: [sh, -c, 'date > {{outputs.parameters.current-date.path}}']
`
func TestResolveOutputParameterPathPlaceholder(t *testing.T) {
_, err := validate(outputParameterPath)
assert.NoError(t, err)
}
var stepOutputReferences = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: step-output-ref-
spec:
entrypoint: whalesay
templates:
- name: whalesay
inputs:
parameters:
- name: message
value: "value"
container:
image: docker/whalesay:latest
outputs:
parameters:
- name: outparam
valueFrom:
path: /etc/hosts
- name: stepref
steps:
- - name: one
template: whalesay
- - name: two
template: whalesay
arguments:
parameters:
- name: message
value: "{{steps.one.outputs.parameters.outparam}}"
`
func TestStepOutputReference(t *testing.T) {
_, err := validate(stepOutputReferences)
assert.NoError(t, err)
}
var stepStatusReferences = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: status-ref-
spec:
entrypoint: statusref
templates:
- name: statusref
steps:
- - name: one
template: say
arguments:
parameters:
- name: message
value: "Hello, world"
- - name: two
template: say
arguments:
parameters:
- name: message
value: "{{steps.one.status}}"
- name: say
inputs:
parameters:
- name: message
value: "value"
container:
image: alpine:latest
command: [sh, -c]
args: ["echo {{inputs.parameters.message}}"]
`
func TestStepStatusReference(t *testing.T) {
_, err := validate(stepStatusReferences)
assert.NoError(t, err)
}
var stepStatusReferencesNoFutureReference = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: status-ref-
spec:
entrypoint: statusref
templates:
- name: statusref
steps:
- - name: one
template: say
arguments:
parameters:
- name: message
value: "{{steps.two.status}}"
- - name: two
template: say
arguments:
parameters:
- name: message
value: "{{steps.one.status}}"
- name: say
inputs:
parameters:
- name: message
value: "value"
container:
image: alpine:latest
command: [sh, -c]
args: ["echo {{inputs.parameters.message}}"]
`
func TestStepStatusReferenceNoFutureReference(t *testing.T) {
_, err := validate(stepStatusReferencesNoFutureReference)
// Can't reference the status of steps that have not run yet
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "failed to resolve {{steps.two.status}}")
}
}
var stepArtReferences = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: step-art-ref-
spec:
entrypoint: stepref
templates:
- name: generate
container:
image: alpine:3.7
command: [echo, generate]
outputs:
artifacts:
- name: generated_hosts
path: /etc/hosts
- name: echo
inputs:
parameters:
- name: message
artifacts:
- name: passthrough
path: /tmp/passthrough
container:
image: alpine:3.7
command: [echo, "{{inputs.parameters.message}}"]
outputs:
parameters:
- name: hosts
valueFrom:
path: /etc/hosts
artifacts:
- name: someoutput
path: /tmp/passthrough
- name: stepref
steps:
- - name: one
template: generate
- - name: two
template: echo
arguments:
parameters:
- name: message
value: val
artifacts:
- name: passthrough
from: "{{steps.one.outputs.artifacts.generated_hosts}}"
`
func TestStepArtReference(t *testing.T) {
_, err := validate(stepArtReferences)
assert.NoError(t, err)
}
var unsatisfiedParam = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
`
func TestUnsatisfiedParam(t *testing.T) {
_, err := validate(unsatisfiedParam)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "not supplied")
}
}
var globalParam = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: global-parameters-complex-
spec:
priority: 100
entrypoint: test-workflow
arguments:
parameters:
- name: message1
value: hello world
- name: message2
value: foo bar
templates:
- name: test-workflow
inputs:
parameters:
- name: message1
- name: message-internal
value: "{{workflow.parameters.message1}}"
steps:
- - name: step1
template: whalesay
arguments:
parameters:
- name: message1
value: world hello
- name: message2
value: "{{inputs.parameters.message1}}"
- name: message3
value: "{{workflow.parameters.message2}}"
- name: message4
value: "{{inputs.parameters.message-internal}}"
- name: whalesay
inputs:
parameters:
- name: message1
- name: message2
- name: message3
- name: message4
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["Global 1: {{workflow.parameters.message1}} Input 1: {{inputs.parameters.message1}} Input 2/Steps Input 1/Global 1: {{inputs.parameters.message2}} Input 3/Global 2: {{inputs.parameters.message3}} Input4/Steps Input 2 internal/Global 1: {{inputs.parameters.message4}}"]
`
func TestGlobalParam(t *testing.T) {
_, err := validate(globalParam)
assert.NoError(t, err)
}
var invalidTemplateNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay_d
templates:
- name: whalesay_d
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
`
func TestInvalidTemplateName(t *testing.T) {
_, err := validate(invalidTemplateNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
}
var invalidArgParamNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
arguments:
parameters:
- name: param#1
value: paramValue
templates:
- name: whalesay
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
`
func TestInvalidArgParamName(t *testing.T) {
_, err := validate(invalidArgParamNames)
assert.NotNil(t, err)
}
var invalidArgArtNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: arguments-artifacts-
spec:
entrypoint: kubectl-input-artifact
arguments:
artifacts:
- name: "&-kubectl"
http:
url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl
templates:
- name: kubectl-input-artifact
inputs:
artifacts:
- name: "&-kubectl"
path: /usr/local/bin/kubectl
mode: 0755
container:
image: debian:9.4
command: [sh, -c]
args: ["kubectl version"]
`
func TestInvalidArgArtName(t *testing.T) {
_, err := validate(invalidArgArtNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
}
var invalidStepNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-
spec:
entrypoint: hello-hello-hello
templates:
- name: hello-hello-hello
steps:
- - name: hello1.blah
template: whalesay
arguments:
parameters:
- name: message
value: "hello1"
- - name: hello2a
template: whalesay
arguments:
parameters:
- name: message
value: "hello2a"
- name: hello2b
template: whalesay
arguments:
parameters:
- name: message
value: "hello2b"
- name: whalesay
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
`
func TestInvalidStepName(t *testing.T) {
_, err := validate(invalidStepNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
}
var invalidInputParamNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-
spec:
entrypoint: whalesay
templates:
- name: whalesay
inputs:
parameters:
- name: message+123
default: "abc"
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message+123}}"]
`
func TestInvalidInputParamName(t *testing.T) {
_, err := validate(invalidInputParamNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
}
var invalidInputArtNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-
spec:
entrypoint: hello-hello-hello
templates:
- name: hello-hello-hello
steps:
- - name: hello1
template: whalesay
arguments:
parameters:
- name: message
value: "hello1"
- - name: hello2a
template: whalesay
arguments:
parameters:
- name: message
value: "hello2a"
- name: hello2b
template: whalesay
arguments:
parameters:
- name: message
value: "hello2b"
- name: whalesay
inputs:
parameters:
- name: message
artifacts:
- name: test(jpg
path: /test.jpg
http:
url: https://commons.wikimedia.org/wiki/File:Example.jpg
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
`
func TestInvalidInputArtName(t *testing.T) {
_, err := validate(invalidInputArtNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
}
var invalidOutputArtNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-artifact-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
outputs:
artifacts:
- name: "!1"
path: /tmp/hello_world.txt
`
func TestInvalidOutputArtName(t *testing.T) {
_, err := validate(invalidOutputArtNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
}
var invalidOutputParamNames = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-artifact-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
outputs:
parameters:
- name: blah-122lsfj}
valueFrom:
path: /tmp/hello_world.txt
`
var invalidOutputMissingValueFrom = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-param-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
outputs:
parameters:
- name: outparam
`
var invalidOutputMultipleValueFrom = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-param-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
outputs:
parameters:
- name: outparam
valueFrom:
path: /abc
jqFilter: abc
`
var invalidOutputIncompatibleValueFromPath = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-param-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
outputs:
parameters:
- name: outparam
valueFrom:
parameter: abc
`
var invalidOutputIncompatibleValueFromParam = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-param-
spec:
entrypoint: my-steps
templates:
- name: my-steps
steps:
- - name: step1
template: whalesay
outputs:
parameters:
- name: myoutput
valueFrom:
path: /abc
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
outputs:
parameters:
- name: outparam
valueFrom:
path: /abc
`
func TestInvalidOutputParam(t *testing.T) {
_, err := validate(invalidOutputParamNames)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), invalidErr)
}
_, err = validate(invalidOutputMissingValueFrom)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "does not have valueFrom or value specified")
}
_, err = validate(invalidOutputMultipleValueFrom)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "multiple valueFrom")
}
_, err = validate(invalidOutputIncompatibleValueFromPath)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), ".path must be specified for Container templates")
}
_, err = validate(invalidOutputIncompatibleValueFromParam)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), ".parameter must be specified for Steps templates")
}
}
var multipleTemplateTypes = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: multiple-template-types-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello world | tee /tmp/hello_world.txt"]
script:
image: python:alpine3.6
command: [python]
source: |
import random
i = random.randint(1, 100)
print(i)
`
func TestMultipleTemplateTypes(t *testing.T) {
_, err := validate(multipleTemplateTypes)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "multiple template types specified")
}
}
var exitHandlerWorkflowStatusOnExit = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: exit-handlers-
spec:
entrypoint: pass
onExit: fail
templates:
- name: pass
container:
image: alpine:latest
command: [sh, -c]
args: ["exit 0"]
- name: fail
container:
image: alpine:latest
command: [sh, -c]
args: ["echo {{workflow.status}} {{workflow.uid}}"]
`
var workflowStatusNotOnExit = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: exit-handlers-
spec:
entrypoint: pass
templates:
- name: pass
container:
image: alpine:latest
command: [sh, -c]
args: ["echo {{workflow.status}}"]
`
func TestExitHandler(t *testing.T) {
// ensure {{workflow.status}} is not available when not in exit handler
_, err := validate(workflowStatusNotOnExit)
assert.NotNil(t, err)
// ensure {{workflow.status}} is available in exit handler
_, err = validate(exitHandlerWorkflowStatusOnExit)
assert.NoError(t, err)
}
var workflowWithPriority = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: with-priority-
spec:
entrypoint: whalesay
priority: 100
templates:
- name: whalesay
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["{{workflow.priority}}"]
`
func TestPriorityVariable(t *testing.T) {
_, err := validate(workflowWithPriority)
assert.NoError(t, err)
}
var volumeMountArtifactPathCollision = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: path-collision-
spec:
volumeClaimTemplates:
- metadata:
name: workdir
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
entrypoint: pass
templates:
- name: pass
inputs:
artifacts:
- name: argo-source
path: /src
git: