-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathconfigure
executable file
·596 lines (508 loc) · 21.4 KB
/
configure
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#!/usr/bin/env bash
set -eux
source $SNAP/actions/common/utils.sh
use_snap_env
# Make sure either the install hook has run or we are refreshing an already existing snap as indicated
# by the existence of certificates.
if [ ! -f "${SNAP_DATA}/var/lock/installed.lock" ] && [ ! -f ${SNAP_DATA}/certs/csr.conf.template ]
then
exit 0
fi
if is_strict
then
echo "Checking snap interfaces..."
check_snap_interfaces # Check for interfaces but do not start until this script has run.
else
# In classic we do not make use of the status flag. Here we clean any "blocked" message that may have
# come from a failed strict deployment
snapctl set-health okay
fi
need_api_restart=false
need_cluster_agent_restart=false
need_proxy_restart=false
need_kubelet_restart=false
need_controller_restart=false
need_scheduler_restart=false
# Try to symlink /var/lib/kubelet so that most kubelet device plugins work out of the box.
if ! [ -e /var/lib/kubelet ] && ln -s $SNAP_COMMON/var/lib/kubelet /var/lib/kubelet; then
echo "/var/lib/kubelet linked to $SNAP_COMMON"
fi
SNAP_DATA_CURRENT=`echo "${SNAP_DATA}" | sed -e "s,${SNAP_REVISION},current,"`
# Try to symlink /var/lib/calico so that the Calico CNI plugin picks up the mtu configuration.
if ! [ -e /var/lib/calico ]; then
if ln -s $SNAP_DATA_CURRENT/var/lib/calico /var/lib/calico; then
echo "/var/lib/calico linked to $SNAP_DATA_CURRENT/var/lib/calico"
fi
fi
# Try to symlink standard CNI Kubernetes directories.
if ! [ -e /etc/cni/net.d ]; then
if mkdir -p /etc/cni && ln -s $SNAP_DATA_CURRENT/args/cni-network /etc/cni/net.d; then
echo "/etc/cni/net.d linked to $SNAP_DATA_CURRENT/args/cni-network"
fi
fi
if ! [ -e /opt/cni/bin ]; then
if mkdir -p /opt/cni && ln -s $SNAP_DATA_CURRENT/opt/cni/bin /opt/cni/bin; then
echo "/opt/cni/bin linked to $SNAP_DATA_CURRENT/opt/cni/bin"
fi
fi
# If the configurations directory is missing from SNAP_COMMON, we are upgrading from an older MicroK8s version.
if [ ! -d "${SNAP_COMMON}/etc/launcher" ]
then
mkdir -p "${SNAP_COMMON}/etc/launcher"
fi
# snap set microk8s config="$(cat config.yaml)"
config="$(snapctl get config || true)"
if [ ! -z "${config}" ]
then
# Only write config file if not already applied.
applied_config="$(cat ${SNAP_COMMON}/etc/launcher/snap-set.yaml.applied || true)"
if [ -z "${applied_config}" ] || [ "${config}" != "${applied_config}" ]
then
echo "${config}" > "${SNAP_COMMON}/etc/launcher/snap-set.yaml"
fi
fi
# If the addons directory is missing from SNAP_COMMON, then we are upgrading from an older MicroK8s version.
if [ ! -d "${SNAP_COMMON}/addons" ]
then
mkdir -p ${SNAP_COMMON}/addons
snap_current=`echo "${SNAP}" | sed -e "s,${SNAP_REVISION},current,"`
for addon in $(cat "${SNAP}/addons/.auto-add"); do
"${SNAP}/git.wrapper" clone "${snap_current}/addons/${addon}" "${SNAP_COMMON}/addons/${addon}"
done
fi
if [ ! -d "${SNAP_COMMON}/plugins" ]
then
mkdir -p ${SNAP_COMMON}/plugins
fi
#Allow the ability to add external IPs to the csr, by moving the csr.conf.template to SNAP_DATA
# TODO(neoaggelos): investigate if this is needed
if [ ! -f ${SNAP_DATA}/certs/csr.conf.template ]
then
cp ${SNAP}/certs/csr.conf.template ${SNAP_DATA}/certs/csr.conf.template
fi
# Enable the aggregation layer
if ! grep "requestheader-client-ca-file" ${SNAP_DATA}/args/kube-apiserver
then
echo "Patching requestheader-client-ca-file argument"
# Add a new line at the end
echo "" >> ${SNAP_DATA}/args/kube-apiserver
echo "--requestheader-client-ca-file=\${SNAP_DATA}/certs/front-proxy-ca.crt" >> ${SNAP_DATA}/args/kube-apiserver
need_api_restart=true
fi
# Enable the aggregation layer (continue)
if ! grep -E -- '--(requestheader-allowed-names|requestheader-extra-headers-prefix|requestheader-group-headers|requestheader-username-headers|proxy-client-cert-file|proxy-client-key-file)=' ${SNAP_DATA}/args/kube-apiserver
then
echo "Enabling Enable the aggregation layer"
echo "" >> ${SNAP_DATA}/args/kube-apiserver
echo '--requestheader-allowed-names=front-proxy-client' >> ${SNAP_DATA}/args/kube-apiserver
echo '--requestheader-extra-headers-prefix=X-Remote-Extra-' >> ${SNAP_DATA}/args/kube-apiserver
echo '--requestheader-group-headers=X-Remote-Group' >> ${SNAP_DATA}/args/kube-apiserver
echo '--requestheader-username-headers=X-Remote-User' >> ${SNAP_DATA}/args/kube-apiserver
echo '--proxy-client-cert-file=${SNAP_DATA}/certs/front-proxy-client.crt' >> ${SNAP_DATA}/args/kube-apiserver
echo '--proxy-client-key-file=${SNAP_DATA}/certs/front-proxy-client.key' >> ${SNAP_DATA}/args/kube-apiserver
need_api_restart=true
fi
# Patch for issue: https://github.com/canonical/microk8s/issues/121
if grep -e "requestheader-client-ca-file=/var/snap/microk8s/.../certs/ca.crt" ${SNAP_DATA}/args/kube-apiserver
then
"$SNAP/bin/sed" -i 's@requestheader-client-ca-file=/var/snap/microk8s/.../certs/ca.crt@requestheader-client-ca-file=\${SNAP_DATA}/certs/ca.crt@g' ${SNAP_DATA}/args/kube-apiserver
fi
# Patch for issue: https://github.com/canonical/microk8s/issues/721
if grep -F 'requestheader-client-ca-file=${SNAP_DATA}/certs/ca.crt' ${SNAP_DATA}/args/kube-apiserver
then
"$SNAP/bin/sed" -i 's@requestheader-client-ca-file=${SNAP_DATA}/certs/ca.crt@requestheader-client-ca-file=${SNAP_DATA}/certs/front-proxy-ca.crt@g' ${SNAP_DATA}/args/kube-apiserver
fi
# Create the locks directory
mkdir -p ${SNAP_DATA}/var/lock/
# Create tmp directory
mkdir -p ${SNAP_DATA}/tmp/
# This will allow us to refresh the snap to the more secure version.
# We need to make sure the client certificate used in microk8s kubectl is available under $SNAP_DATA
# TODO(neoaggelos): investigate whether this is needed
if [ ! -f ${SNAP_DATA}/credentials/client.config ]
then
echo "Patching client config location"
mkdir -p ${SNAP_DATA}/credentials/
cp ${SNAP}/client.config ${SNAP_DATA}/credentials/
fi
# copy kubectl-env
if [ ! -e ${SNAP_DATA}/args/kubectl-env ] && grep -e "\-\-kubeconfig=\${SNAP_DATA}/credentials/client.config" ${SNAP_DATA}/args/kubectl
then
echo "Making sure we have kubectl environment file"
cp ${SNAP}/default-args/kubectl-env ${SNAP_DATA}/args/kubectl-env
skip_opt_in_config kubeconfig kubectl
fi
# copy kubectl
if [ ! -e ${SNAP_DATA}/args/kubectl ]
then
echo "Making sure we have kubectl arguments file"
cp ${SNAP}/default-args/kubectl ${SNAP_DATA}/args/kubectl
fi
# copy traefik
if [ ! -e ${SNAP_DATA}/args/traefik ]
then
echo "Making sure we have traefik configuration"
cp -r ${SNAP}/default-args/traefik ${SNAP_DATA}/args/
fi
# copy apiserver-proxy
if [ ! -e ${SNAP_DATA}/args/apiserver-proxy ]
then
echo "Making sure we have apiserver-proxy configuration"
cp -r ${SNAP}/default-args/apiserver-proxy ${SNAP_DATA}/args/
fi
# (1.24 -> 1.25) migrate from traefik to apiserver-proxy
if [ -e ${SNAP_DATA}/var/lock/no-traefik ]
then
touch ${SNAP_DATA}/var/lock/no-apiserver-proxy
fi
# Upgrading to containerd
if [ ! -e ${SNAP_DATA}/args/containerd ] ||
grep -e "\-\-docker unix://\${SNAP_DATA}/docker.sock" ${SNAP_DATA}/args/kubelet
then
echo "Making sure we have containerd file"
cp ${SNAP_DATA}/args/containerd ${SNAP_DATA}/args/containerd.backup || true
cp ${SNAP}/default-args/containerd ${SNAP_DATA}/args/containerd
cp ${SNAP_DATA}/args/containerd-template.toml ${SNAP_DATA}/args/containerd-template.toml.backup || true
cp ${SNAP}/default-args/containerd-template.toml ${SNAP_DATA}/args/containerd-template.toml
cp ${SNAP_DATA}/args/containerd-env ${SNAP_DATA}/args/containerd-env.backup || true
cp ${SNAP}/default-args/containerd-env ${SNAP_DATA}/args/containerd-env
cp -r ${SNAP}/default-args/cni-network ${SNAP_DATA}/args/
cp ${SNAP}/default-args/ctr ${SNAP_DATA}/args/ctr
refresh_opt_in_config container-runtime remote kubelet
refresh_opt_in_config container-runtime-endpoint \${SNAP_COMMON}/run/containerd.sock kubelet
skip_opt_in_config docker-root kubelet
skip_opt_in_config docker kubelet
skip_opt_in_config docker-endpoint kubelet
snapctl restart ${SNAP_NAME}.daemon-containerd
need_kubelet_restart=true
if [ -e ${SNAP_DATA}/args/dockerd ] && grep -e "default-runtime=nvidia" ${SNAP_DATA}/args/dockerd
then
# Deployment used to run docker with nvidia enabled we need to enable nvidia on containerd
# Allow for kubelet and containerd to restart
sleep 10
${SNAP}/microk8s-enable.wrapper gpu
fi
fi
# Install default-hooks
if ! [ -d "${SNAP_COMMON}/hooks" ]
then
cp -r --preserve=mode ${SNAP}/default-hooks ${SNAP_COMMON}/hooks
fi
# (1.28 -> 1.29) Install 10-pods-restart hook if missing
if ! [ -e "${SNAP_COMMON}/hooks/reconcile.d/10-pods-restart" ]; then
cp -r --preserve=mode "${SNAP}/default-hooks/reconcile.d/10-pods-restart" "${SNAP_COMMON}/hooks/reconcile.d/10-pods-restart"
fi
# Make sure the server certificate includes the IP we are using
if [ "$(produce_certs)" == "1" ]
then
rm -rf .srl
need_api_restart=true
need_proxy_restart=true
need_cluster_agent_restart=true
fi
# Make containerd stream server listen to localhost
if [ -e ${SNAP_DATA}/args/containerd-template.toml ] && grep -e "stream_server_address = \"\"" ${SNAP_DATA}/args/containerd-template.toml
then
"$SNAP/bin/sed" -i 's@stream_server_address = ""@stream_server_address = "127.0.0.1"@g' ${SNAP_DATA}/args/containerd-template.toml
if grep -e "stream_server_port = \"10010\"" ${SNAP_DATA}/args/containerd-template.toml
then
"$SNAP/bin/sed" -i 's@stream_server_port = "10010"@stream_server_port = "0"@g' ${SNAP_DATA}/args/containerd-template.toml
fi
snapctl restart ${SNAP_NAME}.daemon-containerd
need_kubelet_restart=true
fi
# With v1.15 allow-privileged is removed from kubelet
if grep -e "\-\-allow-privileged" ${SNAP_DATA}/args/kubelet
then
echo "Patching 1.15 allow-privileged"
"${SNAP}/bin/sed" -i '/allow-privileged/d' ${SNAP_DATA}/args/kubelet
need_kubelet_restart=true
fi
# Add option to support kata containers
if [ -e "${SNAP_DATA}/args/containerd-env" ] &&
! grep -e "KATA_PATH" ${SNAP_DATA}/args/containerd-env
then
echo "" >> "${SNAP_DATA}/args/containerd-env"
echo "# You can set the of the kata containers runtime here." >> "${SNAP_DATA}/args/containerd-env"
echo "#" >> "${SNAP_DATA}/args/containerd-env"
echo "# KATA_PATH=" >> "${SNAP_DATA}/args/containerd-env"
echo "#" >> "${SNAP_DATA}/args/containerd-env"
echo "PATH=\$PATH:\$KATA_PATH" >> "${SNAP_DATA}/args/containerd-env"
fi
# Add option to support kata containers
if [ -e "${SNAP_DATA}/args/containerd-template.toml" ] &&
! grep -e "io.containerd.kata.v2" ${SNAP_DATA}/args/containerd-template.toml
then
KATA_HANDLER_BEFORE='\[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.nvidia-container-runtime\]'
KATA_HANDLER_AFTER=' [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]
runtime_type = "io.containerd.kata.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata.options]
BinaryName = "kata-runtime"
'
CD_TOML="${SNAP_DATA}/args/containerd-template.toml"
CD_TOML_TMP="${SNAP_DATA}/args/containerd-template.toml.tmp"
"$SNAP/usr/bin/gawk" -v kata="${KATA_HANDLER_AFTER}" '/'${KATA_HANDLER_BEFORE}'/{print kata }1' ${CD_TOML} > ${CD_TOML_TMP}
mv ${CD_TOML_TMP} ${CD_TOML}
fi
for dir in ${SNAP_COMMON}/plugins ${SNAP_COMMON}/addons ${SNAP_DATA}/credentials/ ${SNAP_DATA}/certs/ ${SNAP_DATA}/args/ ${SNAP_DATA}/var/lock ${SNAP_DATA}/tmp/ ${SNAP_COMMON}/hooks
do
chmod -R ug+rwX ${dir}
chmod -R o-rwX ${dir}
done
group=$(get_microk8s_or_cis_group)
# Try to create the snap_microk8s group. Do not fail the installation if something goes wrong
if ! getent group ${group} >/dev/null 2>&1
then
groupadd ${group} || true
fi
if getent group ${group} >/dev/null 2>&1 && ! [ -e "${SNAP_DATA}/var/lock/cis-hardening" ]
then
chgrp ${group} -R ${SNAP_COMMON}/plugins ${SNAP_COMMON}/addons ${SNAP_DATA}/credentials/ ${SNAP_DATA}/certs/ ${SNAP_DATA}/args/ ${SNAP_DATA}/var/lock/ ${SNAP_DATA}/var/kubernetes/backend/ ${SNAP_DATA}/tmp/ ${SNAP_COMMON}/hooks || true
fi
if [ -e "${SNAP_DATA}/var/lock/cis-hardening" ]
then
chmod -R g-wr ${SNAP_COMMON}/plugins ${SNAP_COMMON}/addons ${SNAP_DATA}/credentials/ ${SNAP_DATA}/certs/ ${SNAP_DATA}/args/ ${SNAP_DATA}/var/lock/ ${SNAP_DATA}/var/kubernetes/backend/ ${SNAP_DATA}/tmp/ ${SNAP_COMMON}/hooks || true
chmod -R o-wr ${SNAP_COMMON}/plugins ${SNAP_COMMON}/addons ${SNAP_DATA}/credentials/ ${SNAP_DATA}/certs/ ${SNAP_DATA}/args/ ${SNAP_DATA}/var/lock/ ${SNAP_DATA}/var/kubernetes/backend/ ${SNAP_DATA}/tmp/ ${SNAP_COMMON}/hooks || true
if ! is_strict && [ -e /etc/systemd/system/snap.microk8s.daemon-kubelite.service ]
then
chmod -R g-wr /etc/systemd/system/snap.microk8s.daemon-kubelite.service
chmod -R o-wr /etc/systemd/system/snap.microk8s.daemon-kubelite.service
fi
fi
if ! is_strict
then
try_copy_users_to_snap_microk8s
fi
# as only one cni bin dir can be used we will use the one in SNAP_DATA but have links to
# the real CNI plugins we distribute in SNAP
mkdir -p "${SNAP_DATA}/opt/cni/bin/"
(
cd "${SNAP}/opt/cni/bin/"
MY_SNAP_DIR=$(dirname "${SNAP}")
for i in *; do ln -sf "${MY_SNAP_DIR}/current/opt/cni/bin/$i" "${SNAP_DATA}/opt/cni/bin/${i}"; done
)
if ! [ -e "${SNAP_DATA}/opt/cni/bin/flanneld" ]
then
# cover situation where cilium was installed prior to this update
if [ -f "${SNAP_DATA}/opt/cni/bin/loopback" ] && [ -f "${SNAP}/opt/cni/bin/loopback" ]; then
rm -f "${SNAP_DATA}/opt/cni/bin/loopback"
fi
fi
if ! [ -f "${SNAP_DATA}/args/flanneld" ]
then
mkdir -p ${SNAP_DATA}/args/cni-network/
cp -r ${SNAP}/default-args/cni-network/flannel.conflist ${SNAP_DATA}/args/cni-network/
cp ${SNAP}/default-args/flanneld ${SNAP_DATA}/args/
cp ${SNAP}/default-args/flannel-template.conflist ${SNAP_DATA}/args/
cp ${SNAP}/default-args/flannel-network-mgr-config ${SNAP_DATA}/args/
snapctl restart ${SNAP_NAME}.daemon-etcd
snapctl restart ${SNAP_NAME}.daemon-containerd
snapctl restart ${SNAP_NAME}.daemon-flanneld
fi
if grep -e "etcd.socket:2379" ${SNAP_DATA}/args/etcd
then
echo "Using a port for etcd"
# TODO: Do something smart in selecting a port
refresh_opt_in_config advertise-client-urls https://\${DEFAULT_INTERFACE_IP_ADDR}:12379 etcd
refresh_opt_in_config listen-client-urls https://0.0.0.0:12379 etcd
refresh_opt_in_config client-cert-auth true etcd
refresh_opt_in_config trusted-ca-file \${SNAP_DATA}/certs/ca.crt etcd
refresh_opt_in_config cert-file \${SNAP_DATA}/certs/server.crt etcd
refresh_opt_in_config key-file \${SNAP_DATA}/certs/server.key etcd
snapctl restart ${SNAP_NAME}.daemon-etcd
refresh_opt_in_config etcd-servers https://127.0.0.1:12379 kube-apiserver
refresh_opt_in_config etcd-cafile \${SNAP_DATA}/certs/ca.crt kube-apiserver
refresh_opt_in_config etcd-certfile \${SNAP_DATA}/certs/server.crt kube-apiserver
refresh_opt_in_config etcd-keyfile \${SNAP_DATA}/certs/server.key kube-apiserver
need_api_restart=true
fi
if ! grep -e "service-account-issuer" ${SNAP_DATA}/args/kube-apiserver
then
echo "--service-account-issuer='https://kubernetes.default.svc'" >> ${SNAP_DATA}/args/kube-apiserver
need_api_restart=true
fi
if ! grep -e "service-account-signing-key-file" ${SNAP_DATA}/args/kube-apiserver
then
echo '--service-account-signing-key-file=${SNAP_DATA}/certs/serviceaccount.key' >> ${SNAP_DATA}/args/kube-apiserver
need_api_restart=true
fi
# Disable the watchlist feature until k8s-dqlite can handle it
if ! grep -e "WatchList" ${SNAP_DATA}/args/kube-apiserver
then
if ! grep -e "--feature-gates=" ${SNAP_DATA}/args/kube-apiserver
then
echo '--feature-gates=WatchList=false' >> ${SNAP_DATA}/args/kube-apiserver
else
# Find the line starting with --feature-gates= and append ,WatchList=false
"${SNAP}/bin/sed" -i '/^--feature-gates=/ s/$/,WatchList=false/' "$SNAP_DATA/args/kube-apiserver"
fi
need_api_restart=true
fi
# RemoveSelfLink feature flag is removed after 1.24
if grep -e "feature-gates=RemoveSelfLink" ${SNAP_DATA}/args/kube-apiserver
then
"${SNAP}/bin/sed" -i '/feature-gates=RemoveSelfLink/d' "$SNAP_DATA/args/kube-apiserver"
need_api_restart=true
fi
if remove_docker_specific_args
then
need_kubelet_restart=true
fi
# scheduler --address flag is removed after 1.24
if grep -e "--address=" ${SNAP_DATA}/args/kube-scheduler
then
"${SNAP}/bin/sed" -i '/--address=/d' "$SNAP_DATA/args/kube-scheduler"
fi
# controller-manager --address flag is removed after 1.24
if grep -e "--address=" ${SNAP_DATA}/args/kube-controller-manager
then
"${SNAP}/bin/sed" -i '/--address=/d' "$SNAP_DATA/args/kube-controller-manager"
need_api_restart=true
fi
if ! grep '\-\-enable\-v2' ${SNAP_DATA}/args/etcd
then
refresh_opt_in_config enable-v2 true etcd
snapctl restart ${SNAP_NAME}.daemon-etcd
fi
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
if grep -e "\-\-etcd-cafile /var/snap/microk8s/.*/ca.remote.crt" ${SNAP_DATA}/args/flanneld
then
skip_opt_in_config etcd-cafile flanneld
refresh_opt_in_config etcd-cafile \${SNAP_DATA}/certs/ca.remote.crt flanneld
fi
if grep -e "\-\-etcd-certfile /var/snap/microk8s/.*/server.remote.crt" ${SNAP_DATA}/args/flanneld
then
skip_opt_in_config etcd-certfile flanneld
refresh_opt_in_config etcd-certfile \${SNAP_DATA}/certs/server.remote.crt flanneld
fi
fi
# This patches flanneld conf template by adding cniversion if it does not exist.
if [ -e ${SNAP_DATA}/args/flannel-template.conflist ] && ! grep -e "cniVersion" ${SNAP_DATA}/args/flannel-template.conflist
then
"$SNAP/bin/sed" -i 's@"name": "microk8s-flannel-network",@"name": "microk8s-flannel-network",\n "cniVersion": "0.3.1",@g' ${SNAP_DATA}/args/flannel-template.conflist
snapctl restart ${SNAP_NAME}.daemon-flanneld
snapctl restart ${SNAP_NAME}.daemon-containerd
fi
if [ ! -f ${SNAP_DATA}/args/cluster-agent ]
then
cp ${SNAP}/default-args/cluster-agent ${SNAP_DATA}/args/cluster-agent
fi
if ! grep -e "\-\-timeout" ${SNAP_DATA}/args/cluster-agent
then
refresh_opt_in_config timeout 240 cluster-agent
snapctl restart ${SNAP_NAME}.daemon-containerd
fi
if ! grep -e "\-\-ip-masq" ${SNAP_DATA}/args/flanneld
then
refresh_opt_in_config ip-masq true flanneld
snapctl restart ${SNAP_NAME}.daemon-flanneld
fi
if grep -e "\-\-cluster-cidr=10.152.183.0/24" ${SNAP_DATA}/args/kube-proxy
then
refresh_opt_in_config cluster-cidr 10.1.0.0/16 kube-proxy
need_proxy_restart=true
fi
if [ -e ${SNAP_DATA}/var/lock/stopped.lock ]
then
snapctl stop ${SNAP_NAME}.daemon-kubelite
fi
# Enable kubelite
if ! [ -e ${SNAP_DATA}/var/lock/lite.lock ]
then
touch "${SNAP_DATA}/var/lock/lite.lock"
if ! [ -e ${SNAP_DATA}/args/kubelite ]
then
cp ${SNAP}/default-args/kubelite ${SNAP_DATA}/args/kubelite
fi
date
if [ -e ${SNAP_DATA}/var/lock/stopped.lock ]
then
snapctl stop ${SNAP_NAME}.daemon-kubelite
else
snapctl start ${SNAP_NAME}.daemon-kubelite
fi
fi
if ! [ -e ${SNAP_DATA}/args/kubelite ]
then
cp ${SNAP}/default-args/kubelite ${SNAP_DATA}/args/kubelite
need_api_restart=true
fi
# Removed --insecure-port argument
if grep -e "\-\-insecure\-port" ${SNAP_DATA}/args/kube-apiserver
then
$SNAP/bin/sed -i '/\-\-insecure\-port/d' ${SNAP_DATA}/args/kube-apiserver
need_api_restart=true
fi
# Are we using etcd or some other non-dqlite datastore?
if ! [ -e ${SNAP_DATA}/args/k8s-dqlite ] &&
! grep -e "\-\-storage-backend=dqlite" ${SNAP_DATA}/args/kube-apiserver
then
set_service_not_expected_to_start k8s-dqlite
snapctl stop ${SNAP_NAME}.daemon-k8s-dqlite
fi
# Configure the API sever to talk to the external dqlite
if [ -e ${SNAP}/default-args/k8s-dqlite ] &&
! [ -e ${SNAP_DATA}/args/k8s-dqlite ] &&
grep -e "\-\-storage-backend=dqlite" ${SNAP_DATA}/args/kube-apiserver
then
echo "Reconfiguring the API server for dqlite"
cp ${SNAP}/default-args/k8s-dqlite ${SNAP_DATA}/args/k8s-dqlite
cp ${SNAP}/default-args/k8s-dqlite-env ${SNAP_DATA}/args/k8s-dqlite-env
need_api_restart=true
snapctl stop ${SNAP_NAME}.daemon-kubelite
refresh_opt_in_local_config etcd-servers unix://\${SNAP_DATA}/var/kubernetes/backend/kine.sock:12379 kube-apiserver
$SNAP/bin/sed -i '/\-\-storage\-backend=dqlite/d' ${SNAP_DATA}/args/kube-apiserver
storage_dir="$(get_opt_in_config '--storage-dir' 'kube-apiserver')"
if ! [ -z $storage_dir ]
then
refresh_opt_in_local_config storage-dir "$storage_dir" k8s-dqlite
fi
$SNAP/bin/sed -i '/\-\-storage\-dir/d' ${SNAP_DATA}/args/kube-apiserver
snapctl restart ${SNAP_NAME}.daemon-k8s-dqlite
fi
# Fix hard-coded snap revision numbers in worker node services of existing clusters
# https://github.com/canonical/microk8s/pull/3554
for svc in kubelet proxy; do
cfg="${SNAP_DATA}/credentials/${svc}.config"
if [ -e ${cfg} ]; then
sed -i 's,/var/snap/microk8s/[x0-9]*/,/var/snap/microk8s/current/,' "${cfg}" || true
fi
done
# (1.26) Removed --log-dir argument from kubelet
if grep -e "\-\-log\-dir" "${SNAP_DATA}/args/kubelet"
then
"${SNAP}/bin/sed" -i '/\-\-log\-dir/d' "${SNAP_DATA}/args/kubelet"
need_api_restart=true
fi
# Refresh calico if needed
refresh_calico_if_needed
# Refresh apiserver proxy
snapctl restart "${SNAP_NAME}.daemon-apiserver-proxy"
if is_strict
then
enable_snap
fi
# if we are refreshing in a no-flanneld we need to restart the CNI pods because they mount parts of $SNAP_DATA
if [ -e "${SNAP_DATA}/var/lock/no-flanneld" ]
then
touch "${SNAP_DATA}/var/lock/snapdata-mounts-need-reload"
fi
# Restart reconfigured services
if ${need_api_restart} ||
${need_proxy_restart} ||
${need_controller_restart} ||
${need_kubelet_restart}
then
if [ -e ${SNAP_DATA}/var/lock/lite.lock ]
then
snapctl restart ${SNAP_NAME}.daemon-kubelite
else
echo "Unable to restart service"
exit 1
fi
fi
if ${need_cluster_agent_restart}
then
snapctl restart ${SNAP_NAME}.daemon-cluster-agent
fi