CI: use Kubernetes GC to delete kubevirt vms
This leverage the Kubernetes GC to delete kubevirt VMs, by using ownerReferences, with the CI pod running the playbook as the owner. This concretely means that the control plane in our CI cluster will delete the kubevirt VMs associated with a particular ci job as soon as that pod job is deleted, which usually happens when the job terminates, (barring errors, which will be addressed in the cluster directly) Upgrade to kubevirt.io/v1 for the VirtualMachine manifests, since the alpha version is deprecated.pull/11530/head
parent
5aea2abc40
commit
65c67c5c51
|
@ -1,13 +1,21 @@
|
|||
---
|
||||
apiVersion: kubevirt.io/v1alpha3
|
||||
apiVersion: kubevirt.io/v1
|
||||
kind: VirtualMachine
|
||||
metadata:
|
||||
name: "instance-{{ vm_id }}"
|
||||
namespace: "{{ test_name }}"
|
||||
generateName: test-vm-
|
||||
namespace: {{ pod_namespace }}
|
||||
annotations:
|
||||
kubespray.com/ci.template-path: "tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2"
|
||||
labels:
|
||||
kubevirt.io/os: {{ cloud_image }}
|
||||
ci_job_id: "{{ ci_job_id }}"
|
||||
ci_job_name: "{{ ci_job_name }}"
|
||||
# leverage the Kubernetes GC for resources cleanup
|
||||
ownerReferences:
|
||||
- apiVersion: v1
|
||||
kind: Pod
|
||||
name: "{{ pod_name }}"
|
||||
uid: "{{ pod_uid }}"
|
||||
spec:
|
||||
running: true
|
||||
template:
|
||||
|
|
|
@ -9,3 +9,11 @@ _vm_count_dict:
|
|||
default: 2
|
||||
|
||||
vm_count: "{{ _vm_count_dict[mode | d('default')] }}"
|
||||
|
||||
# Get pod metadata / CI vars from environment
|
||||
|
||||
ci_job_id: "{{ lookup('ansible.builtin.env', 'CI_JOB_ID', default=undefined) }}"
|
||||
ci_job_name: "{{ lookup('ansible.builtin.env', 'CI_JOB_NAME', default=undefined) }}"
|
||||
pod_name: "{{ lookup('ansible.builtin.env', 'POD_NAME', default=undefined) }}"
|
||||
pod_uid: "{{ lookup('ansible.builtin.env', 'POD_UID', default=undefined) }}"
|
||||
pod_namespace: "{{ lookup('ansible.builtin.env', 'POD_NAMESPACE', default=undefined) }}"
|
||||
|
|
Loading…
Reference in New Issue