Clean Code

This commit is contained in:
dsk-minchulahn
2023-12-19 13:03:29 +09:00
parent 947561ce1d
commit 0273450ff6
4237 changed files with 0 additions and 7447 deletions

View File

@@ -0,0 +1,49 @@
---
- name: "Create CI namespace {{ test_name }} for test vms"
command: "kubectl create namespace {{ test_name }}"
changed_when: false
- name: "Create temp dir /tmp/{{ test_name }} for CI files"
file:
path: "/tmp/{{ test_name }}"
state: directory
mode: 0755
- name: Template vm files for CI job
template:
src: "vm.yml.j2"
dest: "/tmp/{{ test_name }}/instance-{{ vm_id }}.yml"
mode: 0644
loop: "{{ range(1, vm_count|int + 1, 1) | list }}"
loop_control:
index_var: vm_id
- name: Start vms for CI job
command: "kubectl apply -f /tmp/{{ test_name }}/instance-{{ vm_id }}.yml"
changed_when: false
loop: "{{ range(1, vm_count|int + 1, 1) | list }}"
loop_control:
index_var: vm_id
- name: Wait for vms to have ipaddress assigned
shell: "set -o pipefail && kubectl get vmis -n {{ test_name }} instance-{{ vm_id }} -o json | jq '.status.interfaces[].ipAddress' | tr -d '\"'"
args:
executable: /bin/bash
changed_when: false
register: vm_ips
loop: "{{ range(1, vm_count|int + 1, 1) | list }}"
loop_control:
index_var: vm_id
retries: 20
delay: 15
until:
- vm_ips.stdout | ipaddr
- name: "Create inventory for CI test in file /tmp/{{ test_name }}/inventory"
template:
src: "inventory.j2"
dest: "{{ inventory_path }}"
mode: 0644
vars:
vms: "{{ vm_ips }}"

View File

@@ -0,0 +1,30 @@
---
- name: Check if temp directory for {{ test_name }} exists
stat:
path: "/tmp/{{ test_name }}"
get_attributes: no
get_checksum: no
get_mime: no
register: temp_dir_details
- name: "Cleanup temp directory for {{ test_name }}"
file:
path: "/tmp/{{ test_name }}"
state: absent
- name: "Cleanup namespace for {{ test_name }}"
command: "kubectl delete namespace {{ test_name }}"
changed_when: false
- name: Wait for namespace {{ test_name }} to be fully deleted
command: kubectl get ns {{ test_name }}
register: delete_namespace
failed_when:
- delete_namespace.rc == 0
changed_when:
- delete_namespace.rc == 0
retries: 12
delay: "10"
until:
- delete_namespace.rc != 0

View File

@@ -0,0 +1,16 @@
---
- name: "Include custom vars for ci job: {{ ci_job_name }}"
include_vars: "../files/{{ ci_job_name }}.yml"
- name: Set VM count needed for CI test_id
set_fact:
vm_count: "{%- if mode in ['separate', 'separate-scale', 'ha', 'ha-scale', 'ha-recover', 'ha-recover-noquorum'] -%}{{ 3|int }}{%- elif mode == 'aio' -%}{{ 1|int }}{%- else -%}{{ 2|int }}{%- endif -%}"
- import_tasks: create-vms.yml
when:
- not vm_cleanup
- import_tasks: delete-vms.yml
when:
- vm_cleanup | default(false)