-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.tf
260 lines (220 loc) · 6.64 KB
/
common.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
data "ignition_systemd_unit" "update-engine" {
name = "update-engine.service"
mask = false == var.enable_container_linux_update-engine
}
data "ignition_file" "cfssl" {
path = "/opt/bin/cfssl"
mode = 493
source {
source = "https://github.com/cloudflare/cfssl/releases/download/v${var.cfssl_version}/cfssl_${var.cfssl_version}_linux_amd64"
verification = var.cfssl_binary_sha512
}
}
data "ignition_file" "cfssljson" {
path = "/opt/bin/cfssljson"
mode = 493
source {
source = "https://github.com/cloudflare/cfssl/releases/download/v${var.cfssl_version}/cfssljson_${var.cfssl_version}_linux_amd64"
verification = var.cfssljson_binary_sha512
}
}
data "template_file" "docker_opts_dropin" {
template = file("${path.module}/resources/docker-dropin.conf")
}
data "ignition_systemd_unit" "docker-opts-dropin" {
name = "docker.service"
dropin {
name = "10-custom-options.conf"
content = data.template_file.docker_opts_dropin.rendered
}
}
data "template_file" "node-exporter" {
template = file("${path.module}/resources/node-exporter.service")
vars = {
node_exporter_image_url = var.node_exporter_image_url
node_exporter_image_tag = var.node_exporter_image_tag
}
}
data "ignition_systemd_unit" "node-exporter" {
name = "node-exporter.service"
content = data.template_file.node-exporter.rendered
}
data "ignition_file" "format-and-mount" {
mode = 493
path = "/opt/bin/format-and-mount"
content {
content = file("${path.module}/resources/format-and-mount")
}
}
data "ignition_file" "kubelet" {
mode = 493
path = "/opt/bin/kubelet"
source {
source = "https://storage.googleapis.com/kubernetes-release/release/${var.kubernetes_version}/bin/linux/amd64/kubelet"
}
}
# Dir used by systemd to store logs in disk instead of memory
data "ignition_directory" "journald" {
path = "/var/log/journal"
}
data "ignition_file" "docker_daemon_json" {
mode = 493
path = "/etc/docker/daemon.json"
content {
content = templatefile("${path.module}/resources/docker_daemon.json",
{
dockerhub_mirror_endpoint = var.dockerhub_mirror_endpoint,
}
)
}
}
data "ignition_file" "docker-config" {
mode = 384
path = "/root/.docker/config.json"
content {
content = jsonencode(
{
auths = {
"https://index.docker.io/v1/" = {
auth = base64encode("${var.dockerhub_username}:${var.dockerhub_password}")
}
}
}
)
}
}
data "ignition_file" "kubelet-docker-config" {
mode = 384
path = "/var/lib/kubelet/config.json"
content {
content = jsonencode(
{
auths = {
"https://index.docker.io/v1/" = {
auth = base64encode("${var.dockerhub_username}:${var.dockerhub_password}")
}
}
}
)
}
}
data "ignition_file" "containerd_dockerio_hosts_toml" {
path = "/etc/containerd/certs.d/docker.io/hosts.toml"
mode = 384
content {
content = templatefile("${path.module}/resources/docker.io_hosts.toml",
{
dockerhub_mirror_endpoint = var.dockerhub_mirror_endpoint,
use_mirror = true
}
)
}
}
data "ignition_file" "containerd-config" {
path = "/etc/containerd/config.toml"
mode = 384
content {
content = templatefile("${path.module}/resources/containerd-config.toml",
{
containerd_log_level = var.containerd_log_level
dockerhub_username = var.dockerhub_username
dockerhub_password = var.dockerhub_password
}
)
}
}
data "ignition_systemd_unit" "containerd-dropin" {
name = "containerd.service"
dropin {
name = "10-custom-options.conf"
content = file("${path.module}/resources/containerd-dropin.conf")
}
}
data "ignition_file" "crictl-config" {
path = "/etc/crictl.yaml"
mode = 384
content {
content = file("${path.module}/resources/crictl.yaml")
}
}
data "ignition_file" "bashrc" {
path = "/home/core/.bashrc"
mode = 420
overwrite = true
uid = 500 # core
gid = 500 # core
content {
content = file("${path.module}/resources/bashrc")
}
}
data "ignition_file" "kubernetes_accounting_config" {
path = "/etc/systemd/system.conf.d/kubernetes-accounting.conf"
content {
content = file("${path.module}/resources/kubernetes-accounting.conf")
}
}
# Updating to flatcar 2983.2.0 surfaced an issue where inotify resources are
# exhausted on worker nodes. Increasing inotify watchers and instances was
# tested to mitigate this issue. Using values from:
# https://github.com/giantswarm/k8scloudconfig/blob/master/files/conf/hardening.conf
# Same approach also mentioned here:
# https://github.com/kubernetes/kubernetes/issues/64315#issuecomment-904103310
#
# vm.max_map_count=1048576 :: higher value is needed by Partner Kafka, but also
# matching Fedora + Arch Linux upstream:
# - https://fedoraproject.org/wiki/Changes/IncreaseVmMaxMapCount
# - https://archlinux.org/news/increasing-the-default-vmmax_map_count-value/
data "ignition_file" "sysctl_kernel_vars" {
mode = 420
path = "/etc/sysctl.d/kernel.conf"
content {
content = <<EOS
fs.inotify.max_user_watches=1048576
fs.inotify.max_user_instances=8192
vm.max_map_count=1048576
user.max_user_namespaces=0
EOS
}
}
# `touch` /boot/flatcar/first_boot to trigger ignition to run every time:
# https://flatcar-linux.org/docs/latest/provisioning/ignition/boot-process/#reprovisioning
# Useful when we want to fetch ignition updates during boot.
data "ignition_systemd_unit" "flatcar_first_boot" {
name = "ensure-flatcar-first-boot.service"
content = <<EOS
[Unit]
Description=touch /boot/flatcar/first_boot to trigger new ignition run on reboot
[Service]
Type=oneshot
ExecStart=/usr/bin/touch /boot/flatcar/first_boot
RemainAfterExit=true
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOS
}
# Specifies a root filesystem where we wipe the device before filesystem
# creation. When combined with ignition reprovisioning it can give us "fresh"
# nodes on reboot.
data "ignition_filesystem" "root_wipe_filesystem" {
device = "/dev/disk/by-partlabel/ROOT"
format = "ext4"
wipe_filesystem = true
label = "ROOT"
}
data "ignition_file" "aws_meta_data_IMDSv2" {
mode = 493
path = "/opt/bin/aws-imdsv2"
content {
content = <<EOS
#!/bin/sh
META_ENDPOINT=$1
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 600")
curl http://169.254.169.254/latest/meta-data/$META_ENDPOINT -H "X-aws-ec2-metadata-token: $TOKEN"
EOS
}
}
data "ignition_systemd_unit" "coreos_metadata_sshkeys" {
name = "coreos-metadata-sshkeys@core.service"
mask = false == var.enable_coreos_metadata_sshkeys_service
}