Skip to content

Commit 3043588

Browse files
committed
feat: match cgroups between host system and container
This change ensures cgroup consistency between the Bottlerocket host system and the admin container, preventing resource management conflicts. The implementation synchronizes cgroup configurations between the host and admin container. Signed-off-by: Maher Homsi <[email protected]>
1 parent 5c48a4b commit 3043588

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

start_admin.sh

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ for key_alg in rsa ecdsa ed25519; do
228228
fi
229229
done
230230

231+
readonly host_cgroup="/.bottlerocket/rootfs/sys/fs/cgroup"
232+
233+
cgroup_fstype=$(findmnt -n -o FSTYPE "${host_cgroup}" || true)
234+
if [[ "${cgroup_fstype}" == tmpfs ]]; then
235+
# Host uses cgroup v1, so use cgroup v1 in container too
236+
ln -sf "${host_cgroup}" /sys/fs/cgroup
237+
log "cgroup v1 enabled in admin container to match host"
238+
fi
239+
231240
install_proxy_profile
232241

233242
enable_systemd_services
@@ -236,32 +245,7 @@ enable_systemd_services
236245

237246
systemd_options=()
238247

239-
# cgroup v2 compatibility crimes: systemd 219 in the admin container only
240-
# supports cgroup v1.
241-
if [[ $(findmnt -n -o FSTYPE /sys/fs/cgroup) = cgroup2 ]]; then
242-
# Mount an extra cgroup v1 hierarchy for use by systemd in the admin
243-
# container. Vanilla systemd is hard-wired to look for it at /sys/fs/cgroup
244-
# but that path is already taken by the host's proper cgroup hierarchy.
245-
# Mounting a cgroup v1 hierarchy here might confuse the host and the systemd
246-
# documentation advises against manually interfering with anything in that
247-
# path. Therefore, mount the extra hierarchy elsewhere and tell systemd in
248-
# the admin container where to look. Requirements:
249-
#
250-
# 1. The base must be a mount point.
251-
# 2. The base must contain another mounted cgroup file system named "systemd".
252-
#
253-
# In either case there is no need to populate the file systems with any
254-
# actual cgroup controllers, since the host is expected to manage processes.
255-
readonly cgroup_base=/.bottlerocket/admin-container-cgroup
256-
mkdir -p "${cgroup_base}"
257-
mount -t tmpfs -o nosuid,nodev,noexec tmpfs "${cgroup_base}"
258-
mkdir -p "${cgroup_base}"/systemd
259-
mount -o remount,ro "${cgroup_base}"
260-
mount -t cgroup -o none,name=systemd cgroup "${cgroup_base}"/systemd
261-
systemd_options+=( --cgroup-base "${cgroup_base}" )
262-
fi
263-
264248
# Persuade systemd that it's OK to run as a user manager.
265249
export XDG_RUNTIME_DIR="/run/user/${UID}"
266250
mkdir -p /run/systemd/system "${XDG_RUNTIME_DIR}"
267-
exec /usr/lib/systemd/systemd "${systemd_options[@]}" --user --unit=admin.target
251+
exec /usr/lib/systemd/systemd "${systemd_options[@]}" --user --unit=admin.target

0 commit comments

Comments
 (0)