diff --git a/tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2 b/tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2 index 371656b73..f5f7cc02a 100644 --- a/tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2 +++ b/tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2 @@ -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: diff --git a/tests/cloud_playbooks/roles/packet-ci/vars/main.yml b/tests/cloud_playbooks/roles/packet-ci/vars/main.yml index ba448587d..103da858b 100644 --- a/tests/cloud_playbooks/roles/packet-ci/vars/main.yml +++ b/tests/cloud_playbooks/roles/packet-ci/vars/main.yml @@ -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) }}"