Skip to content

Commit 7a50177

Browse files
author
Scott Davidson
committed
Add simplified Magnum template generation playbook
1 parent fbe04a0 commit 7a50177

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,10 @@ ansible/collections/**/
114114
*~
115115
.*.swp
116116
.*sw?
117+
118+
# Ignore working dirs
119+
ansible/openstack-config-image-cache
120+
ansible/openstack-config-venv
121+
122+
# Ignore tmp output from template generation playbook
123+
generated-magnum-snippets/

README.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,32 @@ configuration parameter:
7676
.. code-block::
7777
7878
$ tools/openstack-config -- --vault-password-file config-secret.vault
79+
80+
81+
Magnum Cluster Templates
82+
========================
83+
84+
To generate a new set of Magnum cluster templates and corresponding Glance image
85+
definitions which utilise the latest stable upstream release tag, set the following
86+
variables in `etc/openstack-config.yml`
87+
88+
.. code-block:: yaml
89+
90+
magnum_flavor_name: # Chosen flavor on target cloud
91+
magnum_external_net_name: # External network
92+
magnum_loadbalancer_provider: # Octavia provider (e.g. 'ovn')
93+
94+
then run the provided playbook with
95+
96+
.. code-block:: bash
97+
98+
$ tools/openstack-config -p ansible/generate-magnum-capi-templates.yml
99+
100+
This will create a ``generated-magnum-snippets`` directory in the repo root with
101+
a timestamped sub-directory containing an ``images.yml`` file and a ``templates.yml``
102+
file. The contents of these two files can then be added to any existing images and
103+
cluster templates in ``etc/openstack-config.yml``. When deploying the updated config,
104+
be sure to run the ``openstack-images.yml`` playbook *before* running the
105+
``openstack-container-clusters.yml`` playbook, otherwise the Magnum API will return
106+
an error referencing an invalid cluster type with image ``None``. This is handled
107+
automatically if running the full ``openstack.yml`` playbook.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
- name: Generate cluster templates
3+
hosts: localhost
4+
vars:
5+
root_dir: ../
6+
tasks:
7+
8+
- name: Fetch capi-helm-charts release information
9+
ansible.builtin.uri:
10+
url: https://api.github.com/repos/stackhpc/capi-helm-charts/releases/latest
11+
register: capi_helm_chart_release_data
12+
13+
- name: Fetch dependencies.json for capi-helm-charts release
14+
ansible.builtin.uri:
15+
url: https://raw.githubusercontent.com/stackhpc/capi-helm-charts/{{ capi_helm_chart_release_data.json.tag_name }}/dependencies.json
16+
register: dependencies_response
17+
18+
- name: Fetch manifest.json for capi-helm-charts images
19+
# ansible.builtin.uri:
20+
# url: https://raw.githubusercontent.com/stackhpc/azimuth-images/{{ dependencies_response.json['azimuth-images'] }}/manifest.json
21+
# Above URL returns 404 even though similar URL for capi-helm-charts repo works fine
22+
# Not sure why but fall back to wget + JSON parsing for now.
23+
shell: "wget -O - https://github.com/stackhpc/azimuth-images/releases/download/{{ dependencies_response.json['azimuth-images'] }}/manifest.json"
24+
register: manifest_response
25+
changed_when: false
26+
27+
- name: Parse JSON response
28+
set_fact:
29+
new_template_data: "{{ manifest_response.stdout | from_json | dict2items | selectattr('key', 'match', 'kubernetes*') | list }}"
30+
31+
- name: Ensure output dir exists
32+
ansible.builtin.file:
33+
path: "{{ [root_dir, 'generated-magnum-snippets', now(utc=true,fmt='%Y-%m-%d-T%H-%M-%S')] | path_join }}"
34+
state: directory
35+
mode: '0755'
36+
register: output_dir
37+
38+
- name: Write new image config to file
39+
template:
40+
src: "magnum-capi-images.j2"
41+
dest: "{{ output_dir.path }}/images.yml"
42+
43+
- name: Write new cluster template config to file
44+
template:
45+
src: "magnum-capi-templates.j2"
46+
dest: "{{ output_dir.path }}/templates.yml"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Images required for corresponding Magnum cluster template
2+
# To make use of the generated config snippets, copy them to
3+
# etc/openstack-config and add the images to the openstack_images
4+
# list.
5+
6+
# List snippet to add to existing openstack_images:
7+
{% for item in new_template_data %}
8+
# -{% raw %} "{{ {% endraw %}{{ item.value.name | replace('-', '_') | replace('.', '_') }}{% raw %} }}"{% endraw %}
9+
10+
{% endfor %}
11+
12+
{% for item in new_template_data %}
13+
# Image for {{ item.key }}
14+
{{ item.value.name | replace('-', '_') | replace('.', '_') }}:
15+
name: "{{ item.value.name }}"
16+
type: qcow2
17+
image_url: "{{ item.value.url }}"
18+
visibility: "community"
19+
properties:
20+
os_distro: "ubuntu"
21+
os_version: "20.04"
22+
kube_version: "{{ item.value.kubernetes_version }}"
23+
24+
{% endfor %}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Magnum cluster templates generated using latest upstream release tags
2+
# To make use of the generated config snippets, copy them to the
3+
# openstack_container_clusters_templates list.
4+
5+
# List snippet to add to existing openstack_container_clusters_templates:
6+
{% for item in new_template_data %}
7+
# -{% raw %} "{{ {% endraw %}{{ item.key | replace('-', '_') }}_{{ item.value.kubernetes_version | replace('.', '_') }}{% raw %} }}"{% endraw %}
8+
9+
{% endfor %}
10+
11+
{% for item in new_template_data %}
12+
{{ item.key | replace('-', '_') }}_{{ item.value.kubernetes_version | replace('.', '_') }}:
13+
labels:
14+
monitoring_enabled: "True"
15+
kube_dashboard_enabled: "True"
16+
capi_helm_chart_version: "{{ capi_helm_chart_release_data.json.tag_name }}"
17+
octavia_provider: {{ magnum_loadbalancer_provider }}
18+
external_network_id: {{ magnum_external_net_name }}
19+
master_flavor: {{ magnum_flavor_name }}
20+
flavor: {{ magnum_flavor_name }}
21+
image: "{{ item.value.name }}"
22+
name: "{{ item.key }}"
23+
coe: "kubernetes"
24+
network_driver: "calico"
25+
master_lb_enabled: "True"
26+
floating_ip_enabled: "True"
27+
dns_nameserver: "1.1.1.1,8.8.8.8,8.8.4.4"
28+
public: True
29+
30+
{% endfor %}

0 commit comments

Comments
 (0)