-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
workflow_types.go
3109 lines (2560 loc) · 116 KB
/
workflow_types.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 v1alpha1
import (
"encoding/json"
"fmt"
"hash/fnv"
"net/url"
"path"
"reflect"
"sort"
"strings"
"time"
apiv1 "k8s.io/api/core/v1"
policyv1beta "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/intstr"
"github.com/argoproj/argo-workflows/v3/util/slice"
)
// TemplateType is the type of a template
type TemplateType string
// Possible template types
const (
TemplateTypeContainer TemplateType = "Container"
TemplateTypeContainerSet TemplateType = "ContainerSet"
TemplateTypeSteps TemplateType = "Steps"
TemplateTypeScript TemplateType = "Script"
TemplateTypeResource TemplateType = "Resource"
TemplateTypeDAG TemplateType = "DAG"
TemplateTypeSuspend TemplateType = "Suspend"
TemplateTypeData TemplateType = "Data"
TemplateTypeHTTP TemplateType = "HTTP"
TemplateTypeUnknown TemplateType = "Unknown"
)
// NodePhase is a label for the condition of a node at the current time.
type NodePhase string
// Workflow and node statuses
const (
// Node is waiting to run
NodePending NodePhase = "Pending"
// Node is running
NodeRunning NodePhase = "Running"
// Node finished with no errors
NodeSucceeded NodePhase = "Succeeded"
// Node was skipped
NodeSkipped NodePhase = "Skipped"
// Node or child of node exited with non-0 code
NodeFailed NodePhase = "Failed"
// Node had an error other than a non 0 exit code
NodeError NodePhase = "Error"
// Node was omitted because its `depends` condition was not met (only relevant in DAGs)
NodeOmitted NodePhase = "Omitted"
)
// NodeType is the type of a node
type NodeType string
// Node types
const (
NodeTypePod NodeType = "Pod"
NodeTypeContainer NodeType = "Container"
NodeTypeSteps NodeType = "Steps"
NodeTypeStepGroup NodeType = "StepGroup"
NodeTypeDAG NodeType = "DAG"
NodeTypeTaskGroup NodeType = "TaskGroup"
NodeTypeRetry NodeType = "Retry"
NodeTypeSkipped NodeType = "Skipped"
NodeTypeSuspend NodeType = "Suspend"
NodeTypeHTTP NodeType = "HTTP"
)
// PodGCStrategy is the strategy when to delete completed pods for GC.
type PodGCStrategy string
// PodGCStrategy
const (
PodGCOnPodCompletion PodGCStrategy = "OnPodCompletion"
PodGCOnPodSuccess PodGCStrategy = "OnPodSuccess"
PodGCOnWorkflowCompletion PodGCStrategy = "OnWorkflowCompletion"
PodGCOnWorkflowSuccess PodGCStrategy = "OnWorkflowSuccess"
)
// VolumeClaimGCStrategy is the strategy to use when deleting volumes from completed workflows
type VolumeClaimGCStrategy string
const (
VolumeClaimGCOnCompletion VolumeClaimGCStrategy = "OnWorkflowCompletion"
VolumeClaimGCOnSuccess VolumeClaimGCStrategy = "OnWorkflowSuccess"
)
// Workflow is the definition of a workflow resource
// +genclient
// +genclient:noStatus
// +kubebuilder:resource:shortName=wf
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase",description="Status of the workflow"
// +kubebuilder:printcolumn:name="Age",type="date",format="date-time",JSONPath=".status.startedAt",description="When the workflow was started"
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Workflow struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Spec WorkflowSpec `json:"spec" protobuf:"bytes,2,opt,name=spec "`
Status WorkflowStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// Workflows is a sort interface which sorts running jobs earlier before considering FinishedAt
type Workflows []Workflow
func (w Workflows) Len() int { return len(w) }
func (w Workflows) Swap(i, j int) { w[i], w[j] = w[j], w[i] }
func (w Workflows) Less(i, j int) bool {
iStart := w[i].ObjectMeta.CreationTimestamp
iFinish := w[i].Status.FinishedAt
jStart := w[j].ObjectMeta.CreationTimestamp
jFinish := w[j].Status.FinishedAt
if iFinish.IsZero() && jFinish.IsZero() {
return !iStart.Before(&jStart)
}
if iFinish.IsZero() && !jFinish.IsZero() {
return true
}
if !iFinish.IsZero() && jFinish.IsZero() {
return false
}
return jFinish.Before(&iFinish)
}
type WorkflowPredicate = func(wf Workflow) bool
func (w Workflows) Filter(predicate WorkflowPredicate) Workflows {
var out Workflows
for _, wf := range w {
if predicate(wf) {
out = append(out, wf)
}
}
return out
}
// GetTTLStrategy return TTLStrategy based on Order of precedence:
// 1. Workflow, 2. WorkflowTemplate, 3. Workflowdefault
func (w *Workflow) GetTTLStrategy() *TTLStrategy {
var ttlStrategy *TTLStrategy
// TTLStrategy from WorkflowTemplate
if w.Status.StoredWorkflowSpec != nil && w.Status.StoredWorkflowSpec.GetTTLStrategy() != nil {
ttlStrategy = w.Status.StoredWorkflowSpec.GetTTLStrategy()
}
// TTLStrategy from Workflow
if w.Spec.GetTTLStrategy() != nil {
ttlStrategy = w.Spec.GetTTLStrategy()
}
return ttlStrategy
}
var (
WorkflowCreatedAfter = func(t time.Time) WorkflowPredicate {
return func(wf Workflow) bool {
return wf.ObjectMeta.CreationTimestamp.After(t)
}
}
WorkflowFinishedBefore = func(t time.Time) WorkflowPredicate {
return func(wf Workflow) bool {
return !wf.Status.FinishedAt.IsZero() && wf.Status.FinishedAt.Time.Before(t)
}
}
WorkflowRanBetween = func(startTime time.Time, endTime time.Time) WorkflowPredicate {
return func(wf Workflow) bool {
return wf.ObjectMeta.CreationTimestamp.After(startTime) && !wf.Status.FinishedAt.IsZero() && wf.Status.FinishedAt.Time.Before(endTime)
}
}
)
// WorkflowList is list of Workflow resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type WorkflowList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Items Workflows `json:"items" protobuf:"bytes,2,opt,name=items"`
}
var _ TemplateHolder = &Workflow{}
// TTLStrategy is the strategy for the time to live depending on if the workflow succeeded or failed
type TTLStrategy struct {
// SecondsAfterCompletion is the number of seconds to live after completion
SecondsAfterCompletion *int32 `json:"secondsAfterCompletion,omitempty" protobuf:"bytes,1,opt,name=secondsAfterCompletion"`
// SecondsAfterSuccess is the number of seconds to live after success
SecondsAfterSuccess *int32 `json:"secondsAfterSuccess,omitempty" protobuf:"bytes,2,opt,name=secondsAfterSuccess"`
// SecondsAfterFailure is the number of seconds to live after failure
SecondsAfterFailure *int32 `json:"secondsAfterFailure,omitempty" protobuf:"bytes,3,opt,name=secondsAfterFailure"`
}
// WorkflowSpec is the specification of a Workflow.
type WorkflowSpec struct {
// Templates is a list of workflow templates used in a workflow
// +patchStrategy=merge
// +patchMergeKey=name
Templates []Template `json:"templates,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,1,opt,name=templates"`
// Entrypoint is a template reference to the starting point of the workflow.
Entrypoint string `json:"entrypoint,omitempty" protobuf:"bytes,2,opt,name=entrypoint"`
// Arguments contain the parameters and artifacts sent to the workflow entrypoint
// Parameters are referencable globally using the 'workflow' variable prefix.
// e.g. {{workflow.parameters.myparam}}
Arguments Arguments `json:"arguments,omitempty" protobuf:"bytes,3,opt,name=arguments"`
// ServiceAccountName is the name of the ServiceAccount to run all pods of the workflow as.
ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,4,opt,name=serviceAccountName"`
// AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods.
// ServiceAccountName of ExecutorConfig must be specified if this value is false.
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" protobuf:"varint,28,opt,name=automountServiceAccountToken"`
// Executor holds configurations of executor containers of the workflow.
Executor *ExecutorConfig `json:"executor,omitempty" protobuf:"bytes,29,opt,name=executor"`
// Volumes is a list of volumes that can be mounted by containers in a workflow.
// +patchStrategy=merge
// +patchMergeKey=name
Volumes []apiv1.Volume `json:"volumes,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,5,opt,name=volumes"`
// VolumeClaimTemplates is a list of claims that containers are allowed to reference.
// The Workflow controller will create the claims at the beginning of the workflow
// and delete the claims upon completion of the workflow
// +patchStrategy=merge
// +patchMergeKey=name
VolumeClaimTemplates []apiv1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,6,opt,name=volumeClaimTemplates"`
// Parallelism limits the max total parallel pods that can execute at the same time in a workflow
Parallelism *int64 `json:"parallelism,omitempty" protobuf:"bytes,7,opt,name=parallelism"`
// ArtifactRepositoryRef specifies the configMap name and key containing the artifact repository config.
ArtifactRepositoryRef *ArtifactRepositoryRef `json:"artifactRepositoryRef,omitempty" protobuf:"bytes,8,opt,name=artifactRepositoryRef"`
// Suspend will suspend the workflow and prevent execution of any future steps in the workflow
Suspend *bool `json:"suspend,omitempty" protobuf:"bytes,9,opt,name=suspend"`
// NodeSelector is a selector which will result in all pods of the workflow
// to be scheduled on the selected node(s). This is able to be overridden by
// a nodeSelector specified in the template.
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,10,opt,name=nodeSelector"`
// Affinity sets the scheduling constraints for all pods in the workflow.
// Can be overridden by an affinity specified in the template
Affinity *apiv1.Affinity `json:"affinity,omitempty" protobuf:"bytes,11,opt,name=affinity"`
// Tolerations to apply to workflow pods.
// +patchStrategy=merge
// +patchMergeKey=key
Tolerations []apiv1.Toleration `json:"tolerations,omitempty" patchStrategy:"merge" patchMergeKey:"key" protobuf:"bytes,12,opt,name=tolerations"`
// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images
// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets
// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.
// More info: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod
// +patchStrategy=merge
// +patchMergeKey=name
ImagePullSecrets []apiv1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,13,opt,name=imagePullSecrets"`
// Host networking requested for this workflow pod. Default to false.
HostNetwork *bool `json:"hostNetwork,omitempty" protobuf:"bytes,14,opt,name=hostNetwork"`
// Set DNS policy for the pod.
// Defaults to "ClusterFirst".
// Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
// DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy.
// To have DNS options set along with hostNetwork, you have to specify DNS policy
// explicitly to 'ClusterFirstWithHostNet'.
DNSPolicy *apiv1.DNSPolicy `json:"dnsPolicy,omitempty" protobuf:"bytes,15,opt,name=dnsPolicy"`
// PodDNSConfig defines the DNS parameters of a pod in addition to
// those generated from DNSPolicy.
DNSConfig *apiv1.PodDNSConfig `json:"dnsConfig,omitempty" protobuf:"bytes,16,opt,name=dnsConfig"`
// OnExit is a template reference which is invoked at the end of the
// workflow, irrespective of the success, failure, or error of the
// primary workflow.
OnExit string `json:"onExit,omitempty" protobuf:"bytes,17,opt,name=onExit"`
// TTLStrategy limits the lifetime of a Workflow that has finished execution depending on if it
// Succeeded or Failed. If this struct is set, once the Workflow finishes, it will be
// deleted after the time to live expires. If this field is unset,
// the controller config map will hold the default values.
TTLStrategy *TTLStrategy `json:"ttlStrategy,omitempty" protobuf:"bytes,30,opt,name=ttlStrategy"`
// Optional duration in seconds relative to the workflow start time which the workflow is
// allowed to run before the controller terminates the workflow. A value of zero is used to
// terminate a Running workflow
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty" protobuf:"bytes,19,opt,name=activeDeadlineSeconds"`
// Priority is used if controller is configured to process limited number of workflows in parallel. Workflows with higher priority are processed first.
Priority *int32 `json:"priority,omitempty" protobuf:"bytes,20,opt,name=priority"`
// Set scheduler name for all pods.
// Will be overridden if container/script template's scheduler name is set.
// Default scheduler will be used if neither specified.
// +optional
SchedulerName string `json:"schedulerName,omitempty" protobuf:"bytes,21,opt,name=schedulerName"`
// PodGC describes the strategy to use when to deleting completed pods
PodGC *PodGC `json:"podGC,omitempty" protobuf:"bytes,22,opt,name=podGC"`
// PriorityClassName to apply to workflow pods.
PodPriorityClassName string `json:"podPriorityClassName,omitempty" protobuf:"bytes,23,opt,name=podPriorityClassName"`
// Priority to apply to workflow pods.
PodPriority *int32 `json:"podPriority,omitempty" protobuf:"bytes,24,opt,name=podPriority"`
// +patchStrategy=merge
// +patchMergeKey=ip
HostAliases []apiv1.HostAlias `json:"hostAliases,omitempty" patchStrategy:"merge" patchMergeKey:"ip" protobuf:"bytes,25,opt,name=hostAliases"`
// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
// +optional
SecurityContext *apiv1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,26,opt,name=securityContext"`
// PodSpecPatch holds strategic merge patch to apply against the pod spec. Allows parameterization of
// container fields which are not strings (e.g. resource limits).
PodSpecPatch string `json:"podSpecPatch,omitempty" protobuf:"bytes,27,opt,name=podSpecPatch"`
// PodDisruptionBudget holds the number of concurrent disruptions that you allow for Workflow's Pods.
// Controller will automatically add the selector with workflow name, if selector is empty.
// Optional: Defaults to empty.
// +optional
PodDisruptionBudget *policyv1beta.PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty" protobuf:"bytes,31,opt,name=podDisruptionBudget"`
// Metrics are a list of metrics emitted from this Workflow
Metrics *Metrics `json:"metrics,omitempty" protobuf:"bytes,32,opt,name=metrics"`
// Shutdown will shutdown the workflow according to its ShutdownStrategy
Shutdown ShutdownStrategy `json:"shutdown,omitempty" protobuf:"bytes,33,opt,name=shutdown,casttype=ShutdownStrategy"`
// WorkflowTemplateRef holds a reference to a WorkflowTemplate for execution
WorkflowTemplateRef *WorkflowTemplateRef `json:"workflowTemplateRef,omitempty" protobuf:"bytes,34,opt,name=workflowTemplateRef"`
// Synchronization holds synchronization lock configuration for this Workflow
Synchronization *Synchronization `json:"synchronization,omitempty" protobuf:"bytes,35,opt,name=synchronization,casttype=Synchronization"`
// VolumeClaimGC describes the strategy to use when to deleting volumes from completed workflows
VolumeClaimGC *VolumeClaimGC `json:"volumeClaimGC,omitempty" protobuf:"bytes,36,opt,name=volumeClaimGC,casttype=VolumeClaimGC"`
// RetryStrategy for all templates in the workflow.
RetryStrategy *RetryStrategy `json:"retryStrategy,omitempty" protobuf:"bytes,37,opt,name=retryStrategy"`
// PodMetadata defines additional metadata that should be applied to workflow pods
PodMetadata *Metadata `json:"podMetadata,omitempty" protobuf:"bytes,38,opt,name=podMetadata"`
// TemplateDefaults holds default template values that will apply to all templates in the Workflow, unless overridden on the template-level
TemplateDefaults *Template `json:"templateDefaults,omitempty" protobuf:"bytes,39,opt,name=templateDefaults"`
}
// GetVolumeClaimGC returns the VolumeClaimGC that was defined in the workflow spec. If none was provided, a default value is returned.
func (wfs WorkflowSpec) GetVolumeClaimGC() *VolumeClaimGC {
// If no volumeClaimGC strategy was provided, we default to the equivalent of "OnSuccess"
// to match the existing behavior for back-compat
if wfs.VolumeClaimGC == nil {
return &VolumeClaimGC{Strategy: VolumeClaimGCOnSuccess}
}
return wfs.VolumeClaimGC
}
func (wfs WorkflowSpec) GetTTLStrategy() *TTLStrategy {
return wfs.TTLStrategy
}
// GetSemaphoreKeys will return list of semaphore configmap keys which are configured in the workflow
// Example key format namespace/configmapname (argo/my-config)
// Return []string
func (wf *Workflow) GetSemaphoreKeys() []string {
keyMap := make(map[string]bool)
namespace := wf.Namespace
var templates []Template
if wf.Spec.WorkflowTemplateRef == nil {
templates = wf.Spec.Templates
if wf.Spec.Synchronization != nil {
if configMapRef := wf.Spec.Synchronization.getSemaphoreConfigMapRef(); configMapRef != nil {
key := fmt.Sprintf("%s/%s", namespace, configMapRef.Name)
keyMap[key] = true
}
}
} else if wf.Status.StoredWorkflowSpec != nil {
templates = wf.Status.StoredWorkflowSpec.Templates
if wf.Status.StoredWorkflowSpec.Synchronization != nil {
if configMapRef := wf.Status.StoredWorkflowSpec.Synchronization.getSemaphoreConfigMapRef(); configMapRef != nil {
key := fmt.Sprintf("%s/%s", namespace, configMapRef.Name)
keyMap[key] = true
}
}
}
for _, tmpl := range templates {
if tmpl.Synchronization != nil {
if configMapRef := tmpl.Synchronization.getSemaphoreConfigMapRef(); configMapRef != nil {
key := fmt.Sprintf("%s/%s", namespace, configMapRef.Name)
keyMap[key] = true
}
}
}
var semaphoreKeys []string
for key := range keyMap {
semaphoreKeys = append(semaphoreKeys, key)
}
return semaphoreKeys
}
type ShutdownStrategy string
const (
ShutdownStrategyTerminate ShutdownStrategy = "Terminate"
ShutdownStrategyStop ShutdownStrategy = "Stop"
ShutdownStrategyNone ShutdownStrategy = ""
)
func (s ShutdownStrategy) Enabled() bool {
return s != ShutdownStrategyNone
}
func (s ShutdownStrategy) ShouldExecute(isOnExitPod bool) bool {
switch s {
case ShutdownStrategyTerminate:
return false
case ShutdownStrategyStop:
return isOnExitPod
default:
return true
}
}
// +kubebuilder:validation:Type=array
type ParallelSteps struct {
Steps []WorkflowStep `json:"-" protobuf:"bytes,1,rep,name=steps"`
}
// WorkflowStep is an anonymous list inside of ParallelSteps (i.e. it does not have a key), so it needs its own
// custom Unmarshaller
func (p *ParallelSteps) UnmarshalJSON(value []byte) error {
// Since we are writing a custom unmarshaller, we have to enforce the "DisallowUnknownFields" requirement manually.
// First, get a generic representation of the contents
var candidate []map[string]interface{}
err := json.Unmarshal(value, &candidate)
if err != nil {
return err
}
// Generate a list of all the available JSON fields of the WorkflowStep struct
availableFields := map[string]bool{}
reflectType := reflect.TypeOf(WorkflowStep{})
for i := 0; i < reflectType.NumField(); i++ {
cleanString := strings.ReplaceAll(reflectType.Field(i).Tag.Get("json"), ",omitempty", "")
availableFields[cleanString] = true
}
// Enforce that no unknown fields are present
for _, step := range candidate {
for key := range step {
if _, ok := availableFields[key]; !ok {
return fmt.Errorf(`json: unknown field "%s"`, key)
}
}
}
// Finally, attempt to fully unmarshal the struct
err = json.Unmarshal(value, &p.Steps)
if err != nil {
return err
}
return nil
}
func (p ParallelSteps) MarshalJSON() ([]byte, error) {
return json.Marshal(p.Steps)
}
func (b ParallelSteps) OpenAPISchemaType() []string {
return []string{"array"}
}
func (b ParallelSteps) OpenAPISchemaFormat() string { return "" }
func (wfs *WorkflowSpec) HasPodSpecPatch() bool {
return wfs.PodSpecPatch != ""
}
// Template is a reusable and composable unit of execution in a workflow
type Template struct {
// Name is the name of the template
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
// Inputs describe what inputs parameters and artifacts are supplied to this template
Inputs Inputs `json:"inputs,omitempty" protobuf:"bytes,5,opt,name=inputs"`
// Outputs describe the parameters and artifacts that this template produces
Outputs Outputs `json:"outputs,omitempty" protobuf:"bytes,6,opt,name=outputs"`
// NodeSelector is a selector to schedule this step of the workflow to be
// run on the selected node(s). Overrides the selector set at the workflow level.
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,opt,name=nodeSelector"`
// Affinity sets the pod's scheduling constraints
// Overrides the affinity set at the workflow level (if any)
Affinity *apiv1.Affinity `json:"affinity,omitempty" protobuf:"bytes,8,opt,name=affinity"`
// Metdata sets the pods's metadata, i.e. annotations and labels
Metadata Metadata `json:"metadata,omitempty" protobuf:"bytes,9,opt,name=metadata"`
// Deamon will allow a workflow to proceed to the next step so long as the container reaches readiness
Daemon *bool `json:"daemon,omitempty" protobuf:"bytes,10,opt,name=daemon"`
// Steps define a series of sequential/parallel workflow steps
Steps []ParallelSteps `json:"steps,omitempty" protobuf:"bytes,11,opt,name=steps"`
// Container is the main container image to run in the pod
Container *apiv1.Container `json:"container,omitempty" protobuf:"bytes,12,opt,name=container"`
// ContainerSet groups multiple containers within a single pod.
ContainerSet *ContainerSetTemplate `json:"containerSet,omitempty" protobuf:"bytes,40,opt,name=containerSet"`
// Script runs a portion of code against an interpreter
Script *ScriptTemplate `json:"script,omitempty" protobuf:"bytes,13,opt,name=script"`
// Resource template subtype which can run k8s resources
Resource *ResourceTemplate `json:"resource,omitempty" protobuf:"bytes,14,opt,name=resource"`
// DAG template subtype which runs a DAG
DAG *DAGTemplate `json:"dag,omitempty" protobuf:"bytes,15,opt,name=dag"`
// Suspend template subtype which can suspend a workflow when reaching the step
Suspend *SuspendTemplate `json:"suspend,omitempty" protobuf:"bytes,16,opt,name=suspend"`
// Data is a data template
Data *Data `json:"data,omitempty" protobuf:"bytes,39,opt,name=data"`
// HTTP makes a HTTP request
HTTP *HTTP `json:"http,omitempty" protobuf:"bytes,42,opt,name=http"`
// Volumes is a list of volumes that can be mounted by containers in a template.
// +patchStrategy=merge
// +patchMergeKey=name
Volumes []apiv1.Volume `json:"volumes,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,17,opt,name=volumes"`
// InitContainers is a list of containers which run before the main container.
// +patchStrategy=merge
// +patchMergeKey=name
InitContainers []UserContainer `json:"initContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,18,opt,name=initContainers"`
// Sidecars is a list of containers which run alongside the main container
// Sidecars are automatically killed when the main container completes
// +patchStrategy=merge
// +patchMergeKey=name
Sidecars []UserContainer `json:"sidecars,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,19,opt,name=sidecars"`
// Location in which all files related to the step will be stored (logs, artifacts, etc...).
// Can be overridden by individual items in Outputs. If omitted, will use the default
// artifact repository location configured in the controller, appended with the
// <workflowname>/<nodename> in the key.
ArchiveLocation *ArtifactLocation `json:"archiveLocation,omitempty" protobuf:"bytes,20,opt,name=archiveLocation"`
// Optional duration in seconds relative to the StartTime that the pod may be active on a node
// before the system actively tries to terminate the pod; value must be positive integer
// This field is only applicable to container and script templates.
ActiveDeadlineSeconds *intstr.IntOrString `json:"activeDeadlineSeconds,omitempty" protobuf:"bytes,21,opt,name=activeDeadlineSeconds"`
// RetryStrategy describes how to retry a template when it fails
RetryStrategy *RetryStrategy `json:"retryStrategy,omitempty" protobuf:"bytes,22,opt,name=retryStrategy"`
// Parallelism limits the max total parallel pods that can execute at the same time within the
// boundaries of this template invocation. If additional steps/dag templates are invoked, the
// pods created by those templates will not be counted towards this total.
Parallelism *int64 `json:"parallelism,omitempty" protobuf:"bytes,23,opt,name=parallelism"`
// FailFast, if specified, will fail this template if any of its child pods has failed. This is useful for when this
// template is expanded with `withItems`, etc.
FailFast *bool `json:"failFast,omitempty" protobuf:"varint,41,opt,name=failFast"`
// Tolerations to apply to workflow pods.
// +patchStrategy=merge
// +patchMergeKey=key
Tolerations []apiv1.Toleration `json:"tolerations,omitempty" patchStrategy:"merge" patchMergeKey:"key" protobuf:"bytes,24,opt,name=tolerations"`
// If specified, the pod will be dispatched by specified scheduler.
// Or it will be dispatched by workflow scope scheduler if specified.
// If neither specified, the pod will be dispatched by default scheduler.
// +optional
SchedulerName string `json:"schedulerName,omitempty" protobuf:"bytes,25,opt,name=schedulerName"`
// PriorityClassName to apply to workflow pods.
PriorityClassName string `json:"priorityClassName,omitempty" protobuf:"bytes,26,opt,name=priorityClassName"`
// Priority to apply to workflow pods.
Priority *int32 `json:"priority,omitempty" protobuf:"bytes,27,opt,name=priority"`
// ServiceAccountName to apply to workflow pods
ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,28,opt,name=serviceAccountName"`
// AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods.
// ServiceAccountName of ExecutorConfig must be specified if this value is false.
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" protobuf:"varint,32,opt,name=automountServiceAccountToken"`
// Executor holds configurations of the executor container.
Executor *ExecutorConfig `json:"executor,omitempty" protobuf:"bytes,33,opt,name=executor"`
// HostAliases is an optional list of hosts and IPs that will be injected into the pod spec
// +patchStrategy=merge
// +patchMergeKey=ip
HostAliases []apiv1.HostAlias `json:"hostAliases,omitempty" patchStrategy:"merge" patchMergeKey:"ip" protobuf:"bytes,29,opt,name=hostAliases"`
// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
// +optional
SecurityContext *apiv1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,30,opt,name=securityContext"`
// PodSpecPatch holds strategic merge patch to apply against the pod spec. Allows parameterization of
// container fields which are not strings (e.g. resource limits).
PodSpecPatch string `json:"podSpecPatch,omitempty" protobuf:"bytes,31,opt,name=podSpecPatch"`
// Metrics are a list of metrics emitted from this template
Metrics *Metrics `json:"metrics,omitempty" protobuf:"bytes,35,opt,name=metrics"`
// Synchronization holds synchronization lock configuration for this template
Synchronization *Synchronization `json:"synchronization,omitempty" protobuf:"bytes,36,opt,name=synchronization,casttype=Synchronization"`
// Memoize allows templates to use outputs generated from already executed templates
Memoize *Memoize `json:"memoize,omitempty" protobuf:"bytes,37,opt,name=memoize"`
// Timout allows to set the total node execution timeout duration counting from the node's start time.
// This duration also includes time in which the node spends in Pending state. This duration may not be applied to Step or DAG templates.
Timeout string `json:"timeout,omitempty" protobuf:"bytes,38,opt,name=timeout"`
}
// SetType will set the template object based on template type.
func (tmpl *Template) SetType(tmplType TemplateType) {
switch tmplType {
case TemplateTypeSteps:
tmpl.setTemplateObjs(tmpl.Steps, nil, nil, nil, nil, nil, nil)
case TemplateTypeDAG:
tmpl.setTemplateObjs(nil, tmpl.DAG, nil, nil, nil, nil, nil)
case TemplateTypeContainer:
tmpl.setTemplateObjs(nil, nil, tmpl.Container, nil, nil, nil, nil)
case TemplateTypeScript:
tmpl.setTemplateObjs(nil, nil, nil, tmpl.Script, nil, nil, nil)
case TemplateTypeResource:
tmpl.setTemplateObjs(nil, nil, nil, nil, tmpl.Resource, nil, nil)
case TemplateTypeData:
tmpl.setTemplateObjs(nil, nil, nil, nil, nil, tmpl.Data, nil)
case TemplateTypeSuspend:
tmpl.setTemplateObjs(nil, nil, nil, nil, nil, nil, tmpl.Suspend)
}
}
func (tmpl *Template) setTemplateObjs(steps []ParallelSteps, dag *DAGTemplate, container *apiv1.Container, script *ScriptTemplate, resource *ResourceTemplate, data *Data, suspend *SuspendTemplate) {
tmpl.Steps = steps
tmpl.DAG = dag
tmpl.Container = container
tmpl.Script = script
tmpl.Resource = resource
tmpl.Data = data
tmpl.Suspend = suspend
}
// GetBaseTemplate returns a base template content.
func (tmpl *Template) GetBaseTemplate() *Template {
baseTemplate := tmpl.DeepCopy()
baseTemplate.Inputs = Inputs{}
return baseTemplate
}
func (tmpl *Template) HasPodSpecPatch() bool {
return tmpl.PodSpecPatch != ""
}
func (tmpl *Template) GetSidecarNames() []string {
var containerNames []string
for _, s := range tmpl.Sidecars {
containerNames = append(containerNames, s.Name)
}
return containerNames
}
func (tmpl *Template) IsFailFast() bool {
return tmpl.FailFast != nil && *tmpl.FailFast
}
func (tmpl *Template) HasParallelism() bool {
return tmpl.Parallelism != nil && *tmpl.Parallelism > 0
}
type Artifacts []Artifact
func (a Artifacts) GetArtifactByName(name string) *Artifact {
for _, art := range a {
if art.Name == name {
return &art
}
}
return nil
}
// Inputs are the mechanism for passing parameters, artifacts, volumes from one template to another
type Inputs struct {
// Parameters are a list of parameters passed as inputs
// +patchStrategy=merge
// +patchMergeKey=name
Parameters []Parameter `json:"parameters,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,1,opt,name=parameters"`
// Artifact are a list of artifacts passed as inputs
// +patchStrategy=merge
// +patchMergeKey=name
Artifacts Artifacts `json:"artifacts,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,opt,name=artifacts"`
}
func (in Inputs) IsEmpty() bool {
return len(in.Parameters) == 0 && len(in.Artifacts) == 0
}
// Pod metdata
type Metadata struct {
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,1,opt,name=annotations"`
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,2,opt,name=labels"`
}
// Parameter indicate a passed string parameter to a service template with an optional default value
type Parameter struct {
// Name is the parameter name
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// Default is the default value to use for an input parameter if a value was not supplied
Default *AnyString `json:"default,omitempty" protobuf:"bytes,2,opt,name=default"`
// Value is the literal value to use for the parameter.
// If specified in the context of an input parameter, the value takes precedence over any passed values
Value *AnyString `json:"value,omitempty" protobuf:"bytes,3,opt,name=value"`
// ValueFrom is the source for the output parameter's value
ValueFrom *ValueFrom `json:"valueFrom,omitempty" protobuf:"bytes,4,opt,name=valueFrom"`
// GlobalName exports an output parameter to the global scope, making it available as
// '{{workflow.outputs.parameters.XXXX}} and in workflow.status.outputs.parameters
GlobalName string `json:"globalName,omitempty" protobuf:"bytes,5,opt,name=globalName"`
// Enum holds a list of string values to choose from, for the actual value of the parameter
Enum []AnyString `json:"enum,omitempty" protobuf:"bytes,6,rep,name=enum"`
}
// ValueFrom describes a location in which to obtain the value to a parameter
type ValueFrom struct {
// Path in the container to retrieve an output parameter value from in container templates
Path string `json:"path,omitempty" protobuf:"bytes,1,opt,name=path"`
// JSONPath of a resource to retrieve an output parameter value from in resource templates
JSONPath string `json:"jsonPath,omitempty" protobuf:"bytes,2,opt,name=jsonPath"`
// JQFilter expression against the resource object in resource templates
JQFilter string `json:"jqFilter,omitempty" protobuf:"bytes,3,opt,name=jqFilter"`
// Selector (https://github.com/antonmedv/expr) that is evaluated against the event to get the value of the parameter. E.g. `payload.message`
Event string `json:"event,omitempty" protobuf:"bytes,7,opt,name=event"`
// Parameter reference to a step or dag task in which to retrieve an output parameter value from
// (e.g. '{{steps.mystep.outputs.myparam}}')
Parameter string `json:"parameter,omitempty" protobuf:"bytes,4,opt,name=parameter"`
// Supplied value to be filled in directly, either through the CLI, API, etc.
Supplied *SuppliedValueFrom `json:"supplied,omitempty" protobuf:"bytes,6,opt,name=supplied"`
// ConfigMapKeyRef is configmap selector for input parameter configuration
ConfigMapKeyRef *apiv1.ConfigMapKeySelector `json:"configMapKeyRef,omitempty" protobuf:"bytes,9,opt,name=configMapKeyRef"`
// Default specifies a value to be used if retrieving the value from the specified source fails
Default *AnyString `json:"default,omitempty" protobuf:"bytes,5,opt,name=default"`
// Expression, if defined, is evaluated to specify the value for the parameter
Expression string `json:"expression,omitempty" protobuf:"bytes,8,rep,name=expression"`
}
func (p *Parameter) HasValue() bool {
return p.Value != nil || p.Default != nil || p.ValueFrom != nil
}
func (p *Parameter) GetValue() string {
if p.Value != nil {
return p.Value.String()
}
if p.Default != nil {
return p.Default.String()
}
return ""
}
// SuppliedValueFrom is a placeholder for a value to be filled in directly, either through the CLI, API, etc.
type SuppliedValueFrom struct{}
// Artifact indicates an artifact to place at a specified path
type Artifact struct {
// name of the artifact. must be unique within a template's inputs/outputs.
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
// Path is the container path to the artifact
Path string `json:"path,omitempty" protobuf:"bytes,2,opt,name=path"`
// mode bits to use on this file, must be a value between 0 and 0777
// set when loading input artifacts.
Mode *int32 `json:"mode,omitempty" protobuf:"varint,3,opt,name=mode"`
// From allows an artifact to reference an artifact from a previous step
From string `json:"from,omitempty" protobuf:"bytes,4,opt,name=from"`
// ArtifactLocation contains the location of the artifact
ArtifactLocation `json:",inline" protobuf:"bytes,5,opt,name=artifactLocation"`
// GlobalName exports an output artifact to the global scope, making it available as
// '{{workflow.outputs.artifacts.XXXX}} and in workflow.status.outputs.artifacts
GlobalName string `json:"globalName,omitempty" protobuf:"bytes,6,opt,name=globalName"`
// Archive controls how the artifact will be saved to the artifact repository.
Archive *ArchiveStrategy `json:"archive,omitempty" protobuf:"bytes,7,opt,name=archive"`
// Make Artifacts optional, if Artifacts doesn't generate or exist
Optional bool `json:"optional,omitempty" protobuf:"varint,8,opt,name=optional"`
// SubPath allows an artifact to be sourced from a subpath within the specified source
SubPath string `json:"subPath,omitempty" protobuf:"bytes,9,opt,name=subPath"`
// If mode is set, apply the permission recursively into the artifact if it is a folder
RecurseMode bool `json:"recurseMode,omitempty" protobuf:"varint,10,opt,name=recurseMode"`
// FromExpression, if defined, is evaluated to specify the value for the artifact
FromExpression string `json:"fromExpression,omitempty" protobuf:"bytes,11,opt,name=fromExpression"`
}
// PodGC describes how to delete completed pods as they complete
type PodGC struct {
// Strategy is the strategy to use. One of "OnPodCompletion", "OnPodSuccess", "OnWorkflowCompletion", "OnWorkflowSuccess"
Strategy PodGCStrategy `json:"strategy,omitempty" protobuf:"bytes,1,opt,name=strategy,casttype=PodGCStrategy"`
// LabelSelector is the label selector to check if the pods match the labels before being added to the pod GC queue.
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty" protobuf:"bytes,2,opt,name=labelSelector"`
}
// Matches returns whether the pod labels match with the label selector specified in podGC.
func (podGC *PodGC) Matches(labels labels.Set) (bool, error) {
if podGC == nil {
return true, nil
}
selector, err := metav1.LabelSelectorAsSelector(podGC.LabelSelector)
if err != nil {
return false, err
}
return selector.Matches(labels), nil
}
// GetLabelSelector gets the label selector from podGC.
func (podGC *PodGC) GetLabelSelector() *metav1.LabelSelector {
if podGC != nil && podGC.LabelSelector != nil {
return podGC.LabelSelector
}
return nil
}
// VolumeClaimGC describes how to delete volumes from completed Workflows
type VolumeClaimGC struct {
// Strategy is the strategy to use. One of "OnWorkflowCompletion", "OnWorkflowSuccess"
Strategy VolumeClaimGCStrategy `json:"strategy,omitempty" protobuf:"bytes,1,opt,name=strategy,casttype=VolumeClaimGCStrategy"`
}
// GetStrategy returns the VolumeClaimGCStrategy to use for the workflow
func (vgc VolumeClaimGC) GetStrategy() VolumeClaimGCStrategy {
if vgc.Strategy == "" {
return VolumeClaimGCOnSuccess
}
return vgc.Strategy
}
// ArchiveStrategy describes how to archive files/directory when saving artifacts
type ArchiveStrategy struct {
Tar *TarStrategy `json:"tar,omitempty" protobuf:"bytes,1,opt,name=tar"`
None *NoneStrategy `json:"none,omitempty" protobuf:"bytes,2,opt,name=none"`
Zip *ZipStrategy `json:"zip,omitempty" protobuf:"bytes,3,opt,name=zip"`
}
// TarStrategy will tar and gzip the file or directory when saving
type TarStrategy struct {
// CompressionLevel specifies the gzip compression level to use for the artifact.
// Defaults to gzip.DefaultCompression.
CompressionLevel *int32 `json:"compressionLevel,omitempty" protobuf:"varint,1,opt,name=compressionLevel"`
}
// ZipStrategy will unzip zipped input artifacts
type ZipStrategy struct{}
// NoneStrategy indicates to skip tar process and upload the files or directory tree as independent
// files. Note that if the artifact is a directory, the artifact driver must support the ability to
// save/load the directory appropriately.
type NoneStrategy struct{}
type ArtifactLocationType interface {
HasLocation() bool
GetKey() (string, error)
SetKey(key string) error
}
// ArtifactLocation describes a location for a single or multiple artifacts.
// It is used as single artifact in the context of inputs/outputs (e.g. outputs.artifacts.artname).
// It is also used to describe the location of multiple artifacts such as the archive location
// of a single workflow step, which the executor will use as a default location to store its files.
type ArtifactLocation struct {
// ArchiveLogs indicates if the container logs should be archived
ArchiveLogs *bool `json:"archiveLogs,omitempty" protobuf:"varint,1,opt,name=archiveLogs"`
// S3 contains S3 artifact location details
S3 *S3Artifact `json:"s3,omitempty" protobuf:"bytes,2,opt,name=s3"`
// Git contains git artifact location details
Git *GitArtifact `json:"git,omitempty" protobuf:"bytes,3,opt,name=git"`
// HTTP contains HTTP artifact location details
HTTP *HTTPArtifact `json:"http,omitempty" protobuf:"bytes,4,opt,name=http"`
// Artifactory contains artifactory artifact location details
Artifactory *ArtifactoryArtifact `json:"artifactory,omitempty" protobuf:"bytes,5,opt,name=artifactory"`
// HDFS contains HDFS artifact location details
HDFS *HDFSArtifact `json:"hdfs,omitempty" protobuf:"bytes,6,opt,name=hdfs"`
// Raw contains raw artifact location details
Raw *RawArtifact `json:"raw,omitempty" protobuf:"bytes,7,opt,name=raw"`
// OSS contains OSS artifact location details
OSS *OSSArtifact `json:"oss,omitempty" protobuf:"bytes,8,opt,name=oss"`
// GCS contains GCS artifact location details
GCS *GCSArtifact `json:"gcs,omitempty" protobuf:"bytes,9,opt,name=gcs"`
}
func (a *ArtifactLocation) Get() ArtifactLocationType {
if a == nil {
return nil
} else if a.Artifactory != nil {
return a.Artifactory
} else if a.Git != nil {
return a.Git
} else if a.GCS != nil {
return a.GCS
} else if a.HDFS != nil {
return a.HDFS
} else if a.HTTP != nil {
return a.HTTP
} else if a.OSS != nil {
return a.OSS
} else if a.Raw != nil {
return a.Raw
} else if a.S3 != nil {
return a.S3
}
return nil
}
// SetType sets the type of the artifact to type the argument.
// Any existing value is deleted.
func (a *ArtifactLocation) SetType(x ArtifactLocationType) error {
switch v := x.(type) {
case *ArtifactoryArtifact:
a.Artifactory = &ArtifactoryArtifact{}
case *GCSArtifact:
a.GCS = &GCSArtifact{}
case *HDFSArtifact:
a.HDFS = &HDFSArtifact{}
case *HTTPArtifact:
a.HTTP = &HTTPArtifact{}
case *OSSArtifact:
a.OSS = &OSSArtifact{}
case *RawArtifact:
a.Raw = &RawArtifact{}
case *S3Artifact:
a.S3 = &S3Artifact{}
default:
return fmt.Errorf("set type not supported for type: %v", reflect.TypeOf(v))
}
return nil
}
func (a *ArtifactLocation) HasLocationOrKey() bool {
return a.HasLocation() || a.HasKey()
}
// HasKey returns whether or not an artifact has a key. They may or may not also HasLocation.
func (a *ArtifactLocation) HasKey() bool {
key, _ := a.GetKey()
return key != ""
}