Skip to content

Commit 9525f2c

Browse files
sjpbpriteau
andauthored
Support additional nodegroups (#704)
* Support fixed IP addresses for control node The variable control_ip_address was documented but not implemented. Since we support multiple networks, change it to control_ip_addresses and implement it. Closes #642. * Update environments/skeleton/{{cookiecutter.environment}}/tofu/variables.tf * tf style tweaks * update production docs for control_ip_addresses * fix control IP address logic * add validation for control_ip_addresses * remove fixed IPs from production docs - not standard process * support ip_addresses fo all nodes * make stackhpc tofu format consistent * add support for additional_nodegroups * add missing additional nodegroup file * rename additional tf file for consistency * support changing security groups for additional nodes * add node_fqdn from PR#702 to additional_nodes --------- Co-authored-by: Pierre Riteau <[email protected]>
1 parent 933dcf4 commit 9525f2c

File tree

6 files changed

+128
-2
lines changed

6 files changed

+128
-2
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
module "additional" {
2+
source = "./node_group"
3+
4+
for_each = var.additional_nodegroups
5+
6+
# must be set for group:
7+
nodes = each.value.nodes
8+
flavor = each.value.flavor
9+
10+
# always taken from top-level value:
11+
cluster_name = var.cluster_name
12+
cluster_domain_suffix = var.cluster_domain_suffix
13+
key_pair = var.key_pair
14+
environment_root = var.environment_root
15+
16+
# can be set for group, defaults to top-level value:
17+
image_id = lookup(each.value, "image_id", var.cluster_image_id)
18+
vnic_types = lookup(each.value, "vnic_types", var.vnic_types)
19+
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
20+
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
21+
root_volume_type = lookup(each.value, "root_volume_type", var.root_volume_type)
22+
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
23+
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
24+
25+
# optionally set for group:
26+
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
27+
# here null means "use module var default"
28+
extra_volumes = lookup(each.value, "extra_volumes", null)
29+
fip_addresses = lookup(each.value, "fip_addresses", null)
30+
fip_network = lookup(each.value, "fip_network", null)
31+
match_ironic_node = lookup(each.value, "match_ironic_node", null)
32+
availability_zone = lookup(each.value, "availability_zone", null)
33+
ip_addresses = lookup(each.value, "ip_addresses", null)
34+
security_group_ids = lookup(each.value, "security_group_ids", [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id])
35+
36+
# can't be set for additional nodes
37+
compute_init_enable = []
38+
ignore_image_changes = false
39+
40+
# computed
41+
# not using openstack_compute_instance_v2.control.access_ip_v4 to avoid
42+
# updates to node metadata on deletion/recreation of the control node:
43+
control_address = openstack_networking_port_v2.control[var.cluster_networks[0].network].all_fixed_ips[0]
44+
baremetal_nodes = data.external.baremetal_nodes.result
45+
46+
# input dict validation:
47+
group_name = each.key
48+
group_keys = keys(each.value)
49+
allowed_keys = [
50+
"nodes",
51+
"flavor",
52+
"image_id",
53+
"extra_networks",
54+
"vnic_types",
55+
"volume_backed_instances",
56+
"root_volume_size",
57+
"root_volume_type",
58+
"extra_volumes",
59+
"fip_addresses",
60+
"fip_network",
61+
"match_ironic_node",
62+
"availability_zone",
63+
"ip_addresses",
64+
"gateway_ip",
65+
"nodename_template",
66+
"security_group_ids",
67+
]
68+
}

environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ resource "local_file" "hosts" {
77
"control_fqdn": local.control_fqdn
88
"login_groups": module.login
99
"compute_groups": module.compute
10+
"additional_groups": module.additional
1011
"state_dir": var.state_dir
1112
"cluster_home_volume": var.home_volume_provisioning != "none"
1213
},

environments/skeleton/{{cookiecutter.environment}}/tofu/inventory.tpl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ control:
1515
vars:
1616
appliances_state_dir: ${state_dir} # NB needs to be set on group not host otherwise it is ignored in packer build!
1717

18+
# --- login nodes ---
1819
%{ for group_name in keys(login_groups) ~}
1920
${cluster_name}_${group_name}:
2021
hosts:
@@ -34,6 +35,7 @@ login:
3435
${cluster_name}_${group_name}:
3536
%{ endfor ~}
3637

38+
# --- compute nodes ---
3739
%{ for group_name in keys(compute_groups) ~}
3840
${cluster_name}_${group_name}:
3941
hosts:
@@ -47,10 +49,37 @@ ${cluster_name}_${group_name}:
4749
vars:
4850
# NB: this is the target image, not necessarily what is provisioned
4951
image_id: ${compute_groups[group_name]["image_id"]}
52+
53+
${group_name}:
54+
children:
55+
${cluster_name}_${group_name}:
56+
5057
%{ endfor ~}
5158

5259
compute:
5360
children:
5461
%{ for group_name in keys(compute_groups) ~}
5562
${cluster_name}_${group_name}:
5663
%{ endfor ~}
64+
65+
# --- additional nodes ---
66+
%{ for group_name in keys(additional_groups) ~}
67+
${cluster_name}_${group_name}:
68+
hosts:
69+
%{ for nodename, node in additional_groups[group_name]["compute_instances"] ~}
70+
${ node.name }:
71+
ansible_host: ${node.access_ip_v4}
72+
instance_id: ${ node.id }
73+
networks: ${jsonencode({for n in node.network: n.name => {"fixed_ip_v4": n.fixed_ip_v4, "fixed_ip_v6": n.fixed_ip_v6}})}
74+
node_fqdn: ${additional_groups[group_name]["fqdns"][nodename]}
75+
%{ endfor ~}
76+
${group_name}:
77+
children:
78+
${cluster_name}_${group_name}:
79+
80+
%{ endfor ~}
81+
additional:
82+
children:
83+
%{ for group_name in keys(additional_groups) ~}
84+
${cluster_name}_${group_name}:
85+
%{ endfor ~}

environments/skeleton/{{cookiecutter.environment}}/tofu/login.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module "login" {
2222
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
2323
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
2424

25-
# optionally set for group
25+
# optionally set for group:
2626
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
2727
# here null means "use module var default"
2828
extra_volumes = lookup(each.value, "extra_volumes", null)

environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ variable "extra_volumes" {
7272
}
7373

7474
variable "security_group_ids" {
75-
type = list
75+
type = list(string)
76+
nullable = false
7677
}
7778

7879
variable "control_address" {

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,38 @@ variable "compute" {
125125
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
126126
gateway_ip: Address to add default route via
127127
nodename_template: Overrides variable cluster_nodename_template
128+
129+
Nodes are added to the following inventory groups:
130+
- $group_name
131+
- $cluster_name + '_' + $group_name - this is used for the stackhpc.openhpc role
132+
- 'compute'
128133
EOF
129134

130135
type = any # can't do any better; TF type constraints can't cope with heterogeneous inner mappings
131136
}
132137

138+
variable "additional_nodegroups" {
139+
default = {}
140+
description = <<-EOF
141+
Mapping defining homogenous groups of nodes for arbitrary purposes.
142+
These nodes are not in the compute or login inventory groups so they
143+
will not run slurmd.
144+
145+
Keys are names of groups.
146+
Values are a mapping as for the "login" variable, with the addition of
147+
the optional entry:
148+
149+
security_group_ids: List of strings giving IDs of security groups
150+
to apply. If not specified the groups from the
151+
variable nonlogin_security_groups are applied.
152+
153+
Nodes are added to the following inventory groups:
154+
- $group_name
155+
- $cluster_name + '_' + $group_name
156+
- 'additional'
157+
EOF
158+
}
159+
133160
variable "environment_root" {
134161
type = string
135162
description = "Path to environment root, automatically set by activate script"

0 commit comments

Comments
 (0)