Skip to content

Commit c19930c

Browse files
authored
Merge pull request stackhpc#21 from stackhpc/feat/magnum-capi-templates
Add simplified Magnum template generation playbook
2 parents fbe04a0 + 828aafc commit c19930c

File tree

6 files changed

+184
-0
lines changed

6 files changed

+184
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,33 @@ 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_default_master_flavor_name: # Chosen flavor on target cloud
91+
magnum_default_worker_flavor_name: # Chosen flavor on target cloud
92+
magnum_external_net_name: # External network
93+
magnum_loadbalancer_provider: # Octavia provider (e.g. 'ovn')
94+
95+
then run the provided playbook with
96+
97+
.. code-block:: bash
98+
99+
$ tools/openstack-config -p ansible/generate-magnum-capi-templates.yml
100+
101+
This will create a ``generated-magnum-snippets`` directory in the repo root with
102+
a timestamped sub-directory containing an ``images.yml`` file and a ``templates.yml``
103+
file. The contents of these two files can then be added to any existing images and
104+
cluster templates in ``etc/openstack-config.yml``. When deploying the updated config,
105+
be sure to run the ``openstack-images.yml`` playbook *before* running the
106+
``openstack-container-clusters.yml`` playbook, otherwise the Magnum API will return
107+
an error referencing an invalid cluster type with image ``None``. This is handled
108+
automatically if running the full ``openstack.yml`` playbook.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
- name: Generate cluster templates
3+
hosts: localhost
4+
vars:
5+
root_dir: ../
6+
tasks:
7+
8+
- name: Check that required variables are defined
9+
assert:
10+
that:
11+
- magnum_default_master_flavor_name is defined
12+
- magnum_default_worker_flavor_name is defined
13+
- magnum_external_net_name is defined
14+
- magnum_loadbalancer_provider is defined
15+
16+
- name: Fetch capi-helm-charts release information
17+
ansible.builtin.uri:
18+
url: https://api.github.com/repos/stackhpc/capi-helm-charts/releases/latest
19+
register: capi_helm_chart_release_data
20+
21+
- name: Fetch dependencies.json for capi-helm-charts release
22+
ansible.builtin.uri:
23+
url: https://raw.githubusercontent.com/stackhpc/capi-helm-charts/{{ capi_helm_chart_release_data.json.tag_name }}/dependencies.json
24+
register: dependencies_response
25+
26+
- name: Ensure wget packages is installed
27+
become: true
28+
package:
29+
name: wget
30+
state: present
31+
32+
- name: Fetch manifest.json for capi-helm-charts images
33+
# ansible.builtin.uri:
34+
# url: https://raw.githubusercontent.com/stackhpc/azimuth-images/{{ dependencies_response.json['azimuth-images'] }}/manifest.json
35+
# Above URL returns 404 even though similar URL for capi-helm-charts repo works fine
36+
# Not sure why but fall back to wget + JSON parsing for now.
37+
shell: "wget -O - https://github.com/stackhpc/azimuth-images/releases/download/{{ dependencies_response.json['azimuth-images'] }}/manifest.json"
38+
register: manifest_response
39+
changed_when: false
40+
41+
- name: Parse JSON response
42+
set_fact:
43+
new_template_data: "{{ manifest_response.stdout | from_json | dict2items | selectattr('key', 'match', 'kubernetes*') | list }}"
44+
45+
- name: Ensure output dir exists
46+
ansible.builtin.file:
47+
path: "{{ [root_dir, 'generated-magnum-snippets', now(utc=true,fmt='%Y-%m-%d-T%H-%M-%S')] | path_join }}"
48+
state: directory
49+
mode: '0755'
50+
register: output_dir
51+
52+
- name: Write new image config to file
53+
template:
54+
src: "magnum-capi-images.j2"
55+
dest: "{{ output_dir.path }}/images.yml"
56+
57+
- name: Write new cluster template config to file
58+
template:
59+
src: "magnum-capi-templates.j2"
60+
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_default_master_flavor_name }}
20+
flavor: {{ magnum_default_worker_flavor_name }}
21+
image: "{{ item.value.name }}"
22+
name: "{{ item.key }}"
23+
coe: "kubernetes"
24+
network_driver: "{{ magnum_default_network_driver | default('calico') }}"
25+
master_lb_enabled: "{{ magnum_master_lb_enabled | default('True') }}"
26+
floating_ip_enabled: "{{ magnum_cluster_floating_ip_enabled | default('True') }}"
27+
dns_nameserver: "{{ (magnum_cluster_default_dns_nameservers | default(['1.1.1.1', '8.8.8.8', '8.8.4.4'])) | join(',') }}"
28+
public: "{{ magnum_cluster_templates_public | default('True') }}"
29+
30+
{% endfor %}

etc/openstack-config/openstack-config.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,39 @@
6363
# stackhpc.os-container-clusters role.
6464
#openstack_container_clusters_templates:
6565

66+
###############################################################################
67+
# Configuration variables for generating new Magnum cluster template config.
68+
69+
# These variables must be defined before using the generating new cluster
70+
# templates - see repo README for more details.
71+
72+
# Must have at least 2 CPUs, 4GB RAM and 20GB disk
73+
# magnum_default_master_flavor_name:
74+
# magnum_default_worker_flavor_name:
75+
76+
# Network to create tenant cluster FIPs on
77+
# magnum_external_net_name:
78+
79+
# Provider for cluster loadbalancers (e.g. 'ovn')
80+
# magnum_loadbalancer_provider:
81+
82+
# Kubernetes CNI to use for cluster templates (defaults to 'calico')
83+
# Must be one of the options supported by capi-helm-charts, see
84+
# https://github.com/stackhpc/capi-helm-charts/tree/main/charts/cluster-addons#container-network-interface-cni-plugins
85+
# magnum_default_network_driver:
86+
87+
# Whether to create a master nodes loadbalancer for cluster templates (defaults to 'True')
88+
# magnum_master_lb_enabled:
89+
90+
# Whether to add a floating IP to the loadbalancer for cluster templates (defaults to 'True')
91+
# magnum_cluster_floating_ip_enabled:
92+
93+
# List of nameservers to use for cluster templates
94+
# magnum_cluster_default_dns_nameservers:
95+
96+
# Whether generated cluster templates should be public by default (defaults to 'True')
97+
# magnum_cluster_templates_public:
98+
6699
###############################################################################
67100
# Dummy variable to allow Ansible to accept this file.
68101
workaround_ansible_issue_8743: yes

0 commit comments

Comments
 (0)