mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2025-12-14 13:54:37 +03:00
CI: adapt packet-ci role to act as a molecule provisioner
To work with molecule, we need to use the name provided by molecule_yml in inventory. Inject the name in the VirtualMachineInstance (with a default to handle non-molecule scenario) and get it back as part of inventory). Account for no ansible groups
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
---
|
||||
|
||||
- name: Provision Packet VMs
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
become: true
|
||||
roles:
|
||||
- { role: packet-ci, vm_cleanup: false }
|
||||
tasks:
|
||||
- name: Create Kubevirt VMs
|
||||
import_role:
|
||||
name: packet-ci
|
||||
- name: Update inventory for Molecule
|
||||
meta: refresh_inventory
|
||||
|
||||
@@ -13,7 +13,9 @@ memory_allocation_ratio: 1
|
||||
# Deployment mode
|
||||
mode: all-in-one
|
||||
|
||||
cluster_layout: "{{ scenarios[mode] }}"
|
||||
node_groups:
|
||||
- 'all'
|
||||
cluster_layout: "{{ molecule_yml.platforms | d(scenarios[mode]) }}"
|
||||
|
||||
# Cloud init config for each os type
|
||||
# distro: fedora -> I2Nsb3VkLWNvbmZpZwpzeXN0ZW1faW5mbzoKICBkaXN0cm86IGZlZG9yYQp1c2VyczoKIC0gbmFtZToga3ViZXNwcmF5CiAgIGdyb3Vwczogd2hlZWwKICAgc3VkbzogJ0FMTD0oQUxMKSBOT1BBU1NXRDpBTEwnCiAgIHNoZWxsOiAvYmluL2Jhc2gKICAgbG9ja19wYXNzd2Q6IEZhbHNlCiAgIGhvbWU6IC9ob21lL2t1YmVzcHJheQogICBzc2hfYXV0aG9yaXplZF9rZXlzOgogICAgIC0gc3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFCQVFDYW5UaS9lS3gwK3RIWUpBZURocStzRlMyT2JVUDEvSTY5ZjdpVjNVdGtLbFQyMEpmVzFmNkZlWHQvMDRWZjI3V1FxK05xczZ2R0JxRDlRWFNZdWYrdDAvczdFUExqVGVpOW1lMW1wcXIrdVRlK0tEdFRQMzlwZkQzL2VWQ2FlQjcyNkdQMkZrYUQwRnpwbUViNjZPM05xaHhPUTk2R3gvOVhUdXcvSzNsbGo0T1ZENkdyalIzQjdjNFh0RUJzWmNacHBNSi9vSDFtR3lHWGRoMzFtV1FTcUFSTy9QOFU4R3d0MCtIR3BVd2gvaGR5M3QrU1lvVEIyR3dWYjB6b3lWd3RWdmZEUXpzbThmcTNhdjRLdmV6OGtZdU5ESnYwNXg0bHZVWmdSMTVaRFJYc0FuZGhReXFvWGRDTEFlMCtlYUtYcTlCa1d4S0ZiOWhQZTBBVWpqYTU=
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
---
|
||||
- name: Include custom vars for ci job
|
||||
include_vars: "../files/{{ ci_job_name }}.yml"
|
||||
when: molecule_yml is not defined
|
||||
|
||||
- name: Start vms for CI job
|
||||
kubernetes.core.k8s:
|
||||
definition: "{{ lookup('template', 'vm.yml.j2', template_vars=item) }}"
|
||||
loop: "{{ cluster_layout }}"
|
||||
loop_control:
|
||||
index_var: index
|
||||
|
||||
- name: Wait for vms to have IP addresses
|
||||
kubernetes.core.k8s_info:
|
||||
@@ -24,17 +27,17 @@
|
||||
- name: Massage VirtualMachineInstance data into an Ansible inventory structure
|
||||
vars:
|
||||
ips: "{{ vmis.resources | map(attribute='status.interfaces.0.ipAddress') }}"
|
||||
names: "{{ vmis.resources | map(attribute='metadata.name') }}"
|
||||
_groups: "{{ vmis.resources | map(attribute='metadata.annotations.ansible_groups') | map('split', ',') }}"
|
||||
names: "{{ vmis.resources | map(attribute='metadata.annotations.inventory_name') }}"
|
||||
_groups: "{{ (vmis.resources | map(attribute='metadata.annotations.ansible_groups') | map('split', ','))}}"
|
||||
hosts: "{{ ips | zip(_groups, names)
|
||||
| map('zip', ['ansible_host', 'ansible_groups', 'k8s_vmi_name'])
|
||||
| map('zip', ['ansible_host', 'ansible_groups', 'inventory_name'])
|
||||
| map('map', 'reverse') | map('community.general.dict') }}"
|
||||
loop: "{{ hosts | map(attribute='ansible_groups') | flatten | unique }}"
|
||||
set_fact:
|
||||
ci_inventory: "{{ ci_inventory|d({}) | combine({
|
||||
item: {
|
||||
'hosts': hosts | selectattr('ansible_groups', 'contains', item)
|
||||
| rekey_on_member('k8s_vmi_name')
|
||||
| rekey_on_member('inventory_name')
|
||||
}
|
||||
})
|
||||
}}"
|
||||
|
||||
@@ -7,11 +7,11 @@ metadata:
|
||||
annotations:
|
||||
kubespray.com/ci.template-path: "tests/cloud_playbooks/roles/packet-ci/templates/vm.yml.j2"
|
||||
ansible_groups: "{{ node_groups | join(',') }}"
|
||||
inventory_name: "{{ name | d(cloud_image ~ '-' ~ index) }}"
|
||||
# This does not use a dns prefix because dots are hard to escape with map(attribute=) in Jinja
|
||||
labels:
|
||||
kubevirt.io/os: {{ cloud_image }}
|
||||
kubevirt.io/size: small
|
||||
kubevirt.io/domain: "{{ test_name }}"
|
||||
ci_job_id: "{{ ci_job_id }}"
|
||||
ci_job_name: "{{ ci_job_name }}"
|
||||
# leverage the Kubernetes GC for resources cleanup
|
||||
|
||||
Reference in New Issue
Block a user