Skip to content

Commit 123c573

Browse files
committed
Merge branch 'feature/k3s-ansible-init' into feature/k3s-monitoring
2 parents 96edb79 + 8b7941d commit 123c573

File tree

14 files changed

+80
-51
lines changed

14 files changed

+80
-51
lines changed

ansible/roles/cluster_infra/templates/outputs.tf.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output "cluster_gateway_ip" {
22
description = "The IP address of the gateway used to contact the cluster nodes"
3-
value = openstack_compute_floatingip_associate_v2.login_floatingip_assoc.floating_ip
3+
value = openstack_networking_floatingip_associate_v2.login_floatingip_assoc.floating_ip
44
}
55

66
{% if cluster_ssh_private_key_file is not defined %}
@@ -24,8 +24,8 @@ output "cluster_nodes" {
2424
}
2525
},
2626
{
27-
name = openstack_compute_instance_v2.control.name
28-
ip = openstack_compute_instance_v2.control.network[0].fixed_ip_v4
27+
name = openstack_compute_instance_v2.control["control"].name
28+
ip = openstack_compute_instance_v2.control["control"].network[0].fixed_ip_v4
2929
groups = ["control", "{{ cluster_name }}_control"],
3030
facts = {
3131
openstack_project_id = data.openstack_identity_auth_scope_v3.scope.project_id

ansible/roles/cluster_infra/templates/providers.tf.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ terraform {
55
required_providers {
66
openstack = {
77
source = "terraform-provider-openstack/openstack"
8+
# TODO we must upgrade to 3.0.0
9+
# but only after we stop using the deprecated
10+
# openstack_compute_floatingip_associate_v2
11+
version = "~>2.1.0"
812
}
913
}
1014
}

ansible/roles/cluster_infra/templates/resources.tf.j2

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ data "openstack_identity_auth_scope_v3" "scope" {
77
name = "{{ cluster_name }}"
88
}
99

10+
####
11+
#### Data resources
12+
####
13+
14+
resource "terraform_data" "k3s_token" {
15+
input = "{{ k3s_token }}"
16+
lifecycle {
17+
ignore_changes = [
18+
input,
19+
]
20+
}
21+
}
22+
1023
#####
1124
##### Security groups for the cluster
1225
#####
@@ -386,6 +399,8 @@ resource "openstack_compute_instance_v2" "login" {
386399
ansible_init_coll_{{ loop.index0 }}_source = "{{ collection.source }}"
387400
{% endif %}
388401
{% endfor %}
402+
k3s_server = [for n in openstack_compute_instance_v2.control["control"].network: n.fixed_ip_v4 if n.access_network][0]
403+
k3s_token = "{{ k3s_token }}"
389404
}
390405
}
391406

@@ -397,9 +412,11 @@ resource "openstack_compute_instance_v2" "control" {
397412
{% else %}
398413
flavor_id = "{{ control_flavor }}"
399414
{% endif %}
415+
for_each = toset(["control"])
400416

401417
network {
402418
port = openstack_networking_port_v2.control.id
419+
access_network = true
403420
}
404421

405422
{% if cluster_storage_network is defined %}
@@ -479,6 +496,7 @@ resource "openstack_compute_instance_v2" "control" {
479496
ansible_init_coll_{{ loop.index0 }}_source = "{{ collection.source }}"
480497
{% endif %}
481498
{% endfor %}
499+
k3s_token = "{{ k3s_token }}"
482500
}
483501
}
484502

@@ -548,6 +566,8 @@ resource "openstack_compute_instance_v2" "{{ partition.name }}" {
548566
ansible_init_coll_{{ loop.index0 }}_source = "{{ collection.source }}"
549567
{% endif %}
550568
{% endfor %}
569+
k3s_server = [for n in openstack_compute_instance_v2.control["control"].network: n.fixed_ip_v4 if n.access_network][0]
570+
k3s_token = "{{ k3s_token }}"
551571
}
552572
}
553573

@@ -572,7 +592,7 @@ data "openstack_networking_floatingip_v2" "cluster_floating_ip" {
572592
{% endif %}
573593
}
574594

