Skip to content

Commit 5a7c09e

Browse files
committed
support mapping to compute + login to ironic nodes
1 parent f23be23 commit 5a7c09e

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

environments/.stackhpc/terraform/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ module "cluster" {
7676
k3s_token = var.k3s_token
7777

7878
login_nodes = {
79-
login-0: var.other_node_flavor
79+
login-0 = {
80+
flavor: var.other_node_flavor
81+
}
8082
}
8183
compute = {
8284
standard: { # NB: can't call this default!
8385
nodes: ["compute-0", "compute-1"]
8486
flavor: var.other_node_flavor
8587
}
88+
8689
# Example of how to add another partition:
8790
# extra: {
8891
# nodes: ["compute-2", "compute-3"]

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
data "external" "nodes" {
2+
program = ["bash", "-c", <<-EOT
3+
openstack baremetal node list --limit 0 -f json 2>/dev/null | \
4+
jq -r 'try map( { (.Name|tostring): .UUID } ) | add catch {}' || echo '{}'
5+
EOT
6+
]
7+
}
8+
19
resource "openstack_networking_port_v2" "compute" {
210

311
for_each = toset(var.nodes)
@@ -50,6 +58,8 @@ resource "openstack_compute_instance_v2" "compute" {
5058
k3s_server = var.k3s_server
5159
}
5260

61+
availability_zone = var.match_ironic_node ? "${var.availability_zone}::${data.external.nodes.result[each.key]}" : var.availability_zone
62+
5363
user_data = <<-EOF
5464
#cloud-config
5565
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,16 @@ variable "k3s_server" {
7676
description = "Name/address of k3s server"
7777
type = string
7878
}
79+
80+
variable "match_ironic_node" {
81+
description = "Whether to launch instances on the Ironic node of the same name as this cluster node"
82+
type = bool
83+
default = false
84+
85+
}
86+
87+
variable availability_zone {
88+
description = "Name of availability zone. NB using ZONE:HOST or ZONE::NODE is not supported if setting match_ironic_node"
89+
type = string
90+
default = "nova"
91+
}

environments/skeleton/{{cookiecutter.environment}}/terraform/nodes.tf

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
locals {
22
control_volumes = concat([openstack_blockstorage_volume_v3.state], var.home_volume_size > 0 ? [openstack_blockstorage_volume_v3.home][0] : [])
3+
4+
login_node_defaults = {
5+
availability_zone = "nova"
6+
match_ironic_node = false
7+
}
8+
9+
login_nodes = {
10+
for nodename, cfg in var.login_nodes:
11+
nodename => merge(local.login_node_defaults, cfg)
12+
}
13+
}
14+
15+
data "external" "nodes" {
16+
# returns an empty map if cannot list baremetal nodes
17+
program = ["bash", "-c", <<-EOT
18+
openstack baremetal node list --limit 0 -f json 2>/dev/null | \
19+
jq -r 'try map( { (.Name|tostring): .UUID } ) | add catch {}' || echo '{}'
20+
EOT
21+
]
322
}
423

524
resource "openstack_networking_port_v2" "login" {
@@ -99,11 +118,11 @@ resource "openstack_compute_instance_v2" "control" {
99118

100119
resource "openstack_compute_instance_v2" "login" {
101120

102-
for_each = var.login_nodes
121+
for_each = local.login_nodes
103122

104123
name = "${var.cluster_name}-${each.key}"
105124
image_id = var.cluster_image_id
106-
flavor_name = each.value
125+
flavor_name = each.value.flavor
107126
key_pair = var.key_pair
108127

109128
dynamic "block_device" {
@@ -129,6 +148,8 @@ resource "openstack_compute_instance_v2" "login" {
129148
k3s_server = [for n in openstack_compute_instance_v2.control["control"].network: n.fixed_ip_v4 if n.access_network][0]
130149
}
131150

151+
availability_zone = each.value.match_ironic_node ? "${each.value.availability_zone}::${data.external.nodes.result[each.key]}" : each.value.availability_zone
152+
132153
user_data = <<-EOF
133154
#cloud-config
134155
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}

environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ variable "control_node_flavor" {
3131

3232
variable "login_nodes" {
3333
type = map
34-
description = "Mapping defining login nodes: key -> (str) nodename suffix, value -> (str) flavor name"
34+
description = <<-EOF
35+
Mapping defining login nodes. Keys are the node name suffix. Values are a mapping as follows:
36+
Required:
37+
flavor: String flavor name
38+
Optional:
39+
availability_zone: String, name of availability zone. NB using ZONE:HOST or ZONE::NODE is not supported if setting match_ironic_node
40+
match_ironic_node: Bool, whether to launch instances on the Ironic node of the same name as this cluster node
41+
EOF
3542
}
3643

3744
variable "cluster_image_id" {

0 commit comments

Comments
 (0)