-
Notifications
You must be signed in to change notification settings - Fork 4
/
metrics_server.tf
73 lines (68 loc) · 2.12 KB
/
metrics_server.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
locals {
metrics_server_schedule_on_control_plane = coalesce(
var.metrics_server_schedule_on_control_plane,
local.worker_sum == 0,
false
)
metrics_server_node_sum = (
local.metrics_server_schedule_on_control_plane ?
local.control_plane_sum :
local.worker_sum > 0 ? local.worker_sum : local.cluster_autoscaler_max_sum
)
metrics_server_replicas = coalesce(
var.metrics_server_replicas,
local.metrics_server_node_sum > 1 ? 2 : 1
)
}
data "helm_template" "metrics_server" {
count = var.metrics_server_enabled ? 1 : 0
name = "metrics-server"
namespace = "kube-system"
repository = var.metrics_server_helm_repository
chart = var.metrics_server_helm_chart
version = var.metrics_server_helm_version
kube_version = var.kubernetes_version
values = [
yamlencode({
replicas = local.metrics_server_replicas
podDisruptionBudget = {
enabled = local.metrics_server_node_sum > 1
minAvailable = local.metrics_server_node_sum > 1 ? 1 : 0
}
topologySpreadConstraints = [
{
topologyKey = "kubernetes.io/hostname"
maxSkew = 1
whenUnsatisfiable = (
local.metrics_server_node_sum > local.metrics_server_replicas ?
"DoNotSchedule" :
"ScheduleAnyway"
)
labelSelector = {
matchLabels = {
"app.kubernetes.io/instance" = "metrics-server"
"app.kubernetes.io/name" = "metrics-server"
}
}
}
]
nodeSelector = local.metrics_server_schedule_on_control_plane ? {
"node-role.kubernetes.io/control-plane" = ""
} : {}
tolerations = local.metrics_server_schedule_on_control_plane ? [
{
key = "node-role.kubernetes.io/control-plane"
effect = "NoSchedule"
operator = "Exists"
}
] : []
}),
yamlencode(var.metrics_server_helm_values)
]
}
locals {
metrics_server_manifest = var.metrics_server_enabled ? {
name = "metrics-server"
contents = data.helm_template.metrics_server[0].manifest
} : null
}