Skip to content

Commit 9f26e6a

Browse files
authored
Merge pull request #5 from stackhpc/merge-upstream
Merge upstream openstack-config (inc. move to stackhpc.openstack collection)
2 parents 5a7c630 + 0ee10c1 commit 9f26e6a

18 files changed

+330
-77
lines changed

.gitignore

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

README.rst

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ packages. For example:
1717
1818
$ virtualenv venv
1919
$ source venv/bin/activate
20-
$ pip install -U pip
20+
$ python -m pip install --upgrade pip
2121
$ pip install -r requirements.txt
2222
2323
Install Ansible role and collection dependencies from Ansible Galaxy:
2424

2525
.. code-block::
26-
27-
$ ansible-galaxy role install \
28-
-p ansible/roles \
29-
-r requirements.yml
30-
3126
$ ansible-galaxy collection install \
3227
-p ansible/collections \
3328
-r requirements.yml
@@ -81,3 +76,33 @@ configuration parameter:
8176
.. code-block::
8277
8378
$ 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"

ansible/group_vars/all/openstack

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
###############################################################################
33
# Configuration of OpenStack user environment for OpenStack.
44

5+
# List of OpenStack domains. Format is as required by the stackhpc.os-projects
6+
# role.
7+
openstack_domains: []
8+
59
# List of OpenStack projects. Format is as required by the stackhpc.os-projects
610
# role.
711
openstack_projects: []
@@ -21,6 +25,10 @@ openstack_routers: []
2125
# stackhpc.os-networks role.
2226
openstack_security_groups: []
2327

28+
# List of RBAC definitions in the openstack projct. Format is as required by the
29+
# stackhpc.os-networks role.
30+
openstack_networks_rbac: []
31+
2432
###############################################################################
2533
# Configuration of nova flavors for OpenStack.
2634

ansible/openstack-container-clusters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
tags:
55
- container-clusters-templates
66
roles:
7-
- role: stackhpc.os-container-clusters
7+
- role: stackhpc.openstack.os_container_clusters
88
os_container_clusters_venv: "{{ openstack_venv }}"
99
os_container_clusters_auth_type: "{{ openstack_auth_type }}"
1010
os_container_clusters_auth: "{{ openstack_auth }}"

ansible/openstack-flavors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
tags:
55
- flavors
66
roles:
7-
- role: stackhpc.os-flavors
7+
- role: stackhpc.openstack.os_flavors
88
os_flavors_venv: "{{ openstack_venv }}"
99
os_flavors_auth_type: "{{ openstack_auth_type }}"
1010
os_flavors_auth: "{{ openstack_auth }}"

ansible/openstack-host-aggregates.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
tags:
55
- host_aggregates
66
roles:
7-
- role: stackhpc.os_host_aggregates
7+
- role: stackhpc.openstack.os_host_aggregates
88
os_host_aggregates_venv: "{{ openstack_venv }}"
99
os_host_aggregates_auth_type: "{{ openstack_auth_type }}"
1010
os_host_aggregates_auth: "{{ openstack_auth }}"

ansible/openstack-images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
tags:
55
- images
66
roles:
7-
- role: stackhpc.os-images
7+
- role: stackhpc.openstack.os_images
88
os_images_venv: "{{ openstack_venv }}"
99
os_images_cache: "{{ ansible_env.PWD }}/openstack-config-image-cache"
1010
os_images_auth_type: "{{ openstack_auth_type }}"

ansible/openstack-networks.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
tags:
55
- networks
66
roles:
7-
- role: stackhpc.os-networks
7+
- role: stackhpc.openstack.os_networks
88
os_networks_venv: "{{ openstack_venv }}"
99
os_networks_auth_type: "{{ openstack_auth_type }}"
1010
os_networks_auth: "{{ openstack_auth }}"
1111
os_networks_cacert: "{{ openstack_cacert }}"
1212
os_networks: "{{ openstack_networks }}"
1313
os_networks_routers: "{{ openstack_routers }}"
1414
os_networks_security_groups: "{{ openstack_security_groups }}"
15+
os_networks_rbac: "{{ openstack_networks_rbac }}"

ansible/openstack-project.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
tags:
55
- project
66
roles:
7-
- role: stackhpc.os-projects
7+
- role: stackhpc.openstack.os_projects
88
os_projects_venv: "{{ openstack_venv }}"
99
os_projects_auth_type: "{{ openstack_auth_type }}"
1010
os_projects_admin_auth: "{{ openstack_auth }}"
1111
os_projects_cacert: "{{ openstack_cacert }}"
1212
os_projects: "{{ openstack_projects }}"
13+
os_projects_domains: "{{ openstack_domains }}"

ansible/roles/.keep

Whitespace-only changes.
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
keystone_auth_enabled: "false"
17+
capi_helm_chart_version: "{{ capi_helm_chart_release_data.json.tag_name }}"
18+
octavia_provider: {{ magnum_loadbalancer_provider }}
19+
external_network_id: {{ magnum_external_net_name }}
20+
master_flavor: {{ magnum_default_master_flavor_name }}
21+
flavor: {{ magnum_default_worker_flavor_name }}
22+
image: "{{ item.value.name }}"
23+
name: "{{ item.key }}"
24+
coe: "kubernetes"
25+
network_driver: "{{ magnum_default_network_driver | default('calico') }}"
26+
master_lb_enabled: "{{ magnum_master_lb_enabled | default('True') }}"
27+
floating_ip_enabled: "{{ magnum_cluster_floating_ip_enabled | default('True') }}"
28+
dns_nameserver: "{{ (magnum_cluster_default_dns_nameservers | default(['1.1.1.1', '8.8.8.8', '8.8.4.4'])) | join(',') }}"
29+
public: "{{ magnum_cluster_templates_public | default('True') }}"
30+
31+
{% endfor %}

0 commit comments

Comments
 (0)