Skip to content

Commit e020c0e

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 5a0088c commit e020c0e

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ ARG IMAGE_VERSION
6565
RUN test -n "$IMAGE_VERSION"
6666
LABEL "org.opencontainers.image.version"="$IMAGE_VERSION"
6767

68-
# Install the custom systemd build in the same transaction as all original
69-
# packages to save space. For example, openssh-server pulls in systemd. This
70-
# dependency is best satisfied by the downstream build. Reinstalling it later
71-
# would result in also carrying around the original systemd in the final image
72-
# where it would remain forever hidden and unused in a lower layer.
7368
RUN dnf update -y \
7469
&& dnf install -y \
7570
crypto-policies-scripts \

start_admin.sh

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ for key_alg in "${key_algorithms[@]}"; do
247247
fi
248248
done
249249

250+
readonly host_cgroup="/.bottlerocket/rootfs/sys/fs/cgroup"
251+
252+
cgroup_fstype=$(findmnt -n -o FSTYPE "${host_cgroup}" || true)
253+
if [[ "${cgroup_fstype}" == tmpfs ]]; then
254+
# Host uses cgroup v1, so use cgroup v1 in container too
255+
ln -sf "${host_cgroup}" /sys/fs/cgroup
256+
log "cgroup v1 enabled in admin container to match host"
257+
fi
258+
250259
install_proxy_profile
251260

252261
enable_systemd_services
@@ -255,32 +264,7 @@ enable_systemd_services
255264

256265
systemd_options=()
257266

258-
# cgroup v2 compatibility crimes: systemd 219 in the admin container only
259-
# supports cgroup v1.
260-
if [[ $(findmnt -n -o FSTYPE /sys/fs/cgroup) = cgroup2 ]]; then
261-
# Mount an extra cgroup v1 hierarchy for use by systemd in the admin
262-
# container. Vanilla systemd is hard-wired to look for it at /sys/fs/cgroup
263-
# but that path is already taken by the host's proper cgroup hierarchy.
264-
# Mounting a cgroup v1 hierarchy here might confuse the host and the systemd
265-
# documentation advises against manually interfering with anything in that
266-
# path. Therefore, mount the extra hierarchy elsewhere and tell systemd in
267-
# the admin container where to look. Requirements:
268-
#
269-
# 1. The base must be a mount point.
270-
# 2. The base must contain another mounted cgroup file system named "systemd".
271-
#
272-
# In either case there is no need to populate the file systems with any
273-
# actual cgroup controllers, since the host is expected to manage processes.
274-
readonly cgroup_base=/.bottlerocket/admin-container-cgroup
275-
mkdir -p "${cgroup_base}"
276-
mount -t tmpfs -o nosuid,nodev,noexec tmpfs "${cgroup_base}"
277-
mkdir -p "${cgroup_base}"/systemd
278-
mount -o remount,ro "${cgroup_base}"
279-
mount -t cgroup -o none,name=systemd cgroup "${cgroup_base}"/systemd
280-
systemd_options+=( --cgroup-base "${cgroup_base}" )
281-
fi
282-
283267
# Persuade systemd that it's OK to run as a user manager.
284268
export XDG_RUNTIME_DIR="/run/user/${UID}"
285269
mkdir -p /run/systemd/system "${XDG_RUNTIME_DIR}"
286-
exec /usr/lib/systemd/systemd "${systemd_options[@]}" --user --unit=admin.target
270+
exec /usr/lib/systemd/systemd "${systemd_options[@]}" --user --unit=admin.target

0 commit comments

Comments
 (0)