-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
workflow_template_types.go
73 lines (59 loc) · 2.23 KB
/
workflow_template_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
package v1alpha1
import (
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// WorkflowTemplate is the definition of a workflow template resource
// +genclient
// +genclient:noStatus
// +kubebuilder:resource:shortName=wftmpl
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type WorkflowTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Spec WorkflowTemplateSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
}
type WorkflowTemplates []WorkflowTemplate
func (w WorkflowTemplates) Len() int {
return len(w)
}
func (w WorkflowTemplates) Less(i, j int) bool {
return strings.Compare(w[j].ObjectMeta.Name, w[i].ObjectMeta.Name) > 0
}
func (w WorkflowTemplates) Swap(i, j int) {
w[i], w[j] = w[j], w[i]
}
// WorkflowTemplateList is list of WorkflowTemplate resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type WorkflowTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Items WorkflowTemplates `json:"items" protobuf:"bytes,2,rep,name=items"`
}
var _ TemplateHolder = &WorkflowTemplate{}
// WorkflowTemplateSpec is a spec of WorkflowTemplate.
type WorkflowTemplateSpec struct {
WorkflowSpec `json:",inline" protobuf:"bytes,1,opt,name=workflowSpec"`
// WorkflowMetadata contains some metadata of the workflow to be refer
WorkflowMetadata *metav1.ObjectMeta `json:"workflowMetadata,omitempty" protobuf:"bytes,2,opt,name=workflowMeta"`
}
// GetTemplateByName retrieves a defined template by its name
func (wftmpl *WorkflowTemplate) GetTemplateByName(name string) *Template {
for _, t := range wftmpl.Spec.Templates {
if t.Name == name {
return &t
}
}
return nil
}
// GetResourceScope returns the template scope of workflow template.
func (wftmpl *WorkflowTemplate) GetResourceScope() ResourceScope {
return ResourceScopeNamespaced
}
func (wftmpl *WorkflowTemplate) GetWorkflowMetadata() *metav1.ObjectMeta {
return wftmpl.Spec.WorkflowMetadata
}
// GetWorkflowSpec returns the WorkflowSpec of workflow template.
func (wftmpl *WorkflowTemplate) GetWorkflowSpec() *WorkflowSpec {
return &wftmpl.Spec.WorkflowSpec
}