forked from StarpTech/k-andy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrades.tf
127 lines (124 loc) · 3.25 KB
/
upgrades.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
data "kubectl_file_documents" "upgrade_controller" {
content = var.enable_upgrade_controller ? templatefile("${path.module}/manifests/upgrade-controller.yaml", {
upgrade_controller_image_tag = var.upgrade_controller_image_tag
}) : ""
}
resource "kubectl_manifest" "upgrade_controller" {
for_each = data.kubectl_file_documents.upgrade_controller.manifests
yaml_body = each.value
}
resource "kubectl_manifest" "upgrade_plan_control_plane" {
count = var.upgrade_k3s_target_version != null && var.enable_upgrade_controller ? 1 : 0
yaml_body = yamlencode({
apiVersion = "upgrade.cattle.io/v1"
kind = "Plan"
metadata = {
labels = {
"k3s-upgrade" = "server"
}
name = "k3s-server"
namespace = "system-upgrade"
}
spec = {
version = var.upgrade_k3s_target_version
concurrency = 1
cordon = true
serviceAccountName = "system-upgrade"
upgrade = {
image = "rancher/k3s-upgrade"
}
nodeSelector = {
matchExpressions = [
{
"key" = "k3s-upgrade"
"operator" = "Exists"
},
{
"key" = "k3s-upgrade"
"operator" = "NotIn"
"values" = [
"disabled",
"false",
]
},
{
"key" = "node-role.kubernetes.io/master"
"operator" = "In"
"values" = [
"true",
]
},
]
}
tolerations = concat([
{
"key" = "node-role.kubernetes.io/master"
"operator" = "Exists"
"effect" = "NoSchedule"
},
{
"key" = "CriticalAddonsOnly"
"operator" = "Exists"
"effect" = "NoExecute"
},
], var.upgrade_node_additional_tolerations)
}
})
}
resource "kubectl_manifest" "upgrade_plan_agents" {
count = var.upgrade_k3s_target_version != null && var.enable_upgrade_controller ? 1 : 0
yaml_body = yamlencode({
apiVersion = "upgrade.cattle.io/v1"
kind = "Plan"
metadata = {
labels = {
"k3s-upgrade" = "agent"
}
name = "k3s-agent"
namespace = "system-upgrade"
}
spec = {
version = var.upgrade_k3s_target_version
concurrency = 1
drain = {
force = true
skipWaitForDeleteTimeout = 60
}
serviceAccountName = "system-upgrade"
prepare = {
args = [
"prepare",
"k3s-server",
]
image = "rancher/k3s-upgrade"
}
upgrade = {
image = "rancher/k3s-upgrade"
}
nodeSelector = {
matchExpressions = [
{
"key" = "k3s-upgrade"
"operator" = "Exists"
},
{
"key" = "k3s-upgrade"
"operator" = "NotIn"
"values" = [
"disabled",
"false",
]
},
{
"key" = "node-role.kubernetes.io/master"
"operator" = "NotIn"
"values" = [
"true",
]
},
]
}
tolerations = var.upgrade_node_additional_tolerations
}
})
}