-
Notifications
You must be signed in to change notification settings - Fork 4
/
autoscaler.tf
127 lines (119 loc) · 3.43 KB
/
autoscaler.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
locals {
cluster_autoscaler_enabled = length(local.cluster_autoscaler_nodepools) > 0
cluster_autoscaler_cluster_config = local.cluster_autoscaler_enabled ? {
imagesForArch = {
arm64 = local.image_label_selector,
amd64 = local.image_label_selector
},
nodeConfigs = {
for nodepool in local.cluster_autoscaler_nodepools : "${var.cluster_name}-${nodepool.name}" => {
cloudInit = data.talos_machine_configuration.cluster_autoscaler[nodepool.name].machine_configuration,
labels = nodepool.labels
taints = nodepool.taints
}
}
} : null
}
data "helm_template" "cluster_autoscaler" {
count = local.cluster_autoscaler_enabled ? 1 : 0
name = "cluster-autoscaler"
namespace = "kube-system"
repository = var.cluster_autoscaler_helm_repository
chart = var.cluster_autoscaler_helm_chart
version = var.cluster_autoscaler_helm_version
kube_version = var.kubernetes_version
set {
name = "image.tag"
value = "v1.31.1"
}
set {
name = "cloudProvider"
value = "hetzner"
}
set {
name = "extraEnvSecrets.HCLOUD_TOKEN.name"
value = "hcloud"
}
set {
name = "extraEnvSecrets.HCLOUD_TOKEN.key"
value = "token"
}
set {
name = "extraEnv.HCLOUD_CLUSTER_CONFIG"
value = base64encode(jsonencode(local.cluster_autoscaler_cluster_config))
}
set {
name = "extraEnv.HCLOUD_SERVER_CREATION_TIMEOUT"
value = 10
}
set {
name = "extraEnv.HCLOUD_FIREWALL"
value = hcloud_firewall.this.id
}
set {
name = "extraEnv.HCLOUD_SSH_KEY"
value = hcloud_ssh_key.this.id
}
set {
name = "extraEnv.HCLOUD_PUBLIC_IPV4"
value = var.talos_public_ipv4_enabled
}
set {
name = "extraEnv.HCLOUD_PUBLIC_IPV6"
value = var.talos_public_ipv6_enabled
}
set {
name = "extraEnv.HCLOUD_NETWORK"
value = hcloud_network_subnet.autoscaler.network_id
}
values = [
yamlencode({
replicaCount = local.control_plane_sum > 1 ? 2 : 1
podDisruptionBudget = {
maxUnavailable = null
minAvailable = local.control_plane_sum > 1 ? 1 : 0
}
topologySpreadConstraints = [
{
topologyKey = "kubernetes.io/hostname"
maxSkew = 1
whenUnsatisfiable = local.control_plane_sum > 2 ? "DoNotSchedule" : "ScheduleAnyway"
labelSelector = {
matchLabels = {
"app.kubernetes.io/instance" = "cluster-autoscaler"
"app.kubernetes.io/name" = "hetzner-cluster-autoscaler"
}
}
}
],
nodeSelector = { "node-role.kubernetes.io/control-plane" : "" }
tolerations = [
{
key = "node-role.kubernetes.io/control-plane"
effect = "NoSchedule"
operator = "Exists"
}
]
autoscalingGroups = [
for np in local.cluster_autoscaler_nodepools : {
name = "${var.cluster_name}-${np.name}",
minSize = np.min,
maxSize = np.max,
instanceType = np.server_type,
region = np.location
}
]
}),
yamlencode(var.cluster_autoscaler_helm_values)
]
depends_on = [
terraform_data.amd64_image,
terraform_data.arm64_image,
]
}
locals {
cluster_autoscaler_manifest = local.cluster_autoscaler_enabled ? {
name = "cluster-autoscaler"
contents = data.helm_template.cluster_autoscaler[0].manifest
} : null
}