-
Notifications
You must be signed in to change notification settings - Fork 20
/
dci-openshift-agent.yml
626 lines (569 loc) · 17.8 KB
/
dci-openshift-agent.yml
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
---
# Step 0 : DCI setup
- name: 'Set dci variables'
hosts: localhost
tags:
- job
- dci
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
tasks:
- name: Display proxy settings
debug:
msg: "http_proxy={{ http_proxy }} https_proxy={{ https_proxy }} no_proxy={{ no_proxy_list }}"
- name: Read credentials from env vars
set_fact:
dci_client_id: "{{ lookup('env','DCI_CLIENT_ID') }}"
dci_api_secret: "{{ lookup('env','DCI_API_SECRET') }}"
dci_cs_url: "{{ lookup('env','DCI_CS_URL') }}"
dci_ui_url: "{{ lookup('env','DCI_UI_URL') | default('https://www.distributed-ci.io', True) }}"
no_log: "{{ dci_hide_secrets }}"
# Schedule a new job only if not passed via dci-pipeline
- name: Schedule a new job
dci_job:
components: "{{ dci_components }}"
components_by_query: "{{ dci_components_by_query }}"
topic: "{{ dci_topic }}"
comment: "{{ dci_comment }}"
url: "{{ dci_url }}"
name: "{{ dci_name }}"
configuration: "{{ dci_configuration }}"
previous_job_id: "{{ dci_previous_job_id }}"
team_id: "{{ dci_team_id }}"
pipeline_id: "{{ dci_pipeline_id }}"
register: job_info
when: job_info is not defined
- name: Custom OCP build component
when:
- dci_custom_component | default(false) | bool
- dci_custom_component_file is defined
- dci_custom_component_file | length
block:
- name: Load custom build component
set_fact:
custom_component: "{{ lookup('file', dci_custom_component_file) | from_json }}"
- name: Set the job id
set_fact:
job_id: '{{ job_info.job.id }}'
- name: Copy the job_id to the JOB_ID_FILE if it exists
copy:
content: "{{ job_id }}"
dest: "{{ JOB_ID_FILE }}"
mode: "0644"
when: JOB_ID_FILE is defined
# Keep in sync with test-runner parsing
- name: UI URL
debug:
msg: 'Follow the log at: {{ dci_ui_url }}/jobs/{{ hostvars.localhost.job_info.job.id }}/jobStates' # noqa 204
- name: Set DCI tags for the current job
dci_job:
id: '{{ job_id }}'
tags: >
{{ ["agent:openshift"] +
dci_tags +
dci_workarounds +
((dci_main == "upgrade") |
ternary(["upgrade"],["install", "install_type:" + install_type])) }}
- name: Add cluster tag to the current job
dci_job:
id: '{{ job_id }}'
tags:
- cluster:{{ cluster }}
when: cluster is defined
- name: Count workarounds
dci_job:
id: "{{ job_id }}"
key: "workarounds"
value: "{{ dci_workarounds | length }}"
- name: Debug components
debug:
msg: "{{ job_info.job.components + [custom_component] if custom_component is defined else job_info.job.components }}"
- name: Get openshift_version from job.components
set_fact:
ocp_tags: "{{ item['tags'] }}"
url: "{{ item['url'] | regex_replace('\\/$', '') }}"
version: "{{ item.version }}"
version_pull_url: "{{ item['data']['pull_url'] }}"
ocp_product_id: "{{ item['id'] }}"
with_items: "{{ job_info.job.components + [custom_component] if custom_component is defined else job_info.job.components }}"
when: item["type"] == "ocp"
- name: Get build from tag
set_fact:
build: "{{ item.split(':')[1] }}"
with_items: "{{ ocp_tags }}"
when: item.split(":")[0] == "build"
# Candidate builds are ga builds that haven't gone ga quite yet.
# The following changes the build and version vars to look like ga
# for the upstream install playbooks. The dci-feeder adds '-0.rc-$TIMESTAMP'
# to the version, we have to strip it here.
- name: Set build:ga when build:candidate
set_fact:
build: "ga"
when: build == "candidate"
- name: Pre-run
dci_job:
id: "{{ job_id }}"
status: "pre-run"
- name: "Requirements for ACM install_type"
when:
- install_type == 'acm'
block:
- name: "Read HUB_KUBECONFIG path from env vars"
set_fact:
hub_kubeconfig_path: "{{ lookup('env','HUB_KUBECONFIG') }}"
when: hub_kubeconfig_path is not defined
- name: "Check if HUB_KUBECONFIG path exists"
stat:
path: "{{ hub_kubeconfig_path }}"
register: hub_kubeconfig
- name: "Fail if hub_kubeconfig NOT found"
fail:
msg: "hub_kubeconfig not found at {{ hub_kubeconfig_path }}"
when: not hub_kubeconfig.stat.exists
# Step 1a : pre run
- name: 'Launch pre-run'
hosts: localhost
tags:
- pre-run
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
tasks:
- name: Pre-run
block:
- name: Configure jumpbox
include_tasks: plays/configure-jumpbox.yml
- name: "Setup job_logs directory"
include_tasks: plays/log-dir.yml
when: job_logs is undefined
- name: Run the pre-run
include_tasks: plays/pre-run.yml
when:
- install_type not in ['assisted', 'acm']
- name: "ACM pre-run"
include_tasks:
file: plays/acm-pre-run.yml
apply:
environment:
KUBECONFIG: "{{ hub_kubeconfig_path }}"
tags:
- acm-pre-run
when:
- install_type == 'acm'
rescue: &teardown_error
- name: Run the teardown error handler
delegate_to: localhost
ignore_unreachable: true
block:
- name: Error
dci_job:
id: "{{ hostvars.localhost.job_id }}"
status: "error"
tags: [dci]
delegate_to: localhost
- name: Teardown hooks
when: dci_teardown_on_failure|bool
delegate_to: localhost
ignore_unreachable: true
ignore_errors: true
block:
- name: Run the teardown hooks
include_tasks: "{{ hookdir }}/hooks/teardown.yml"
loop: "{{ dci_config_dirs | reverse | list }}"
loop_control:
loop_var: hookdir
- name: Run the teardown play
include_tasks: plays/teardown.yml
always:
- name: Run the error process
include_tasks: plays/failure.yml
- name: Assited pre-run
import_playbook: plays/assisted-pre-run.yml
when:
- install_type == 'assisted'
# Step 1b : hook pre run
- name: 'Launch hook pre-run'
hosts: localhost
tags:
- pre-run
- hook-pre-run
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
tasks:
- name: Pre-run hooks
block:
- name: Run the pre-run hook
include_tasks: '{{ hookdir }}/hooks/pre-run.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
rescue: *teardown_error
# Step 1c : Set status to "running"
- name: 'Set running'
hosts: localhost
tags:
- running
tasks:
- name: Running
dci_job:
id: "{{ hostvars.localhost.job_id }}"
status: "running"
delegate_to: localhost
tags: [dci]
# Step 2 : configure
- name: 'Launch configure'
hosts: provisioner
tags:
- running
- configure
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
tasks:
- name: Configure
when:
- install_type != 'acm'
block:
# Prepare provisioner host
- name: Configure provisioner
include_tasks: plays/configure-provisioner.yml
when: ansible_distribution_major_version == '8'
- name: Launch configure
include_tasks: '{{ hookdir }}/hooks/configure.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
rescue: *teardown_error
# Step 3a-1 : installing
- name: 'Launch [IPI/SNO/UPI] install'
hosts: provisioner
tags:
- running
- installing
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
tasks:
- name: Install IPI/SNO/UPI
block:
- name: Launch install {{ install_type }}
include_tasks: "plays/{{ install_type }}-install.yml"
when:
- dci_main == 'install'
- install_type in ['ipi', 'upi', 'sno']
- name: "Get KUBECONFIG auth/creds from provisioner node"
fetch:
src: "{{ item }}"
dest: "{{ dci_cluster_configs_dir }}/"
flat: true
loop:
- "{{ dir }}/auth/kubeconfig"
- "{{ dir }}/auth/kubeadmin-password"
when:
- dci_main == 'install'
- install_type in ['ipi', 'upi', 'sno']
rescue: &teardown_failure
- name: Run the teardown failure handler
delegate_to: localhost
ignore_unreachable: true
block:
- name: Failure
dci_job:
id: "{{ hostvars.localhost.job_id }}"
status: "failure"
delegate_to: localhost
tags: [dci]
- name: Run the failure process for partners
include_tasks: "{{ hookdir }}/hooks/failure.yml"
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
ignore_errors: true
- name: Teardown Hooks
when: dci_teardown_on_failure|bool
delegate_to: localhost
ignore_unreachable: true
ignore_errors: true
block:
- name: Run the teardown hooks
include_tasks: "{{ hookdir }}/hooks/teardown.yml"
loop: "{{ dci_config_dirs | reverse | list }}"
loop_control:
loop_var: hookdir
- name: Run the teardown play
include_tasks: plays/teardown.yml
always:
- name: Run the failure process
include_tasks: plays/failure.yml
# Step 3a-1 : installing
- name: 'Launch ACM install'
hosts: localhost
tags:
- running
- installing
- acm
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
tasks:
- name: Install ACM
block:
- name: "ACM Installation"
include_tasks:
file: plays/acm-install.yml
apply:
environment:
KUBECONFIG: "{{ hub_kubeconfig_path }}"
tags:
- acm-install
when:
- install_type == 'acm'
rescue: *teardown_failure
# Step 3a-1 : installing
- name: 'Launch Assisted Install'
import_playbook: plays/assisted-install.yml
when:
- install_type == 'assisted'
# Step 3a-1 : installing
- name: 'Launch after install'
hosts: localhost
tags:
- running
- installing
- after
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: After Install
block:
- name: "Launch after install"
include_tasks: "plays/after-install.yml"
when:
- dci_main == 'install'
rescue: *teardown_failure
# Step 3a-2 : deploy operators
- name: 'Deploy operators to OCP cluster'
hosts: localhost
tags:
- running
- operator-deployment
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Deploy operators
when:
- dci_main == 'install'
- acm_cluster_type | default('') != 'hypershift'
block:
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
- name: "Setup job_logs directory"
include_tasks: plays/log-dir.yml
when: job_logs is undefined
- name: "Deploy operators"
include_tasks: plays/deploy-operators.yml
rescue: *teardown_failure
# Step 3a-3 : hook installing
- name: 'Launch hook install'
hosts: localhost
tags:
- running
- hook-installing
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Install Hooks
when:
- dci_main == 'install'
- acm_cluster_type | default('') != 'hypershift'
block:
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
- name: "Launch partner install"
include_tasks: '{{ hookdir }}/hooks/install.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
rescue: *teardown_failure
# Step 3b-1 : upgrading
- name: 'Launch upgrade'
hosts: localhost
tags:
- running
- upgrading
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Upgrade
when:
- dci_main == 'upgrade'
block:
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
- name: "Launch upgrade"
include_tasks: plays/upgrade.yml
rescue: *teardown_failure
# Step 3b-2 : hook upgrading
- name: 'Launch hook upgrade'
hosts: localhost
tags:
- running
- hook-upgrading
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Upgrade Hooks
when:
- dci_main == 'upgrade'
block:
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
- name: "Launch partner upgrade"
include_tasks: '{{ hookdir }}/hooks/upgrade.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
rescue: *teardown_failure
# Step 4 : Red Hat testing
- name: 'Launch Red Hat tests'
hosts: localhost
tags:
- running
- testing
- redhat-testing
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Red Hat tests
when:
- install_type != 'acm'
block:
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
- name: "Setup job_logs directory"
include_tasks: plays/log-dir.yml
when: job_logs is undefined
- name: "Launch Red Hat tests"
include_tasks: plays/tests.yml
rescue: *teardown_failure
# Step 5 : partner testing
- name: 'Launch partner tests'
hosts: localhost
tags:
- running
- testing
- partner-testing
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Test Hooks
when:
- acm_cluster_type | default('') != 'hypershift'
block:
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
- name: "Setup job_logs directory"
include_tasks: plays/log-dir.yml
when: job_logs is undefined
- name: Run the partner tests
include_tasks: '{{ hookdir }}/hooks/tests.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
- name: "Run cluster health checks"
include_tasks: plays/check-cluster-health.yml
rescue: *teardown_failure
- name: Post-run
dci_job:
id: "{{ job_id }}"
status: "post-run"
tags: [dci]
# Step 6 : post run
- name: Launch post run
hosts: localhost
tags:
- post-run
- dci
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Post-run
block:
- name: Run the partner post-run
include_tasks: '{{ hookdir }}/hooks/post-run.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
- name: Run the post-run
include_tasks: plays/post-run.yml
rescue: *teardown_error
- name: Success
dci_job:
id: "{{ job_id }}"
status: "success"
tags: [dci]
# Step 7 : state "success"
- name: 'Success'
hosts: localhost
tags:
- success
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy_list }}"
KUBECONFIG: "{{ kubeconfig_path }}"
tasks:
- name: Success
ignore_unreachable: true
ignore_errors: true
block:
- name: Run the success hook
include_tasks: '{{ hookdir }}/hooks/success.yml'
loop: "{{ dci_config_dirs }}"
loop_control:
loop_var: hookdir
- name: Run the success
include_tasks: plays/success.yml
- name: Teardown on success
when: dci_teardown_on_success | bool
block:
- name: Run the teardown hooks
include_tasks: "{{ hookdir }}/hooks/teardown.yml"
loop: "{{ dci_config_dirs | reverse | list }}"
loop_control:
loop_var: hookdir
- name: Run the teardown play
include_tasks: plays/teardown.yml
...