Skip to content

Commit cfb5514

Browse files
committed
updated caas for k3s
1 parent 8f0923c commit cfb5514

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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/resources.tf.j2

Lines changed: 20 additions & 0 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

environments/.caas/hooks/pre.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
22

3+
# Generate k3s token
4+
- name: Generate k3s token
5+
hosts: openstack
6+
tasks:
7+
- ansible.builtin.set_fact:
8+
k3s_token: "{{ lookup('ansible.builtin.password', '/dev/null', length=64) }}"
9+
310
# Provision the infrastructure using Terraform
411
- name: Provision infrastructure
512
hosts: openstack

0 commit comments

Comments
 (0)