-
Notifications
You must be signed in to change notification settings - Fork 108
/
031_install_containerd.sh.tpl
88 lines (76 loc) · 3.61 KB
/
031_install_containerd.sh.tpl
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
# Copyright 2021 Flant JSC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{{- if eq .cri "Containerd" }}
bb-event-on 'bb-package-installed' 'post-install'
post-install() {
systemctl daemon-reload
systemctl enable containerd.service
{{ if ne .runType "ImageBuilding" -}}
systemctl restart containerd.service
{{- end }}
}
if bb-apt-package? docker-ce || bb-apt-package? docker.io; then
bb-deckhouse-get-disruptive-update-approval
if systemctl is-active -q kubelet.service; then
systemctl stop kubelet.service
fi
# Stop docker containers if they run
docker stop $(docker ps -q) || true
systemctl stop docker.service
systemctl stop containerd.service
# Kill running containerd-shim processes
kill $(ps ax | grep containerd-shim | grep -v grep |awk '{print $1}') 2>/dev/null || true
# Remove mounts
umount $(mount | grep "/run/containerd" | cut -f3 -d" ") 2>/dev/null || true
bb-rp-remove docker-ce containerd-io
bb-apt-remove docker.io docker-ce containerd-io
rm -rf /var/lib/docker/ /var/run/docker.sock /var/lib/containerd/ /etc/docker /etc/containerd/config.toml
# Pod kubelet-eviction-thresholds-exporter in cri=Docker mode mounts /var/run/containerd/containerd.sock, /var/run/containerd/containerd.sock will be a directory and newly installed containerd won't run. Same thing with crictl.
rm -rf /var/run/containerd /usr/local/bin/crictl
bb-log-info "Setting reboot flag due to cri being updated"
bb-flag-set reboot
fi
{{- range $key, $value := index .k8s .kubernetesVersion "bashible" "ubuntu" }}
{{- $ubuntuVersion := toString $key }}
{{- if or $value.containerd.desiredVersion $value.containerd.allowedPattern }}
if bb-is-ubuntu-version? {{ $ubuntuVersion }} ; then
desired_version={{ $value.containerd.desiredVersion | quote }}
allowed_versions_pattern={{ $value.containerd.allowedPattern | quote }}
fi
{{- end }}
{{- end }}
if [[ -z $desired_version ]]; then
bb-log-error "Desired version must be set"
exit 1
fi
should_install_containerd=true
version_in_use="$(dpkg -l containerd.io 2>/dev/null | grep -E "(hi|ii)\s+(containerd.io)" | awk '{print $2"="$3}' || true)"
if test -n "$allowed_versions_pattern" && test -n "$version_in_use" && grep -Eq "$allowed_versions_pattern" <<< "$version_in_use"; then
should_install_containerd=false
fi
if [[ "$version_in_use" == "$desired_version" ]]; then
should_install_containerd=false
fi
if [[ "$should_install_containerd" == true ]]; then
{{- $ubuntuName := dict "16.04" "Xenial" "18.04" "Bionic" "20.04" "Focal" "22.04" "Jammy"}}
{{- range $key, $value := index .k8s .kubernetesVersion "bashible" "ubuntu" }}
{{- $ubuntuVersion := toString $key }}
if bb-is-ubuntu-version? {{ $ubuntuVersion }} ; then
containerd_tag="{{- index $.images.registrypackages (printf "containerdUbuntu%s%s" ($value.containerd.desiredVersion | replace "containerd.io=" "" | replace "." "_" | replace "-" "_" | camelcase) (index $ubuntuName $ubuntuVersion)) }}"
fi
{{- end }}
crictl_tag="{{ index .images.registrypackages (printf "crictl%s" (.kubernetesVersion | replace "." "")) | toString }}"
bb-rp-install "containerd-io:${containerd_tag}" "crictl:${crictl_tag}"
fi
{{- end }}