Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,10 @@ ansible/collections/**/
*~
.*.swp
.*sw?

# Ignore working dirs
ansible/openstack-config-image-cache
ansible/openstack-config-venv

# Ignore tmp output from template generation playbook
generated-magnum-snippets/
29 changes: 29 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,32 @@ configuration parameter:
.. code-block::

$ tools/openstack-config -- --vault-password-file config-secret.vault


Magnum Cluster Templates
========================

To generate a new set of Magnum cluster templates and corresponding Glance image
definitions which utilise the latest stable upstream release tag, set the following
variables in `etc/openstack-config.yml`

.. code-block:: yaml

magnum_default_flavor_name: # Chosen flavor on target cloud
magnum_external_net_name: # External network
magnum_loadbalancer_provider: # Octavia provider (e.g. 'ovn')

then run the provided playbook with

.. code-block:: bash

$ tools/openstack-config -p ansible/generate-magnum-capi-templates.yml

This will create a ``generated-magnum-snippets`` directory in the repo root with
a timestamped sub-directory containing an ``images.yml`` file and a ``templates.yml``
file. The contents of these two files can then be added to any existing images and
cluster templates in ``etc/openstack-config.yml``. When deploying the updated config,
be sure to run the ``openstack-images.yml`` playbook *before* running the
``openstack-container-clusters.yml`` playbook, otherwise the Magnum API will return
an error referencing an invalid cluster type with image ``None``. This is handled
automatically if running the full ``openstack.yml`` playbook.
46 changes: 46 additions & 0 deletions ansible/generate-magnum-capi-templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- name: Generate cluster templates
hosts: localhost
vars:
root_dir: ../
tasks:

- name: Fetch capi-helm-charts release information
ansible.builtin.uri:
url: https://api.github.com/repos/stackhpc/capi-helm-charts/releases/latest
register: capi_helm_chart_release_data

- name: Fetch dependencies.json for capi-helm-charts release
ansible.builtin.uri:
url: https://raw.githubusercontent.com/stackhpc/capi-helm-charts/{{ capi_helm_chart_release_data.json.tag_name }}/dependencies.json
register: dependencies_response

- name: Fetch manifest.json for capi-helm-charts images
# ansible.builtin.uri:
# url: https://raw.githubusercontent.com/stackhpc/azimuth-images/{{ dependencies_response.json['azimuth-images'] }}/manifest.json
# Above URL returns 404 even though similar URL for capi-helm-charts repo works fine
# Not sure why but fall back to wget + JSON parsing for now.
shell: "wget -O - https://github.com/stackhpc/azimuth-images/releases/download/{{ dependencies_response.json['azimuth-images'] }}/manifest.json"
register: manifest_response
changed_when: false

- name: Parse JSON response
set_fact:
new_template_data: "{{ manifest_response.stdout | from_json | dict2items | selectattr('key', 'match', 'kubernetes*') | list }}"

- name: Ensure output dir exists
ansible.builtin.file:
path: "{{ [root_dir, 'generated-magnum-snippets', now(utc=true,fmt='%Y-%m-%d-T%H-%M-%S')] | path_join }}"
state: directory
mode: '0755'
register: output_dir

- name: Write new image config to file
template:
src: "magnum-capi-images.j2"
dest: "{{ output_dir.path }}/images.yml"

- name: Write new cluster template config to file
template:
src: "magnum-capi-templates.j2"
dest: "{{ output_dir.path }}/templates.yml"
24 changes: 24 additions & 0 deletions ansible/templates/magnum-capi-images.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Images required for corresponding Magnum cluster template
# To make use of the generated config snippets, copy them to
# etc/openstack-config and add the images to the openstack_images
# list.

# List snippet to add to existing openstack_images:
{% for item in new_template_data %}
# -{% raw %} "{{ {% endraw %}{{ item.value.name | replace('-', '_') | replace('.', '_') }}{% raw %} }}"{% endraw %}

{% endfor %}

{% for item in new_template_data %}
# Image for {{ item.key }}
{{ item.value.name | replace('-', '_') | replace('.', '_') }}:
name: "{{ item.value.name }}"
type: qcow2
image_url: "{{ item.value.url }}"
visibility: "community"
properties:
os_distro: "ubuntu"
os_version: "20.04"
kube_version: "{{ item.value.kubernetes_version }}"

{% endfor %}
30 changes: 30 additions & 0 deletions ansible/templates/magnum-capi-templates.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Magnum cluster templates generated using latest upstream release tags
# To make use of the generated config snippets, copy them to the
# openstack_container_clusters_templates list.

# List snippet to add to existing openstack_container_clusters_templates:
{% for item in new_template_data %}
# -{% raw %} "{{ {% endraw %}{{ item.key | replace('-', '_') }}_{{ item.value.kubernetes_version | replace('.', '_') }}{% raw %} }}"{% endraw %}

{% endfor %}

{% for item in new_template_data %}
{{ item.key | replace('-', '_') }}_{{ item.value.kubernetes_version | replace('.', '_') }}:
labels:
monitoring_enabled: "True"
kube_dashboard_enabled: "True"
capi_helm_chart_version: "{{ capi_helm_chart_release_data.json.tag_name }}"
octavia_provider: {{ magnum_loadbalancer_provider }}
external_network_id: {{ magnum_external_net_name }}
master_flavor: {{ magnum_default_flavor_name }}
flavor: {{ magnum_default_flavor_name }}
image: "{{ item.value.name }}"
name: "{{ item.key }}"
coe: "kubernetes"
network_driver: "calico"
master_lb_enabled: "True"
floating_ip_enabled: "True"
dns_nameserver: "1.1.1.1,8.8.8.8,8.8.4.4"
public: True

{% endfor %}