...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "github.com/pkg/errors"
20 corev1 "k8s.io/api/core/v1"
21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22 "k8s.io/apimachinery/pkg/runtime"
23 )
24
25
26
27
28
29 type Workflow struct {
30 metav1.TypeMeta `json:",inline"`
31 metav1.ObjectMeta `json:"metadata,omitempty"`
32
33
34 Spec WorkflowSpec `json:"spec"`
35
36
37
38 Status WorkflowStatus `json:"status"`
39 }
40
41 func (in *Workflow) GetObjectMeta() *metav1.ObjectMeta {
42 return &in.ObjectMeta
43 }
44
45 const KindWorkflow = "Workflow"
46
47 type WorkflowSpec struct {
48 Entry string `json:"entry"`
49 Templates []Template `json:"templates"`
50 }
51
52 type WorkflowStatus struct {
53
54 EntryNode *string `json:"entryNode,omitempty"`
55
56 StartTime *metav1.Time `json:"startTime,omitempty"`
57
58 EndTime *metav1.Time `json:"endTime,omitempty"`
59
60
61
62
63 Conditions []WorkflowCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
64 }
65
66 type WorkflowConditionType string
67
68 const (
69 WorkflowConditionAccomplished WorkflowConditionType = "Accomplished"
70 WorkflowConditionScheduled WorkflowConditionType = "Scheduled"
71 )
72
73 type WorkflowCondition struct {
74 Type WorkflowConditionType `json:"type"`
75 Status corev1.ConditionStatus `json:"status"`
76 Reason string `json:"reason"`
77 StartTime *metav1.Time `json:"startTime,omitempty"`
78 }
79
80 type TemplateType string
81
82 const (
83 TypeTask TemplateType = "Task"
84 TypeSerial TemplateType = "Serial"
85 TypeParallel TemplateType = "Parallel"
86 TypeSuspend TemplateType = "Suspend"
87 TypeSchedule TemplateType = "Schedule"
88 TypeStatusCheck TemplateType = "StatusCheck"
89 )
90
91 func IsChaosTemplateType(target TemplateType) bool {
92 return contains(allChaosTemplateType, target)
93 }
94
95 func contains(arr []TemplateType, target TemplateType) bool {
96 for _, item := range arr {
97 if item == target {
98 return true
99 }
100 }
101 return false
102 }
103
104 type Template struct {
105 Name string `json:"name"`
106 Type TemplateType `json:"templateType"`
107
108 Deadline *string `json:"deadline,omitempty"`
109
110
111 Task *Task `json:"task,omitempty"`
112
113
114 Children []string `json:"children,omitempty"`
115
116
117 ConditionalBranches []ConditionalBranch `json:"conditionalBranches,omitempty"`
118
119
120 *EmbedChaos `json:",inline"`
121
122
123 Schedule *ChaosOnlyScheduleSpec `json:"schedule,omitempty"`
124
125
126 StatusCheck *StatusCheckSpec `json:"statusCheck,omitempty"`
127
128
129
130 AbortWithStatusCheck bool `json:"abortWithStatusCheck,omitempty"`
131 }
132
133
134
135 type ChaosOnlyScheduleSpec struct {
136 Schedule string `json:"schedule"`
137
138
139
140
141 StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds"`
142
143
144
145 ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy"`
146
147
148
149 HistoryLimit int `json:"historyLimit,omitempty"`
150
151 Type ScheduleTemplateType `json:"type"`
152
153 EmbedChaos `json:",inline"`
154 }
155
156 type Task struct {
157
158 Container *corev1.Container `json:"container,omitempty"`
159
160
161
162
163 Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
164
165
166 }
167
168
169 type WorkflowList struct {
170 metav1.TypeMeta `json:",inline"`
171 metav1.ListMeta `json:"metadata,omitempty"`
172 Items []Workflow `json:"items"`
173 }
174
175 func (in *WorkflowList) GetItems() []GenericChaos {
176 var result []GenericChaos
177 for _, item := range in.Items {
178 item := item
179 result = append(result, &item)
180 }
181 return result
182 }
183
184
185 func (in *WorkflowList) DeepCopyList() GenericChaosList {
186 return in.DeepCopy()
187 }
188
189 func init() {
190 SchemeBuilder.Register(&Workflow{}, &WorkflowList{})
191 }
192
193 func FetchChaosByTemplateType(templateType TemplateType) (runtime.Object, error) {
194 if kind, ok := all.kinds[string(templateType)]; ok {
195 return kind.SpawnObject(), nil
196 }
197 return nil, errors.Wrapf(errInvalidValue, "unknown template type %s", templateType)
198 }
199