Skip to content

Commit d511884

Browse files
authored
Merge pull request #157 from LikhithaEda/local
CVP-1871 Enable more checks for ansible linting in upstream playbooks
2 parents 6f4c417 + aafbc79 commit d511884

File tree

68 files changed

+528
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+528
-383
lines changed

.ansible-lint

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
exclude_paths:
33
- .cache/ # implicit unless exclude_paths is defined in config
44
- .github/
5-
- roles/
65
- Dockerfiles
7-
- ./*.yml
6+
- yamllint.yml
87

9-
warn_list: [] # or 'skip_list' to silence them completely
8+
warn_list: [] # or 'skip_list' to silence them completely
109

1110
skip_list:
1211
- deprecated-command-syntax # Using command rather than an argument to e.g. file
@@ -17,4 +16,14 @@ skip_list:
1716
- command-instead-of-shell # Use shell only when shell functionality is required
1817
# - yaml # Violations reported by yamllint
1918
- line-length
20-
- comments
19+
- '102' # No Jinja2
20+
- '206' # Variables should have spaces before and after: {{ var_name}}
21+
- '301' # All tasks should be named
22+
- '302' # Include should has tags
23+
- '303' # Use ":" YAML syntax when arguments are over 4
24+
- '305' # Variable should has space "{{ foo }}"
25+
- '306' # Shells that use pipes should set the pipefail option
26+
- '403' # Package installs should not use latest
27+
- '502' # Use chown module
28+
- '601' # trailing whitespace
29+
- '602' # line too long

ansible-lint.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

deploy-olm-operator.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
2-
- name: Deploy the operator on an OCP cluster with OLM as part of the operator testing pipeline
2+
- name: >
3+
Deploy the operator on an OCP
4+
cluster with OLM as part of the
5+
operator testing pipeline
36
hosts: all
47
become: false
58
gather_facts: false
@@ -15,27 +18,28 @@
1518
quay_token: "{{ quay_token }}"
1619
quay_namespace: "cvpops"
1720
oc_bin_path: "{{ 'kubectl' if run_upstream else 'oc' }}"
18-
jq_bin_path : "/usr/bin/jq"
21+
jq_bin_path: "/usr/bin/jq"
1922
yq_bin_path: "/usr/local/bin/yq"
2023
testing_bin_path: "/usr/local/bin"
2124
scorecard_first_cr: true
2225
run_scorecard: true
23-
current_channel: '' # Added to avoid a bug with undefined variables
24-
26+
current_channel: '' # Added to avoid a bug with undefined variables
2527

2628

2729
tasks:
2830
- name: "Login to the testing OpenShift instance"
29-
shell: "{{ oc_bin_path }} login {{ openshift_url }} -u system:admin --insecure-skip-tls-verify"
31+
shell: >
32+
"{{ oc_bin_path }} login {{ openshift_url }}
33+
-u system:admin --insecure-skip-tls-verify"
3034
register: login_result
3135
retries: 20
3236
delay: 10
3337
until: login_result.rc == 0
3438
environment:
3539
KUBECONFIG: "{{ kubeconfig_path }}"
3640
when:
37-
- openshift_url is defined
38-
- not run_upstream|bool
41+
- openshift_url is defined
42+
- not run_upstream|bool
3943

4044
- name: "Parse operator metadata needed to run the tests"
4145
include_role:
@@ -52,8 +56,15 @@
5256
include_role:
5357
name: deploy_olm_operator
5458
always:
55-
- name: "Remove the quay release of the test operator in the testing namespace"
56-
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"
59+
- name: >
60+
"Remove the quay release of the
61+
test operator in the testing namespace"
62+
shell: >
63+
"curl -s -H \"Authorization: basic
64+
{{ quay_token }}\" -X DELETE
65+
https://quay.io/cnr/api/v1/packages/{{
66+
quay_namespace }}/{{ package_name }}-test/{{
67+
quay_release }}/helm"
5768
when:
5869
- quay_release is defined
5970
- package_name is defined

extract-operator-bundle.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
umoci_bin_path: "/usr/local/bin/umoci"
1616

1717
tasks:
18-
- name: "Extract the operator bundle image into files needed to run the tests"
18+
- name: >
19+
"Extract the operator bundle
20+
image into files needed to run the tests"
1921
include_role:
2022
name: extract_operator_bundle
2123

local-test-operator-bundle.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
run_catalog_init: true
1313
work_dir: "/tmp/operator-test"
1414
testing_bin_path: "{{ work_dir }}/bin"
15-
current_channel: '' # Added to avoid a potential bug with undefined variables
15+
current_channel: >
16+
'' # Added to avoid a potential
17+
bug with undefined variables
1618
olm_ver: 0.14.1
1719

1820
tasks:
@@ -24,7 +26,9 @@
2426
umoci_bin_path: "{{ testing_bin_path }}/umoci"
2527
opm_bin_path: "{{ testing_bin_path }}/opm"
2628
operator_sdk_bin_path: "{{ testing_bin_path }}/operator-sdk"
27-
oc_bin_path: '{{ ''kubectl'' if run_upstream else "{{ testing_bin_path }}/oc" }}'
29+
oc_bin_path: >
30+
'{{ ''kubectl'' if run_upstream
31+
else "{{ testing_bin_path }}/oc" }}'
2832
2933
3034
- name: "Install operator testing prerequisites"
@@ -37,7 +41,9 @@
3741
name: build_image_bundle
3842
when: run_upstream|bool
3943

40-
- name: "Extract the operator bundle image into files needed to run the tests"
44+
- name: >
45+
"Extract the operator bundle image
46+
into files needed to run the tests"
4147
include_role:
4248
name: extract_operator_bundle
4349
@@ -64,10 +70,14 @@
6470
- name: "Install OLM"
6571
block:
6672
- name: "Installing OLM"
67-
shell: "{{ operator_sdk_bin_path }} olm install --version {{ olm_ver }}"
73+
shell: >
74+
"{{ operator_sdk_bin_path }} olm
75+
install --version {{ olm_ver }}"
6876
6977
- name: "Delete catalogsource"
70-
shell: "{{ oc_bin_path }} delete catalogsource operatorhubio-catalog -n olm"
78+
shell: >
79+
"{{ oc_bin_path }} delete catalogsource
80+
operatorhubio-catalog -n olm"
7181
ignore_errors: true
7282
when:
7383
- olm_needed.stdout != "operatorgroup"

local-test-operator.yml

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
openshift_namespace: "test-operator"
2020
work_dir: "/tmp/operator-test"
2121
testing_bin_path: "{{ work_dir }}/bin"
22-
current_channel: '' # Added to avoid a potential bug with undefined variables
22+
current_channel: >
23+
'' # Added to avoid a potential
24+
bug with undefined variables
2325
olm_ver: 0.14.1
2426
events_file_path: "{{ work_dir }}/events.json"
2527

@@ -39,7 +41,9 @@
3941
scorecard_cr_dir: "{{ work_dir }}/scorecard-cr-files"
4042
kube_objects_dir: "{{ work_dir }}/kube_objects"
4143
testing_bin_path: "{{ work_dir }}/bin"
42-
oc_bin_path: '{{ ''kubectl'' if run_upstream else "{{ testing_bin_path }}/oc" }}'
44+
oc_bin_path: >
45+
'{{ ''kubectl'' if run_upstream else
46+
"{{ testing_bin_path }}/oc" }}'
4347
jq_bin_path: "{{ testing_bin_path }}/jq"
4448
yq_bin_path: "{{ testing_bin_path }}/yq"
4549
go_bin_path: "{{ testing_bin_path }}/go/bin/go"
@@ -82,10 +86,14 @@
8286
- name: "Install OLM"
8387
block:
8488
- name: "Installing OLM"
85-
shell: "{{ operator_sdk_bin_path }} olm install --version {{ olm_ver }}"
89+
shell: >
90+
"{{ operator_sdk_bin_path }}
91+
olm install --version {{ olm_ver }}"
8692
8793
- name: "Delete catalogsource"
88-
shell: "{{ oc_bin_path }} delete catalogsource operatorhubio-catalog -n olm"
94+
shell: >
95+
"{{ oc_bin_path }} delete catalogsource
96+
operatorhubio-catalog -n olm"
8997
ignore_errors: true
9098
when:
9199
- olm_needed.stdout != "operatorgroup"
@@ -96,23 +104,27 @@
96104
name: build_catalog_upstream
97105
when: run_upstream|bool
98106

99-
- name: "Run operator-courier nest to copy the operator metadata in nested format to the work dir"
107+
- name: >
108+
"Run operator-courier nest to copy the
109+
operator metadata in nested format to the work dir"
100110
shell: "operator-courier nest {{ operator_dir }} {{ operator_work_dir }}"
101111
when: not run_upstream|bool
102112
103113
- name: Copy the operator metadata in nested format to the work dir
104114
copy:
105115
src: "{{ operator_dir }}/"
106116
dest: "{{ operator_work_dir }}"
107-
remote_src: yes
117+
remote_src: true
108118
mode: 0644
109119
when: run_upstream|bool
110120

111121
- name: "Parse operator metadata needed to run the tests (Openshift)"
112122
include_role:
113123
name: parse_operator_metadata
114124

115-
- name: "Run linting tests with operator-courier verify on the deployed operator"
125+
- name: >
126+
"Run linting tests with operator-courier
127+
verify on the deployed operator"
116128
include_role:
117129
name: operator_courier_verify
118130
when: run_lint|bool
@@ -133,24 +145,37 @@
133145
- run_scorecard|bool
134146
- not run_upstream|bool
135147

136-
- name: "Get all registry images on the OpenShift cluster before deploying the operator"
137-
shell: "{{ oc_bin_path }} get is --all-namespaces -o json | jq '.items[].spec.tags[] | select(.from.kind == \"DockerImage\") | .from.name' --raw-output | sort -u"
148+
- name: >
149+
"Get all registry images on the OpenShift
150+
cluster before deploying the operator"
151+
shell: >
152+
"{{ oc_bin_path }} get is --all-namespaces
153+
-o json | jq '.items[].spec.tags[] |
154+
select(.from.kind == \"DockerImage\") |
155+
.from.name' --raw-output | sort -u"
138156
register: os_registry_is_result_before
139157
environment:
140158
KUBECONFIG: "{{ kubeconfig_path }}"
141159
no_log: true
142160
when: not run_upstream|bool
143161
144-
- name: "Get all pod images on the OpenShift cluster before deploying the operator"
145-
shell: "{{ oc_bin_path }} get pods --all-namespaces -o json | jq '.items[].spec.containers[].image' --raw-output | sort -u"
162+
- name: >
163+
"Get all pod images on the OpenShift
164+
cluster before deploying the operator"
165+
shell: >
166+
"{{ oc_bin_path }} get pods --all-namespaces
167+
-o json | jq '.items[].spec.containers[].image'
168+
--raw-output | sort -u"
146169
register: os_pod_is_result_before
147170
environment:
148171
KUBECONFIG: "{{ kubeconfig_path }}"
149172
no_log: true
150173
when: not run_upstream|bool
151174
152175
- set_fact:
153-
openshift_images_before: " {{ os_registry_is_result_before.stdout_lines }} + {{ os_pod_is_result_before.stdout_lines }}"
176+
openshift_images_before: >
177+
" {{ os_registry_is_result_before.stdout_lines
178+
}} + {{ os_pod_is_result_before.stdout_lines }}"
154179
when: not run_upstream|bool
155180

156181
- name: "Set the deployment start time"
@@ -186,29 +211,40 @@
186211
- run_upstream|bool
187212

188213
- name: "Get all openshift registry images"
189-
shell: "{{ oc_bin_path }} get is --all-namespaces -o json | jq '.items[].spec.tags[] | select(.from.kind == \"DockerImage\") | .from.name' --raw-output | sort -u"
214+
shell: >
215+
"{{ oc_bin_path }} get is --all-namespaces
216+
-o json | jq '.items[].spec.tags[] |
217+
select(.from.kind == \"DockerImage\") |
218+
.from.name' --raw-output | sort -u"
190219
register: os_registry_is_result_after
191220
environment:
192221
KUBECONFIG: "{{ kubeconfig_path }}"
193222
no_log: true
194223
when: not run_upstream|bool
195224

196225
- name: "Get all OpenShift pod images"
197-
shell: "{{ oc_bin_path }} get pods --all-namespaces -o json | jq '.items[].spec.containers[].image' --raw-output | sort -u"
226+
shell: >
227+
"{{ oc_bin_path }} get pods --all-namespaces
228+
-o json | jq '.items[].spec.containers[].image'
229+
--raw-output | sort -u"
198230
register: os_pod_is_result_after
199231
environment:
200232
KUBECONFIG: "{{ kubeconfig_path }}"
201233
no_log: true
202234
when: not run_upstream|bool
203235

204236
- set_fact:
205-
openshift_images_after: "{{ os_registry_is_result_after.stdout_lines }} + {{ os_pod_is_result_after.stdout_lines }}"
237+
openshift_images_after: >
238+
"{{ os_registry_is_result_after.stdout_lines }}
239+
+ {{ os_pod_is_result_after.stdout_lines }}"
206240
when: not run_upstream|bool
207241

208242
- name: "Scorecard test"
209243
block:
210244
- name: "Find all extracted CRs from alm-examples"
211-
shell: "find \"{{ scorecard_cr_dir }}\" -name \"*.cr.yaml\" -print"
245+
shell: >
246+
"find \"{{ scorecard_cr_dir }}\"
247+
-name \"*.cr.yaml\" -print"
212248
register: scorecard_cr_files_result
213249
when:
214250
- run_scorecard|bool
@@ -224,8 +260,14 @@
224260
- run_scorecard|bool
225261
- run_deploy|bool
226262
always:
227-
- name: "Get the pod container logs of the operator after running scorecard tests"
228-
shell: "{{ oc_bin_path }} get --output=name pods | grep {{ operator_pod_name }} | xargs -I{} {{ oc_bin_path }} logs {} -c {{ operator_container_name }}"
263+
- name: >
264+
"Get the pod container logs of the
265+
operator after running scorecard tests"
266+
shell: >
267+
"{{ oc_bin_path }} get --output=name pods
268+
| grep {{ operator_pod_name }} | xargs -I{}
269+
{{ oc_bin_path }} logs {} -c {{
270+
operator_container_name }}"
229271
register: operator_container_result
230272
ignore_errors: true
231273
environment:
@@ -241,11 +283,15 @@
241283

242284
when: not run_upstream|bool
243285

244-
- name: "Test image sources of containers introduced with the testing operator"
286+
- name: >
287+
"Test image sources of containers
288+
introduced with the testing operator"
245289
include_role:
246290
name: operator_imagesource_test
247291
vars:
248-
operator_images: "{{ openshift_images_after | difference(openshift_images_before) | list }}"
292+
operator_images: >
293+
"{{ openshift_images_after |
294+
difference(openshift_images_before) | list }}"
249295
when:
250296
- run_imagesource|bool
251297
- run_deploy|bool
@@ -262,8 +308,14 @@
262308
- run_cleanup|bool
263309
- run_deploy|bool
264310

265-
- name: "Remove the quay release of the test operator in the testing namespace"
266-
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"
311+
- name: >
312+
"Remove the quay release of the
313+
test operator in the testing namespace"
314+
shell: >
315+
"curl -s -H \"Authorization: basic {{ quay_token }}\"
316+
-X DELETE https://quay.io/cnr/api/v1/packages/{{
317+
quay_namespace }}/{{ package_name }}-test/{{
318+
quay_release }}/helm"
267319
when:
268320
- quay_release is defined
269321
- package_name is defined

0 commit comments

Comments
 (0)