575-
resource "openstack_compute_floatingip_associate_v2" "login_floatingip_assoc" {
595+
resource "openstack_networking_floatingip_associate_v2" "login_floatingip_assoc" {
576596
floating_ip = "${data.openstack_networking_floatingip_v2.cluster_floating_ip.address}"
577-
instance_id = "${openstack_compute_instance_v2.login.id}"
597+
port_id = "${openstack_networking_port_v2.login.id}"
578598
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
k3s_version: "v1.31.0+k3s1"
1+
k3s_version: "v1.31.0+k3s1" # Warning: changes to this variable won't be reflected in the cluster/image if k3s is already installed

ansible/roles/k3s/files/start_k3s.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
service_name: "{{ 'k3s-agent' if k3s_server_name is defined else 'k3s' }}"
88
tasks:
99
- name: Add the token for joining the cluster to the environment
10-
no_log: false # avoid logging the server token
10+
no_log: true # avoid logging the server token
1111
ansible.builtin.lineinfile:
1212
path: "/etc/systemd/system/{{ service_name }}.service.env"
1313
line: "K3S_TOKEN={{ k3s_token }}"
@@ -18,15 +18,16 @@
1818
line: "K3S_URL=https://{{ k3s_server_name }}:6443"
1919
when: k3s_server_name is defined
2020

21-
- name: Add loadbalancer label to server
21+
- name: Only run loadbalancer on k3s server
22+
# avoids problems with Ondemand https server
2223
when: k3s_server_name is undefined
2324
block:
2425
- name: Create override directory
2526
ansible.builtin.file:
2627
state: directory
2728
path: "/etc/systemd/system/{{ service_name }}.service.d"
2829

29-
- name: Add label override
30+
- name: Set loadbalancer label on k3s server
3031
ansible.builtin.copy:
3132
dest: "/etc/systemd/system/{{ service_name }}.service.d/override.conf"
3233
content: |

ansible/roles/k3s/tasks/main.yml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
---
22

3-
- name: Download k3s install script
4-
ansible.builtin.get_url:
5-
url: https://get.k3s.io/
6-
timeout: 120
7-
dest: /usr/bin/k3s-install.sh
8-
owner: root
9-
group: root
10-
mode: "0755"
11-
12-
- name: Install k3s
13-
ansible.builtin.shell:
14-
cmd: /usr/bin/k3s-install.sh
15-
environment:
16-
INSTALL_K3S_VERSION: "{{ k3s_version }}"
17-
INSTALL_K3S_EXEC: "{{ item }}"
18-
INSTALL_K3S_SKIP_START: "true"
19-
INSTALL_K3S_SKIP_ENABLE: "true"
20-
INSTALL_K3S_BIN_DIR: "/usr/bin"
21-
changed_when: true
22-
loop:
23-
- server
24-
- agent
3+
- name: Check for existing k3s binaries
4+
stat:
5+
path: /usr/bin/k3s
6+
register: stat_result
7+
8+
- name: Download and install k3s
9+
when: not stat_result.stat.exists
10+
block:
11+
- name: Download k3s install script
12+
ansible.builtin.get_url:
13+
url: https://get.k3s.io/
14+
timeout: 120
15+
dest: /usr/bin/k3s-install.sh
16+
owner: root
17+
group: root
18+
mode: "0755"
19+
20+
- name: Install k3s
21+
ansible.builtin.shell:
22+
cmd: /usr/bin/k3s-install.sh
23+
environment:
24+
INSTALL_K3S_VERSION: "{{ k3s_version }}"
25+
INSTALL_K3S_EXEC: "{{ item }}"
26+
INSTALL_K3S_SKIP_START: "true"
27+
INSTALL_K3S_SKIP_ENABLE: "true"
28+
INSTALL_K3S_BIN_DIR: "/usr/bin"
29+
changed_when: true
30+
loop:
31+
- server
32+
- agent
2533

2634
- name: Install helm
2735
unarchive:

ansible/roles/passwords/defaults/main.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ slurm_appliance_secrets:
88
vault_openhpc_mungekey: "{{ secrets_openhpc_mungekey | default(vault_openhpc_mungekey | default(secrets_openhpc_mungekey_default)) }}"
99
vault_freeipa_ds_password: "{{ vault_freeipa_ds_password | default(lookup('password', '/dev/null')) }}"
1010
vault_freeipa_admin_password: "{{ vault_freeipa_admin_password | default(lookup('password', '/dev/null')) }}"
11+
k3s_token: "{{ lookup('ansible.builtin.password', '/dev/null', length=64) }}"
1112

1213
secrets_openhpc_mungekey_default:
1314
content: "{{ lookup('pipe', 'dd if=/dev/urandom bs=1 count=1024 2>/dev/null | base64') }}"
1415

15-
k3s_secrets:
16-
k3s_token: "{{ lookup('ansible.builtin.password', '/dev/null', length=64) }}"
17-
1816
openhpc_passwords_output_path: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') | default(undefined, true) | mandatory('You must define the APPLIANCES_ENVIRONMENT_ROOT environment variable') }}/inventory/group_vars/all/secrets.yml"

ansible/roles/passwords/tasks/main.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,7 @@
99

1010
- name: Template k3s token to terraform
1111
template:
12-
src: k3s-token.auto.tfvars.json
12+
src: k3s-token.auto.tfvars.json.j2
1313
dest: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}/terraform/k3s-token.auto.tfvars.json"
1414
delegate_to: localhost
1515
run_once: true
16-
17-
18-
# - name: Ensure munge key directory exists
19-
# file:
20-
# state: directory
21-
# recurse: true
22-
# path: "{{ openhpc_passwords_mungekey_output_path | dirname }}"
23-
24-
# - name: Create a munge key
25-
# copy:
26-
# content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}"
27-
# dest: "{{ openhpc_passwords_mungekey_output_path }}"
28-
# force: false

ansible/roles/passwords/templates/k3s-token.auto.tfvars.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"k3s_token": "{{ slurm_appliance_secrets.k3s_token }}"
3+
}

0 commit comments

Comments
 (0)