Skip to content

Commit 0f98d14

Browse files
committed
feat(hetzner): optionally prevent workloads running on manager nodes
1 parent 44e2f97 commit 0f98d14

File tree

6 files changed

+72
-2
lines changed

6 files changed

+72
-2
lines changed

modules/hetzner/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ No modules.
6161
| <a name="input_network_subnet"></a> [network\_subnet](#input\_network\_subnet) | Subnet of the main network | `string` | `"10.0.0.0/16"` | no |
6262
| <a name="input_network_type"></a> [network\_type](#input\_network\_type) | Type of network to use | `string` | `"cloud"` | no |
6363
| <a name="input_region"></a> [region](#input\_region) | Region to use. This covers multiple datacentres. | `string` | `"eu-central"` | no |
64+
| <a name="input_schedule_workloads_on_manager_nodes"></a> [schedule\_workloads\_on\_manager\_nodes](#input\_schedule\_workloads\_on\_manager\_nodes) | Allow scheduling of workloads of manager nodes. | `bool` | `true` | no |
6465
| <a name="input_ssh_key"></a> [ssh\_key](#input\_ssh\_key) | Path to the private SSH key | `string` | `"~/.ssh/id_ed25519"` | no |
6566
| <a name="input_ssh_key_public"></a> [ssh\_key\_public](#input\_ssh\_key\_public) | Path to the public SSH key | `string` | `"~/.ssh/id_ed25519.pub"` | no |
6667
| <a name="input_ssh_port"></a> [ssh\_port](#input\_ssh\_port) | Port to use for SSH access | `number` | `2244` | no |

modules/hetzner/k3s.tf

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ locals {
3434
kube-proxy-arg = "metrics-bind-address=0.0.0.0"
3535
kube-scheduler-arg = "bind-address=0.0.0.0"
3636
node-label = [for l in var.k3s_manager_pool.labels : "${l.key}=${l.value}"]
37-
node-taint = [for t in var.k3s_manager_pool.taints : "${t.key}=${t.value}:${t.effect}"]
38-
service-cidr = var.k3s_service_cidr
37+
node-taint = [for t in concat(
38+
var.schedule_workloads_on_manager_nodes ? [] : [
39+
{
40+
key = "CriticalAddonsOnly"
41+
value = "true"
42+
effect = "NoExecute"
43+
}
44+
],
45+
var.k3s_manager_pool.taints
46+
) : "${t.key}=${t.value}:${t.effect}"]
47+
service-cidr = var.k3s_service_cidr
3948
tls-san = concat(
4049
[local.k3s_access_address],
4150
[for o in hcloud_server.manager : tolist(o.network)[0].ip]

modules/hetzner/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ variable "region" {
172172
default = "eu-central"
173173
}
174174

175+
variable "schedule_workloads_on_manager_nodes" {
176+
type = bool
177+
description = "Allow scheduling of workloads of manager nodes."
178+
default = true
179+
}
180+
175181
variable "ssh_key" {
176182
type = string
177183
description = "Path to the private SSH key"

modules/kubernetes/autoscaler.tf

+22
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,26 @@ resource "helm_release" "cluster_autoscaler" {
9090
name = "podAnnotations.secret"
9191
value = sha512(yamlencode(kubernetes_secret_v1.cluster_autoscaler[count.index].data))
9292
}
93+
94+
# Allow running on control plane nodes
95+
dynamic "set" {
96+
for_each = flatten([
97+
for i, taint in local.control_plane_taints :
98+
[
99+
for k, v in taint :
100+
[
101+
{
102+
name = "tolerations[${i}].${k}"
103+
value = v
104+
},
105+
]
106+
]
107+
])
108+
iterator = each
109+
110+
content {
111+
name = each.value.name
112+
value = each.value.value
113+
}
114+
}
93115
}

modules/kubernetes/hetzner.tf

+26
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,30 @@ resource "helm_release" "hcloud_csi" {
7575
name = "controller.podAnnotations.secret"
7676
value = sha512(yamlencode(kubernetes_secret_v1.hcloud.data))
7777
}
78+
79+
# Allow running on control plane nodes
80+
dynamic "set" {
81+
for_each = flatten([
82+
for i, taint in local.control_plane_taints :
83+
[
84+
for k, v in taint :
85+
[
86+
{
87+
name = "controller.tolerations[${i}].${k}"
88+
value = v
89+
},
90+
{
91+
name = "node.tolerations[${i}].${k}"
92+
value = v
93+
},
94+
]
95+
]
96+
])
97+
iterator = each
98+
99+
content {
100+
name = each.value.name
101+
value = each.value.value
102+
}
103+
}
78104
}

modules/kubernetes/locals.tf

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
# limitations under the License.
1414

1515
locals {
16+
control_plane_taints = [
17+
{
18+
key = "CriticalAddonsOnly"
19+
operator = "Exists"
20+
},
21+
]
1622
kubeconfig = yamldecode(var.kubeconfig)
1723
kubeconfig_clusters = { for context in local.kubeconfig.clusters : context.name => context.cluster }
1824
kubeconfig_users = { for context in local.kubeconfig.users : context.name => context.user }

0 commit comments

Comments
 (0)