forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskset_test.go
335 lines (322 loc) · 9.74 KB
/
taskset_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
package controller
import (
"context"
"strings"
"testing"
"github.com/stretchr/testify/assert"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/workflow/common"
)
func TestCreateTaskSet(t *testing.T) {
wf := wfv1.MustUnmarshalWorkflow(`apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: http-template
namespace: default
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: good
template: http
arguments:
parameters: [{name: url, value: "https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json"}]
- - name: bad
template: http
continueOn:
failed: true
arguments:
parameters: [{name: url, value: "http:https://openlibrary.org/people/george08/nofound.json"}]
- name: http
inputs:
parameters:
- name: url
http:
url: "{{inputs.parameters.url}}"
`)
ctx := context.Background()
var ts wfv1.WorkflowTaskSet
wfv1.MustUnmarshal(`apiVersion: argoproj.io/v1alpha1
kind: WorkflowTaskSet
metadata:
name: http-template-1
namespace: default
spec:
tasks:
http-template-nxvtg-1265710817:
http:
url: http:https://openlibrary.org/people/george08/nofound.json
inputs:
parameters:
- name: url
value: http:https://openlibrary.org/people/george08/nofound.json
name: http
`, &ts)
t.Run("CreateTaskSet", func(t *testing.T) {
cancel, controller := newController(wf, ts)
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
woc.operate(ctx)
tslist, err := woc.controller.wfclientset.ArgoprojV1alpha1().WorkflowTaskSets("default").List(ctx, v1.ListOptions{})
assert.NoError(t, err)
assert.NotEmpty(t, tslist.Items)
assert.Len(t, tslist.Items, 1)
for _, ts := range tslist.Items {
assert.NotNil(t, ts)
assert.Equal(t, ts.Name, wf.Name)
assert.Equal(t, ts.Namespace, wf.Namespace)
assert.Len(t, ts.Spec.Tasks, 1)
}
pods, err := woc.controller.kubeclientset.CoreV1().Pods("default").List(ctx, v1.ListOptions{})
assert.NoError(t, err)
assert.NotEmpty(t, pods.Items)
assert.Len(t, pods.Items, 1)
for _, pod := range pods.Items {
assert.NotNil(t, pod)
assert.True(t, strings.HasSuffix(pod.Name, "-agent"))
}
})
t.Run("CreateTaskSetWithInstanceID", func(t *testing.T) {
cancel, controller := newController(wf, ts)
defer cancel()
controller.Config.InstanceID = "testID"
woc := newWorkflowOperationCtx(wf, controller)
woc.operate(ctx)
tslist, err := woc.controller.wfclientset.ArgoprojV1alpha1().WorkflowTaskSets("default").List(ctx, v1.ListOptions{})
assert.NoError(t, err)
assert.NotEmpty(t, tslist.Items)
assert.Len(t, tslist.Items, 1)
for _, ts := range tslist.Items {
assert.NotNil(t, ts)
assert.Equal(t, ts.Name, wf.Name)
assert.Equal(t, ts.Namespace, wf.Namespace)
assert.Len(t, ts.Spec.Tasks, 1)
}
pods, err := woc.controller.kubeclientset.CoreV1().Pods("default").List(ctx, v1.ListOptions{})
assert.NoError(t, err)
assert.NotEmpty(t, pods.Items)
assert.Len(t, pods.Items, 1)
for _, pod := range pods.Items {
assert.NotNil(t, pod)
assert.True(t, strings.HasSuffix(pod.Name, "-agent"))
assert.Equal(t, "testID", pod.ObjectMeta.Labels[common.LabelKeyControllerInstanceID])
}
})
}
func TestRemoveCompletedTaskSetStatus(t *testing.T) {
wf := wfv1.MustUnmarshalWorkflow(`apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: http-template-1
namespace: default
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: good
template: http
arguments:
parameters: [{name: url, value: "https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json"}]
- - name: bad
template: http
continueOn:
failed: true
arguments:
parameters: [{name: url, value: "http:https://openlibrary.org/people/george08/nofound.json"}]
- name: http
inputs:
parameters:
- name: url
http:
url: "{{inputs.parameters.url}}"
status:
artifactRepositoryRef:
artifactRepository:
archiveLogs: true
s3:
accessKeySecret:
key: accesskey
name: my-minio-cred
bucket: my-bucket
endpoint: minio:9000
insecure: true
secretKeySecret:
key: secretkey
name: my-minio-cred
configMap: artifact-repositories
key: default-v1
namespace: argo
conditions:
- status: "False"
type: PodRunning
finishedAt: null
nodes:
http-template-fqgsf:
children:
- http-template-fqgsf-898749974
displayName: http-template-fqgsf
finishedAt: null
id: http-template-fqgsf
name: http-template-fqgsf
phase: Running
startedAt: "2021-07-20T16:05:13Z"
templateName: main
templateScope: local/http-template-fqgsf
type: Steps
http-template-fqgsf-898749974:
boundaryID: http-template-fqgsf
children:
- http-template-fqgsf-2338098285
- http-template-fqgsf-3753847819
displayName: '[0]'
finishedAt: null
id: http-template-fqgsf-898749974
name: http-template-fqgsf[0]
phase: Running
startedAt: "2021-07-20T16:05:13Z"
templateScope: local/http-template-fqgsf
type: StepGroup
http-template-fqgsf-2338098285:
boundaryID: http-template-fqgsf
displayName: good
finishedAt: null
id: http-template-fqgsf-2338098285
inputs:
parameters:
- name: url
value: https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json
name: http-template-fqgsf[0].good
outputs:
parameters:
- name: result
value: |
{
"swagger": "2.0",
"info": {
"title": "pkg/apis/workflow/v1alpha1/generated.proto",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {}
}
phase: Succeeded
startedAt: "2021-07-20T16:05:13Z"
templateName: http
templateScope: local/http-template-fqgsf
type: HTTP
http-template-fqgsf-3753847819:
boundaryID: http-template-fqgsf
displayName: bad
finishedAt: null
id: http-template-fqgsf-3753847819
inputs:
parameters:
- name: url
value: http:https://openlibrary.org/people/george08/nofound.json
message: 404 Not Found
name: http-template-fqgsf[0].bad
phase: Failed
startedAt: "2021-07-20T16:05:13Z"
templateName: http
templateScope: local/http-template-fqgsf
type: HTTP
phase: Running
progress: 0/0
startedAt: "2021-07-20T16:05:13Z"
`)
ctx := context.Background()
var ts wfv1.WorkflowTaskSet
wfv1.MustUnmarshal(`apiVersion: argoproj.io/v1alpha1
kind: WorkflowTaskSet
metadata:
name: http-template-1
namespace: default
spec:
tasks:
http-template-fqgsf-2338098285:
http:
url: http:https://openlibrary.org/people/george08/nofound.json
inputs:
parameters:
- name: url
value: http:https://openlibrary.org/people/george08/nofound.json
name: http
status:
nodes:
http-template-fqgsf-2338098285:
outputs:
parameters:
- name: result
value: |
{
"swagger": "2.0",
"info": {
"title": "pkg/apis/workflow/v1alpha1/generated.proto",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {}
}
phase: Succeeded
http-template-fqgsf-3753847819:
message: 404 Not Found
phase: Failed
`, &ts)
t.Run("RemoveCompletedTaskSetStatus", func(t *testing.T) {
cancel, controller := newController(wf, ts)
defer cancel()
_, err := controller.wfclientset.ArgoprojV1alpha1().WorkflowTaskSets("default").Create(ctx, &ts, v1.CreateOptions{})
assert.NoError(t, err)
woc := newWorkflowOperationCtx(wf, controller)
err = woc.removeCompletedTaskSetStatus(ctx)
assert.NoError(t, err)
tslist, err := woc.controller.wfclientset.ArgoprojV1alpha1().WorkflowTaskSets("default").List(ctx, v1.ListOptions{})
assert.NoError(t, err)
assert.NotEmpty(t, tslist.Items)
assert.Len(t, tslist.Items, 1)
for _, ts := range tslist.Items {
assert.NotNil(t, ts)
assert.Equal(t, ts.Name, wf.Name)
assert.Equal(t, ts.Namespace, wf.Namespace)
assert.Len(t, ts.Spec.Tasks, 0)
assert.Len(t, ts.Status.Nodes, 0)
}
})
}
func TestNonHTTPTemplateScenario(t *testing.T) {
cancel, controller := newController()
defer cancel()
wf := wfv1.MustUnmarshalWorkflow(helloWorldWf)
woc := newWorkflowOperationCtx(wf, controller)
ctx := context.Background()
t.Run("taskSetReconciliation", func(t *testing.T) {
woc.operate(ctx)
err := woc.taskSetReconciliation(ctx)
assert.NoError(t, err)
})
t.Run("completeTaskSet", func(t *testing.T) {
woc.operate(ctx)
err := woc.completeTaskSet(ctx)
assert.NoError(t, err)
})
t.Run("removeCompletedTaskSetStatus", func(t *testing.T) {
woc.operate(ctx)
err := woc.removeCompletedTaskSetStatus(ctx)
assert.NoError(t, err)
})
}