Skip to content

Commit dbf1422

Browse files
authored
Validate nodegroup names (#793)
* validate nodename groups * add validation for nodegroup name clashes * add validation for nodegroup name clashes * fix linter whinges * extend validation to cover additional_nodegroups * fix TF linting * fixup logic * fix logic * fix linter
1 parent 67b2658 commit dbf1422

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cluster_net = "portal-internal"
2-
cluster_subnet = "portal-internal"
1+
cluster_net = "portal-internal"
2+
cluster_subnet = "portal-internal"
33
control_node_flavor = "vm.ska.cpu.general.eighth"
4-
other_node_flavor = "vm.ska.cpu.general.small"
4+
other_node_flavor = "vm.ska.cpu.general.small"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
cluster_networks = [
2-
{
3-
network = "stackhpc-dev"
4-
subnet = "stackhpc-dev"
5-
}
2+
{
3+
network = "stackhpc-dev"
4+
subnet = "stackhpc-dev"
5+
}
66
]
77
control_node_flavor = "ec1.medium" # small ran out of memory, medium gets down to ~100Mi mem free on deployment
8-
other_node_flavor = "en1.xsmall"
9-
state_volume_type = "unencrypted"
10-
home_volume_type = "unencrypted"
8+
other_node_flavor = "en1.xsmall"
9+
state_volume_type = "unencrypted"
10+
home_volume_type = "unencrypted"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
cluster_networks = [
2-
{
3-
network = "slurmapp-ci"
4-
subnet = "slurmapp-ci"
5-
}
2+
{
3+
network = "slurmapp-ci"
4+
subnet = "slurmapp-ci"
5+
}
66
]
77
control_node_flavor = "ec1.medium" # small ran out of memory, medium gets down to ~100Mi mem free on deployment
8-
other_node_flavor = "en1.xsmall"
9-
state_volume_type = "unencrypted"
10-
home_volume_type = "unencrypted"
8+
other_node_flavor = "en1.xsmall"
9+
state_volume_type = "unencrypted"
10+
home_volume_type = "unencrypted"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
cluster_networks = [
2-
{
3-
network = "stackhpc-ipv4-geneve"
4-
subnet = "stackhpc-ipv4-geneve-subnet"
5-
}
2+
{
3+
network = "stackhpc-ipv4-geneve"
4+
subnet = "stackhpc-ipv4-geneve-subnet"
5+
}
66
]
77
control_node_flavor = "general.v1.small"
8-
other_node_flavor = "general.v1.small"
8+
other_node_flavor = "general.v1.small"

environments/.stackhpc/tofu/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module "cluster" {
7676
control_node_flavor = var.control_node_flavor
7777

7878
login = {
79-
login = {
79+
head = {
8080
nodes = ["login-0"]
8181
flavor = var.other_node_flavor
8282
}

environments/site/tofu/variables.tf

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ variable "login" {
5252
be useful for e.g. separating nodes for ssh and Open Ondemand usage, or
5353
to define login nodes with different capabilities such as high-memory.
5454
55-
Keys are names of groups.
55+
Keys are names of groups, and cannot be 'login', 'compute', 'control', or
56+
keys in the compute or additional_nodegroups variables.
5657
Values are a mapping as follows:
5758
5859
Required:
@@ -88,6 +89,25 @@ variable "login" {
8889
EOF
8990

9091
type = any
92+
validation {
93+
condition = length(setintersection(keys(var.login), ["login", "compute", "control"])) == 0
94+
error_message = <<-EOF
95+
Login nodegroup names cannot be 'login', 'compute' or 'control'. Invalid var.login key(s): ${join(", ", setintersection(keys(var.login), ["login", "compute", "control"]))}.
96+
EOF
97+
}
98+
validation {
99+
condition = length(distinct(concat(keys(var.login), keys(var.compute), keys(var.additional_nodegroups)))) == length(concat(keys(var.login), keys(var.compute), keys(var.additional_nodegroups)))
100+
error_message = <<-EOF
101+
Nodegroup names must be unique. Shared key(s) found in variables login, compute and/or additional_nodegroups: ${
102+
join(", ", setunion(
103+
setintersection(keys(var.login), keys(var.compute)),
104+
setintersection(keys(var.compute), keys(var.additional_nodegroups)),
105+
setintersection(keys(var.additional_nodegroups), keys(var.login))
106+
))
107+
}
108+
EOF
109+
110+
}
91111
}
92112

93113
variable "cluster_image_id" {
@@ -101,7 +121,8 @@ variable "compute" {
101121
Mapping defining homogenous groups of compute nodes. Groups are used
102122
in Slurm partition definitions.
103123
104-
Keys are names of groups.
124+
Keys are names of groups, and cannot be 'compute', 'login', 'control', 'default'
125+
or keys in the login or additional_nodegroups variables.
105126
Values are a mapping as follows:
106127
107128
Required:
@@ -139,6 +160,12 @@ variable "compute" {
139160
EOF
140161

141162
type = any # can't do any better; TF type constraints can't cope with heterogeneous inner mappings
163+
validation {
164+
condition = length(setintersection(keys(var.compute), ["login", "compute", "control", "default"])) == 0
165+
error_message = <<-EOF
166+
Compute nodegroup names cannot be 'compute', 'default', 'login' or 'control'. Invalid var.compute key(s): ${join(", ", setintersection(keys(var.compute), ["login", "compute", "control", "default"]))}.
167+
EOF
168+
}
142169
}
143170

144171
# tflint-ignore: terraform_typed_variables
@@ -149,7 +176,8 @@ variable "additional_nodegroups" {
149176
These nodes are not in the compute or login inventory groups so they
150177
will not run slurmd.
151178
152-
Keys are names of groups.
179+
Keys are names of groups and cannot be 'login', 'compute, 'control', or
180+
keys in the login or additional_nodegroups variables.
153181
Values are a mapping as for the "login" variable, with the addition of
154182
the optional entry:
155183
@@ -162,6 +190,13 @@ variable "additional_nodegroups" {
162190
- $cluster_name + '_' + $group_name
163191
- 'additional'
164192
EOF
193+
type = any # can't do any better; TF type constraints can't cope with heterogeneous inner mappings
194+
validation {
195+
condition = length(setintersection(keys(var.additional_nodegroups), ["login", "compute", "control"])) == 0
196+
error_message = <<-EOF
197+
Additional nodegroup names cannot be 'compute', 'login' or 'control'. Invalid var.additional_nodegroups key(s): ${join(", ", setintersection(keys(var.additional_nodegroups), ["login", "compute", "control"]))}.
198+
EOF
199+
}
165200
}
166201

167202
variable "environment_root" {

0 commit comments

Comments
 (0)