Files
kubespray/tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2
Max Gautier 65c67c5c51 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.
2024-10-18 12:14:52 +02:00

63 lines
1.7 KiB
Django/Jinja

---
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
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:
metadata:
labels:
kubevirt.io/size: small
kubevirt.io/domain: "{{ test_name }}"
spec:
domain:
devices:
blockMultiQueue: true
disks:
- disk:
bus: virtio
name: containervolume
cache: writethrough
- disk:
bus: virtio
name: cloudinitvolume
interfaces:
- name: default
bridge: {}
cpu:
cores: {{ vm_cpu_cores }}
sockets: {{ vm_cpu_sockets }}
threads: {{ vm_cpu_threads }}
resources:
requests:
memory: "{{ vm_memory * memory_allocation_ratio }}Mi"
cpu: {{ vm_cpu_cores * cpu_allocation_ratio }}
limits:
memory: "{{ vm_memory }}Mi"
cpu: {{ vm_cpu_cores }}
networks:
- name: default
pod: {}
terminationGracePeriodSeconds: 0
volumes:
- name: containervolume
containerDisk:
image: quay.io/kubespray/vm-{{ cloud_image }}
- name: cloudinitvolume
cloudInitNoCloud:
userDataBase64: {{ cloud_init[cloud_image] }}