rootfs: Don't remove files from the rootfs by default

Recent PR #10732 moved the deletion of systemd files and units that were
deemed uneccessary by 02b3b3b977 from `image_builder.sh` to `rootfs.sh`.
This unfortunately broke `rootfs.sh centos` and `rootfs.sh -r` as used by
some other downstream users like fedora and RHEL, with the following error :

  Warning  FailedCreatePodSandBox  1s (x5 over 63s)  kubelet
   Failed to create pod sandbox: rpc error: code = Unknown
     desc = CreateContainer failed: Establishing a D-Bus connection

Caused by:
    0: I/O error: Connection reset by peer (os error 104)
    1: Connection reset by peer (os error 104)

This is because the aforementioned distros use dbus-broker [1] that requires
systemd-journald to be present.

It is questionable that systemd units or files should be deemed unnecessary
for _all_ distros but this has been around since 2019. There's now also a
long-standing expectation from CI that `make rootfs && make image` does
remove these files.

In order to accomodate all the expectations, add a `-d` flag to `rootfs.sh`
to delete the systemd files and have `make rootfs` to use it.

[1] https://github.com/bus1/dbus-broker

Reported-by: Niteesh Dubey <niteesh@us.ibm.com>
Signed-off-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
Greg Kurz 2025-04-08 08:49:28 +02:00
parent 497ab9faaf
commit 734e7e8c54
2 changed files with 9 additions and 3 deletions

View File

@ -93,7 +93,7 @@ rootfs-%: $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX)
.PRECIOUS: $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX)
$(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX):: rootfs-builder/%
$(call silent_run,Creating rootfs for "$*",$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*)
$(call silent_run,Creating rootfs for "$*",$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -d -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*)
@touch $@
# To generate a dracut rootfs, we first generate a dracut initrd and then

View File

@ -106,6 +106,8 @@ readonly -a systemd_files=(
"systemd-tmpfiles-cleanup.timer"
)
typeset should_delete_unnecessary_files="no"
handle_error() {
local exit_code="${?}"
local line_number="${1:-}"
@ -158,6 +160,7 @@ $(get_distros | tr "\n" " ")
Options:
-a <version> Specify the agent version. Overrides the AGENT_VERSION
environment variable.
-d Delete unnecessary systemd units and files
-h Show this help message.
-l List the supported Linux distributions and exit immediately.
-o <version> Specify the version of osbuilder to embed in the rootfs
@ -818,7 +821,9 @@ EOF
info "Create /etc/resolv.conf file in rootfs if not exist"
touch "$dns_file"
delete_unnecessary_files
if [[ "${should_delete_unnecessary_files}" == "yes" ]]; then
delete_unnecessary_files
fi
info "Creating summary file"
create_summary_file "${ROOTFS_DIR}"
@ -828,10 +833,11 @@ parse_arguments()
{
[ "$#" -eq 0 ] && usage && return 0
while getopts a:hlo:r:t: opt
while getopts a:dhlo:r:t: opt
do
case $opt in
a) AGENT_VERSION="${OPTARG}" ;;
d) should_delete_unnecessary_files="yes" ;;
h) usage ;;
l) get_distros | sort && exit 0;;
o) OSBUILDER_VERSION="${OPTARG}" ;;