-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
cluster_workflow_template_types.go
63 lines (51 loc) · 1.94 KB
/
cluster_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
package v1alpha1
import (
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ClusterWorkflowTemplate is the definition of a workflow template resource in cluster scope
// +genclient
// +genclient:noStatus
// +genclient:nonNamespaced
// +kubebuilder:resource:scope=Cluster,shortName=clusterwftmpl;cwft
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterWorkflowTemplate 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"`
}
type ClusterWorkflowTemplates []ClusterWorkflowTemplate
func (w ClusterWorkflowTemplates) Len() int {
return len(w)
}
func (w ClusterWorkflowTemplates) Less(i, j int) bool {
return strings.Compare(w[j].ObjectMeta.Name, w[i].ObjectMeta.Name) > 0
}
func (w ClusterWorkflowTemplates) Swap(i, j int) {
w[i], w[j] = w[j], w[i]
}
// ClusterWorkflowTemplateList is list of ClusterWorkflowTemplate resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterWorkflowTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
Items ClusterWorkflowTemplates `json:"items" protobuf:"bytes,2,rep,name=items"`
}
var _ TemplateHolder = &ClusterWorkflowTemplate{}
// GetTemplateByName retrieves a defined template by its name
func (cwftmpl *ClusterWorkflowTemplate) GetTemplateByName(name string) *Template {
for _, t := range cwftmpl.Spec.Templates {
if t.Name == name {
return &t
}
}
return nil
}
// GetResourceScope returns the template scope of workflow template.
func (cwftmpl *ClusterWorkflowTemplate) GetResourceScope() ResourceScope {
return ResourceScopeCluster
}
// GetWorkflowSpec returns the WorkflowSpec of cluster workflow template.
func (cwftmpl *ClusterWorkflowTemplate) GetWorkflowSpec() *WorkflowSpec {
return &cwftmpl.Spec
}