@@ -22,6 +22,7 @@ print_help() {
2222 echo " --no-bind-kubelet disable bind mounting kubelet dir onto MD raid device"
2323 echo " --no-bind-containerd disable bind mounting containerd dir onto MD raid device"
2424 echo " --no-bind-pods-logs disable bind mounting /var/log/pods onto MD raid device"
25+ echo " --no-bind-soci disable bind mounting SOCI container image dir onto MD raid device"
2526 echo " --no-bind-mounts disable all bind mounting onto MD raid device, only create and mount MD device"
2627 echo " -h, --help print this help"
2728}
@@ -79,7 +80,7 @@ maybe_raid() {
7980 mount_unit_name=" $( systemd-escape --path --suffix=mount " ${array_mount_point} " ) "
8081 cat > " /etc/systemd/system/${mount_unit_name} " << EOF
8182 [Unit]
82- Description=Mount EC2 Instance Store NVMe disk RAID0
83+ Description=Mount EC2 Instance Store NVMe disk RAID ${raid_level}
8384 [Mount]
8485 What=UUID=${dev_uuid}
8586 Where=${array_mount_point}
9192 systemd-analyze verify " ${mount_unit_name} "
9293 systemctl enable " ${mount_unit_name} " --now
9394
94- prev_running=" "
95- needs_linked=" "
96-
9795 BIND_MOUNTS=()
98-
9996 if [[ " ${BIND_KUBELET} " == " true" ]]; then
100- BIND_MOUNTS+=(" kubelet" )
97+ BIND_MOUNTS+=(" /var/lib/ kubelet" )
10198 fi
10299
103100 if [[ " ${BIND_CONTAINERD} " == " true" ]]; then
104- BIND_MOUNTS+=(" containerd" )
101+ BIND_MOUNTS+=(" /var/lib/containerd" )
102+ fi
103+
104+ if [[ " ${BIND_SOCI} " == " true" ]]; then
105+ BIND_MOUNTS+=(" /var/lib/soci-snapshotter-grpc" )
106+ fi
107+
108+ if [[ " ${BIND_PODS} " == " true" ]]; then
109+ BIND_MOUNTS+=(" /var/log/pods" )
105110 fi
106111
107- for unit in " ${BIND_MOUNTS[@]} " ; do
112+ prev_running=" "
113+ needs_linked=" "
114+ for mount_point in " ${BIND_MOUNTS[@]} " ; do
115+ local mount_unit_name
116+ mount_unit_name=" $( systemd-escape --path --suffix=mount " ${mount_point} " ) "
108117 # # Check if the bind mount from the RAID already exists
109- if [[ " $( systemctl is-active var-lib-${unit} .mount) " != " active" ]]; then
110- # Check if components that depend on the RAID are running and, if so, stop them
118+ if [[ " $( systemctl is-active " ${mount_unit_name} " ) " != " active" ]]; then
119+ # Check if components that depend on this mount path are running and, if so, stop them
120+ local unit
121+ unit=" $( dependent_unit ${mount_point} ) "
111122 if systemctl is-active " ${unit} " > /dev/null 2>&1 ; then
112123 prev_running+=" ${unit} "
113124 fi
114- needs_linked+=" /var/lib/ ${unit }"
125+ needs_linked+=" ${mount_point }"
115126 fi
116127 done
117128
118- # # Check if /var/log/pods has been bind mounted and make sure kubelet is stopped
119- if [[ " ${BIND_VAR_LOG_PODS} " == " true" ]]; then
120- if [[ " $( systemctl is-active var-log-pods.mount) " != " active" ]]; then
121- if systemctl is-active " kubelet" > /dev/null 2>&1 ; then
122- prev_running+=" kubelet"
123- fi
124- needs_linked+=" /var/log/pods"
125- fi
126- fi
127-
128129 if [[ ! -z " ${prev_running} " ]]; then
129130 systemctl stop ${prev_running}
130131 fi
141142 mount_unit_name=" $( systemd-escape --path --suffix=mount " ${mount_point} " ) "
142143 cat > " /etc/systemd/system/${mount_unit_name} " << EOF
143144 [Unit]
144- Description=Mount ${unit } on EC2 Instance Store NVMe RAID0
145+ Description=Mount ${mount_point } on EC2 Instance Store NVMe RAID ${raid_level}
145146 [Mount]
146147 What=${array_mount_point_unit}
147148 Where=${mount_point}
159160 fi
160161}
161162
163+ # Returns systemd unit that depends on a given bind mount.
164+ dependent_unit () {
165+ local path=" $1 "
166+
167+ case " ${path} " in
168+ " /var/lib/kubelet" )
169+ echo " kubelet.service"
170+ ;;
171+ " /var/lib/containerd" )
172+ echo " containerd.service"
173+ ;;
174+ " /var/lib/soci-snapshotter-grpc" )
175+ echo " soci-snapshotter.service"
176+ ;;
177+ " /var/log/pods" )
178+ echo " kubelet.service"
179+ ;;
180+ * )
181+ echo " "
182+ ;;
183+ esac
184+ }
185+
162186# Mounts and creates xfs file systems on all EC2 instance store NVMe disks
163187# without existing file systems. Mounts in /mnt/k8s-disks/{1..} by default
164188maybe_mount () {
196220MNT_DIR=" /mnt/k8s-disks"
197221BIND_KUBELET=" true"
198222BIND_CONTAINERD=" true"
199- BIND_VAR_LOG_PODS=" true"
223+ BIND_SOCI=" true"
224+ BIND_PODS=" true"
200225
201226while [[ $# -gt 0 ]]; do
202227 key=" $1 "
@@ -219,13 +244,18 @@ while [[ $# -gt 0 ]]; do
219244 shift
220245 ;;
221246 --no-bind-pods-logs)
222- BIND_VAR_LOG_PODS=" false"
247+ BIND_PODS=" false"
248+ shift
249+ ;;
250+ --no-bind-soci)
251+ BIND_SOCI=" false"
223252 shift
224253 ;;
225254 --no-bind-mounts)
226255 BIND_KUBELET=" false"
227256 BIND_CONTAINERD=" false"
228- BIND_VAR_LOG_PODS=" false"
257+ BIND_SOCI=" false"
258+ BIND_PODS=" false"
229259 shift
230260 ;;
231261 * ) # unknown option
0 commit comments