From c49675233a3f229991bd9357e817a0befaf50b34 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Thu, 18 Jan 2024 17:11:50 +0000 Subject: [PATCH] Add role to install and run sonobouy k8s validation tests Change-Id: Ic5af3ec8f8553f54f95e945a91068873f02d1d1a --- mcapi_vexxhost/playbooks/sonobuoy.yml | 22 +++++++++ .../roles/sonobuoy/defaults/main.yml | 31 +++++++++++++ mcapi_vexxhost/roles/sonobuoy/meta/main.yml | 33 +++++++++++++ mcapi_vexxhost/roles/sonobuoy/tasks/main.yml | 46 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 mcapi_vexxhost/playbooks/sonobuoy.yml create mode 100644 mcapi_vexxhost/roles/sonobuoy/defaults/main.yml create mode 100644 mcapi_vexxhost/roles/sonobuoy/meta/main.yml create mode 100644 mcapi_vexxhost/roles/sonobuoy/tasks/main.yml diff --git a/mcapi_vexxhost/playbooks/sonobuoy.yml b/mcapi_vexxhost/playbooks/sonobuoy.yml new file mode 100644 index 00000000..0ac9b033 --- /dev/null +++ b/mcapi_vexxhost/playbooks/sonobuoy.yml @@ -0,0 +1,22 @@ +--- +# Copyright 2024, BBC R&D. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Install and run sonobuoy + hosts: utility_all[0] + gather_facts: false + roles: + - openstack.osa.source_install_vars + - osa_ops.mcapi_vexxhost.sonobuoy + environment: "{{ deployment_environment_variables | default({}) }}" diff --git a/mcapi_vexxhost/roles/sonobuoy/defaults/main.yml b/mcapi_vexxhost/roles/sonobuoy/defaults/main.yml new file mode 100644 index 00000000..ee18a052 --- /dev/null +++ b/mcapi_vexxhost/roles/sonobuoy/defaults/main.yml @@ -0,0 +1,31 @@ +# Copyright (c) 2024 BBC R&D. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +sonobuoy_version: 0.57.1 +sonobuoy_download_file: "sonobuoy_{{ sonobuoy_version }}_linux_amd64.tar.gz" +sonobuoy_download_url: "https://github.com/vmware-tanzu/sonobuoy/releases/download/v{{ sonobuoy_version }}/{{ sonobuoy_download_file }}" +sonobuoy_unarchive_dest: /usr/local/bin + +# set the name or uuid of the openstack coe cluster to test +sonobuoy_coe_cluster: "" + +# the location of the kubeconfig file +sonobuoy_kubeconfig_file: "{{ '/root/' ~ 'kubeconfig-' ~ sonobuoy_coe_cluster ~ '/config' }}" + +# set the options for the test +sonobuoy_run_options: "--mode quick --wait" + +# execute tests after downloading sonobuoy +sonobuoy_run: true +sonobuoy_delete: true diff --git a/mcapi_vexxhost/roles/sonobuoy/meta/main.yml b/mcapi_vexxhost/roles/sonobuoy/meta/main.yml new file mode 100644 index 00000000..1da3643a --- /dev/null +++ b/mcapi_vexxhost/roles/sonobuoy/meta/main.yml @@ -0,0 +1,33 @@ +# Copyright (c) 2024 BBC R&D. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +galaxy_info: + author: BBC R&D + description: Ansible role for "sonobuoy" + license: Apache-2.0 + min_ansible_version: 5.5.0 + standalone: false + platforms: + - name: Ubuntu + versions: + - jammy + +dependencies: + - role: vexxhost.containers.download_artifact + download_artifact_url: "{{ sonobuoy_download_url }}" + download_artifact_dest: "{{ download_artifact_work_directory ~ '/' ~ sonobuoy_download_file }}" + download_artifact_owner: root + download_artifact_mode: "0755" + download_artifact_unarchive: true + download_artifact_unarchive_dest: "{{ sonobuoy_unarchive_dest }}" diff --git a/mcapi_vexxhost/roles/sonobuoy/tasks/main.yml b/mcapi_vexxhost/roles/sonobuoy/tasks/main.yml new file mode 100644 index 00000000..cd20e7c2 --- /dev/null +++ b/mcapi_vexxhost/roles/sonobuoy/tasks/main.yml @@ -0,0 +1,46 @@ +# Copyright (c) 2024 BBC R&D. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Create dir to hold kubeconfig + ansible.builtin.file: + state: directory + path: "{{ sonobuoy_kubeconfig_file | dirname }}" + +- name: Retrieve kubeconfig + vars: + ansible_python_interpreter: "{{ openstack_service_setup_host_python_interpreter }}" + ansible.builtin.command: + cmd: openstack coe cluster config --dir "{{ sonobuoy_kubeconfig_file | dirname }}" "{{ sonobuoy_coe_cluster }}" + creates: "{{ sonobuoy_kubeconfig_file }}" + environment: + OS_CLOUD: default + +- name: Run sonobuoy tests + when: sonobuoy_run + environment: + KUBECONFIG: "{{ sonobuoy_kubeconfig_file }}" + block: + - name: Execute tests + ansible.builtin.shell: + cmd: "{{ sonobuoy_unarchive_dest ~ '/sonobuoy run ' ~ sonobuoy_run_options }}" + + - name: Get sonobuoy results + ansible.builtin.command: + cmd: "{{ sonobuoy_unarchive_dest ~ '/sonobuoy retrieve' }}" + register: _retrieve + + - name: Cleanup + ansible.builtin.command: + cmd: "{{ sonobuoy_unarchive_dest ~ '/sonobuoy delete --wait' }}" + when: sonobuoy_delete