-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-test-operator.yml
178 lines (155 loc) · 6.92 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
---
- name: Test the operator on a OCP 4.0 cluster with OLM
hosts: all
become: false
gather_facts: false
vars:
run_prereqs: true
run_lint: true
run_catalog_init: true
run_deploy: true
run_scorecard: true
run_imagesource: true
run_cleanup: true
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
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"
testing_bin_path: "{{ work_dir }}/bin"
oc_bin_path: "{{ 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"
offline_cataloger_bin_path: "offline-cataloger"
- 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
- name: "Create the scorecard CR directory"
file:
path: "{{ scorecard_cr_dir }}"
state: directory
when: run_scorecard|bool
- name: "Install operator testing prerequisites"
include_role:
name: install_operator_prereqs
when: run_prereqs|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 }}"
- name: "Parse operator metadata needed to run the tests"
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
- 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
- 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
- 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
- set_fact:
openshift_images_before: " {{ os_registry_is_result_before.stdout_lines }} + {{ os_pod_is_result_before.stdout_lines }}"
- name: "Deploy the operator on the OpenShift 4.0 cluster with OLM"
include_role:
name: deploy_olm_operator
when: run_deploy|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
- 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
- set_fact:
openshift_images_after: "{{ os_registry_is_result_after.stdout_lines }} + {{ os_pod_is_result_after.stdout_lines }}"
- 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 != ""
- 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
when:
- run_deploy|bool
always:
- name: "Cleanup created resources on the OCP 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
no_log: true