Skip to content

Commit 7341453

Browse files
authored
Bugfix: install sonobuoy executable in playbook (#924)
* Bugfix: install sonobuoy executable in playbook Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * factor our sonobuoy download url as variable something similar was suggested by @berendt Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * remove whitespace from url Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * use ansible_user_dir Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * use ansible user dir even more Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * smarter search for Sonobuoy executable Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> --------- Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 6ed50e1 commit 7341453

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

.zuul.d/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
kaas: false
3636
do_provision: false
3737
do_cleanup: true
38+
sonobuoy_tar_gz_url: >
39+
https://github.com/vmware-tanzu/sonobuoy/releases/download/v0.57.3/sonobuoy_0.57.3_linux_amd64.tar.gz
3840
pre-run:
3941
- playbooks/pre.yaml
4042
- playbooks/pre_cloud.yaml

Tests/kaas/sonobuoy_handler/sonobuoy_handler.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import os
5+
import os.path
56
import shlex
67
import shutil
78
import subprocess
@@ -11,6 +12,16 @@
1112
logger = logging.getLogger(__name__)
1213

1314

15+
def _find_sonobuoy():
16+
"""find sonobuoy in PATH, but also in a fixed location at ~/.local/bin to simplify use with Ansible"""
17+
result = shutil.which('sonobuoy')
18+
if result:
19+
return result
20+
result = os.path.join(os.path.expanduser('~'), '.local', 'bin', 'sonobuoy')
21+
if os.path.exists(result):
22+
return result
23+
24+
1425
class SonobuoyHandler:
1526
"""
1627
A class that handles both the execution of sonobuoy and
@@ -34,7 +45,7 @@ def __init__(
3445
self.kubeconfig_path = kubeconfig
3546
self.working_directory = os.getcwd()
3647
self.result_dir_name = result_dir_name
37-
self.sonobuoy = shutil.which('sonobuoy')
48+
self.sonobuoy = _find_sonobuoy()
3849
logger.debug(f"working from {self.working_directory}")
3950
logger.debug(f"placing results at {self.result_dir_name}")
4051
logger.debug(f"sonobuoy executable at {self.sonobuoy}")

playbooks/pre_cloud.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,43 @@
1717
requirements: "Tests/kaas/requirements.txt"
1818
when: kaas | bool
1919

20+
- name: Create local binary dir
21+
ansible.builtin.file:
22+
path: "{{ ansible_user_dir}}/.local/bin"
23+
state: directory
24+
recurse: true
25+
26+
- name: Install Sonobuoy
27+
ansible.builtin.shell:
28+
curl -L {{ sonobuoy_tar_gz_url | trim | quote }} | tar xz sonobuoy
29+
args:
30+
chdir: "{{ ansible_user_dir}}/.local/bin/"
31+
creates: sonobuoy
32+
when: kaas | bool
33+
2034
- name: Create cloud config dir
2135
ansible.builtin.file:
22-
path: "~/.config/openstack"
36+
path: "{{ ansible_user_dir }}/.config/openstack"
2337
state: directory
2438
recurse: true
2539
mode: "0700"
2640

2741
- name: Create cloud config file
2842
ansible.builtin.template:
2943
src: "clouds.yaml.j2"
30-
dest: "~/.config/openstack/clouds.yaml"
44+
dest: "{{ ansible_user_dir }}/.config/openstack/clouds.yaml"
3145
mode: "0600"
3246
no_log: true
3347

3448
- name: Create cluster config dir
3549
ansible.builtin.copy:
3650
src: ".config"
37-
dest: "~/"
51+
dest: "{{ ansible_user_dir }}/"
3852

3953
- name: Create cluster config file
4054
ansible.builtin.template:
4155
src: "clusters.yaml.j2"
42-
dest: "~/.config/scs/clusters.yaml"
56+
dest: "{{ ansible_user_dir }}/.config/scs/clusters.yaml"
4357
mode: "0600"
4458
no_log: true
4559

0 commit comments

Comments
 (0)