-
Notifications
You must be signed in to change notification settings - Fork 40
/
local-test-operator.yml
325 lines (290 loc) · 10.4 KB
/
local-test-operator.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
---
- name: Test the operator on a kind/OCP 4.0 cluster with OLM
hosts: all
become: false
gather_facts: false
vars:
run_prereqs: true
run_upstream: false
run_lint: true
run_catalog_init: true
run_deploy: true
run_scorecard: true
run_imagesource: true
run_cleanup: true
run_remove_catalog_repo: true
run_manifest_test: false
scorecard_first_cr: true
openshift_namespace: "test-operator"
work_dir: "/tmp/operator-test"
testing_bin_path: "{{ work_dir }}/bin"
current_channel: >
'' # Added to avoid a potential
bug with undefined variables
olm_ver: 0.14.1
events_file_path: "{{ work_dir }}/events.json"
environment:
PATH: "{{ ansible_env.PATH }}:{{ ansible_env.HOME }}/.local/bin"
when: run_upstream|bool
pre_tasks:
- setup:
tags:
- always
when: run_upstream|bool
tasks:
- set_fact:
operator_work_dir: "{{ work_dir }}/operator-files"
olm_operator_files_path: "{{ work_dir }}/olm-operator-files"
scorecard_cr_dir: "{{ work_dir }}/scorecard-cr-files"
kube_objects_dir: "{{ work_dir }}/kube_objects"
testing_bin_path: "{{ work_dir }}/bin"
oc_bin_path: >
'{{ ''kubectl'' if run_upstream else
"{{ testing_bin_path }}/oc" }}'
jq_bin_path: "{{ testing_bin_path }}/jq"
yq_bin_path: "{{ testing_bin_path }}/yq"
go_bin_path: "{{ testing_bin_path }}/go/bin/go"
operator_sdk_bin_path: "{{ testing_bin_path }}/operator-sdk"
- name: "Clear the operator working directory"
file:
path: "{{ operator_work_dir }}"
state: absent
- name: "Clear the scorecard CR directory"
file:
path: "{{ scorecard_cr_dir }}"
state: absent
when:
- run_scorecard|bool
- not run_upstream|bool
- name: "Create the scorecard CR directory"
file:
path: "{{ scorecard_cr_dir }}"
state: directory
mode: 0744
when:
- run_scorecard|bool
- not run_upstream|bool
- name: "Install operator testing prerequisites"
include_role:
name: install_operator_prereqs
when: run_prereqs|bool
- name: "OLM"
block:
- name: "Check if OLM is needed"
shell: "{{ oc_bin_path }} api-resources | grep -o operatorgroup"
register: olm_needed
ignore_errors: true
- name: "Install OLM"
block:
- name: "Installing OLM"
shell: >
"{{ operator_sdk_bin_path }}
olm install --version {{ olm_ver }}"
- name: "Delete catalogsource"
shell: >
"{{ oc_bin_path }} delete catalogsource
operatorhubio-catalog -n olm"
ignore_errors: true
when:
- olm_needed.stdout != "operatorgroup"
when: run_upstream|bool
- name: "Build upstream catalog"
include_role:
name: build_catalog_upstream
when: run_upstream|bool
- name: >
"Run operator-courier nest to copy the
operator metadata in nested format to the work dir"
shell: "operator-courier nest {{ operator_dir }} {{ operator_work_dir }}"
when: not run_upstream|bool
- name: Copy the operator metadata in nested format to the work dir
copy:
src: "{{ operator_dir }}/"
dest: "{{ operator_work_dir }}"
remote_src: true
mode: 0644
when: run_upstream|bool
- name: "Parse operator metadata needed to run the tests (Openshift)"
include_role:
name: parse_operator_metadata
- name: >
"Run linting tests with operator-courier
verify on the deployed operator"
include_role:
name: operator_courier_verify
when: run_lint|bool
- name: "Run catalog initialization test on operator metadata"
include_role:
name: operator_catalog_initialization_test
when:
- run_catalog_init|bool
- not run_upstream|bool
- name: "Operator deployment and scorecard/imagesource tests"
block:
- name: "Inject operator scorecard data into the operator metadata"
include_role:
name: inject_scorecard_metadata
when:
- run_scorecard|bool
- not run_upstream|bool
- name: >
"Get all registry images on the OpenShift
cluster before deploying the operator"
shell: >
"{{ oc_bin_path }} get is --all-namespaces
-o json | jq '.items[].spec.tags[] |
select(.from.kind == \"DockerImage\") |
.from.name' --raw-output | sort -u"
register: os_registry_is_result_before
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
no_log: true
when: not run_upstream|bool
- name: >
"Get all pod images on the OpenShift
cluster before deploying the operator"
shell: >
"{{ oc_bin_path }} get pods --all-namespaces
-o json | jq '.items[].spec.containers[].image'
--raw-output | sort -u"
register: os_pod_is_result_before
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
no_log: true
when: not run_upstream|bool
- set_fact:
openshift_images_before: >
" {{ os_registry_is_result_before.stdout_lines
}} + {{ os_pod_is_result_before.stdout_lines }}"
when: not run_upstream|bool
- name: "Set the deployment start time"
shell: "date -u '+%Y-%m-%dT%H:%M:%SZ'"
register: start_time
when:
- run_deploy|bool
- not run_upstream|bool
- name: "Deploy the operator on the OpenShift 4.0 with OLM"
include_role:
name: deploy_olm_operator
when:
- run_deploy|bool
- not run_upstream|bool
- name: "Collect the names of the images modified during the deployment"
include_role:
name: collect_modified_images
vars:
deployment_start_time: "{{ start_time }}"
events_file_path: "{{ events_file_path }}"
kubeconfig_path: "{{ kubeconfig_path }}"
when:
- run_deploy|bool
- not run_upstream|bool
- name: "Deploy the operator on the Kind cluster with OLM"
include_role:
name: deploy_olm_operator_upstream
when:
- run_deploy|bool
- run_upstream|bool
- name: "Get all openshift registry images"
shell: >
"{{ oc_bin_path }} get is --all-namespaces
-o json | jq '.items[].spec.tags[] |
select(.from.kind == \"DockerImage\") |
.from.name' --raw-output | sort -u"
register: os_registry_is_result_after
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
no_log: true
when: not run_upstream|bool
- name: "Get all OpenShift pod images"
shell: >
"{{ oc_bin_path }} get pods --all-namespaces
-o json | jq '.items[].spec.containers[].image'
--raw-output | sort -u"
register: os_pod_is_result_after
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
no_log: true
when: not run_upstream|bool
- set_fact:
openshift_images_after: >
"{{ os_registry_is_result_after.stdout_lines }}
+ {{ os_pod_is_result_after.stdout_lines }}"
when: not run_upstream|bool
- name: "Scorecard test"
block:
- name: "Find all extracted CRs from alm-examples"
shell: >
"find \"{{ scorecard_cr_dir }}\"
-name \"*.cr.yaml\" -print"
register: scorecard_cr_files_result
when:
- run_scorecard|bool
- run_deploy|bool
- name: "Run scorecard tests on the deployed operator"
include_role:
name: operator_scorecard_tests
with_items: "{{ scorecard_cr_files_result.stdout_lines }}"
loop_control:
loop_var: cr_path
when:
- run_scorecard|bool
- run_deploy|bool
always:
- name: >
"Get the pod container logs of the
operator after running scorecard tests"
shell: >
"{{ oc_bin_path }} get --output=name pods
| grep {{ operator_pod_name }} | xargs -I{}
{{ oc_bin_path }} logs {} -c {{
operator_container_name }}"
register: operator_container_result
ignore_errors: true
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
no_log: true
- name: "Output the operator container log to a debug file"
copy:
content: "{{ operator_container_result.stdout }}"
dest: "{{ work_dir }}/scorecard-operator-container-debug.txt"
when:
- operator_container_result.stdout != ""
when: not run_upstream|bool
- name: >
"Test image sources of containers
introduced with the testing operator"
include_role:
name: operator_imagesource_test
vars:
operator_images: >
"{{ openshift_images_after |
difference(openshift_images_before) | list }}"
when:
- run_imagesource|bool
- run_deploy|bool
- not run_upstream|bool
when:
- run_deploy|bool
always:
- name: "Cleanup created resources on the OCP/kind cluster"
include_role:
name: cleanup_operator_resources
when:
- run_cleanup|bool
- run_deploy|bool
- name: >
"Remove the quay release of the
test operator in the testing namespace"
shell: >
"curl -s -H \"Authorization: basic {{ quay_token }}\"
-X DELETE https://quay.io/cnr/api/v1/packages/{{
quay_namespace }}/{{ package_name }}-test/{{
quay_release }}/helm"
when:
- quay_release is defined
- package_name is defined
- run_cleanup|bool
- run_deploy|bool
- not run_upstream|bool
no_log: true