Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add libkrun support #679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ install: man all ## - Install QM files (including selinux)
install -D -m 644 containers.conf ${DESTDIR}${DATADIR}/qm/containers.conf
install -D -m 644 qm.container ${DESTDIR}${DATADIR}/containers/systemd/qm.container
install -D -m 755 tools/qm-is-ostree ${DESTDIR}${DATADIR}/qm/qm-is-ostree
install -D -m 755 tools/qm-change-podman-runtime ${DESTDIR}${DATADIR}/qm/qm-change-podman-runtime
2 changes: 2 additions & 0 deletions rpm/qm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ BuildRequires: selinux-policy >= %_selinux_policy_version
BuildRequires: selinux-policy-devel >= %_selinux_policy_version

Requires: parted
Requires: crun-krun
Requires: containers-common
Requires: selinux-policy >= %_selinux_policy_version
Requires(post): selinux-policy-base >= %_selinux_policy_version
Expand Down Expand Up @@ -374,6 +375,7 @@ fi
%{_datadir}/qm/qm-storage-settings
%{_datadir}/qm/comment-tz-local
%{_datadir}/qm/qm-is-ostree
%{_datadir}/qm/qm-change-podman-runtime
%ghost %dir %{_datadir}/containers
%ghost %dir %{_datadir}/containers/systemd
%{_datadir}/containers/systemd/qm.container
Expand Down
79 changes: 79 additions & 0 deletions tools/qm-change-podman-runtime
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slp this script is updating container config in qm.container (which we require) and also podman. Is that good solution to your eyes (only enable when running it)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think we need to change the runtime globally, but on a per-container basis.


# Script to dynamically change Podman runtime
# Usage: /usr/share/qm/qm-change-podman-runtime <runtime-name> <runtime-binary-paths>

set -e

# Usage function
usage() {
echo "Usage: /usr/share/qm/qm-change-podman-runtime <runtime-name> <runtime-binary-paths>"
echo
echo "Examples:"
echo " /usr/share/qm/qm-change-podman-runtime krun /usr/bin/krun"
echo " /usr/share/qm/qm-change-podman-runtime my-runtime /usr/bin/my-runtime,/usr/local/bin/my-runtime"
exit 1
}

# Ensure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Error: This script must be run as root. Please use sudo or switch to the root user."
exit 1
fi

# Validate input arguments
if [ $# -ne 2 ]; then
usage
fi

RUNTIME_NAME=$1
RUNTIME_BINARY_PATHS=$2
CONFIG_FILE="/etc/containers/containers.conf"
QM_CONTAINER_FILE="/usr/share/containers/systemd/qm.container"

# Parse binary paths into TOML array format
BINARY_PATHS_TOML=$(echo "$RUNTIME_BINARY_PATHS" | sed 's/,/","/g' | sed 's/^/["/' | sed 's/$/"]/')

# Create or modify the configuration file
if [ ! -f "$CONFIG_FILE" ]; then
echo "$CONFIG_FILE does not exist. Creating a new configuration file."
mkdir -p /etc/containers
cat << EOF > "$CONFIG_FILE"
runtime = "$RUNTIME_NAME"

[runtimes]
$RUNTIME_NAME = $BINARY_PATHS_TOML
EOF
else
echo "Updating Podman configuration to set runtime $RUNTIME_NAME with paths $RUNTIME_BINARY_PATHS"
sed -i '/^runtime = /d' "$CONFIG_FILE" # Remove existing runtime setting
sed -i '/^\[runtimes\]/,$d' "$CONFIG_FILE" # Remove existing [runtimes] section
cat << EOF >> "$CONFIG_FILE"
runtime = "$RUNTIME_NAME"

[runtimes]
$RUNTIME_NAME = $BINARY_PATHS_TOML
EOF
fi

# Update qm.container file
if [ -f "$QM_CONTAINER_FILE" ]; then
echo "Updating $QM_CONTAINER_FILE to include Runtime=$RUNTIME_NAME in the Container section."
sed -i '/^Runtime=/d' "$QM_CONTAINER_FILE" # Remove any existing Runtime setting
sed -i '/^\[Container\]/a Runtime='"$RUNTIME_NAME" "$QM_CONTAINER_FILE" # Add the new Runtime entry
else
echo "Error: $QM_CONTAINER_FILE does not exist. Skipping update to qm.container."
fi

# Reload Podman configuration
echo "Reloading Podman configuration..."
podman system migrate --new-runtime=krun

# Verify the runtime change
echo "Verifying the runtime change..."
if podman info | grep -q "runtime: $RUNTIME_NAME" -A5; then
echo "Runtime successfully set to $RUNTIME_NAME with paths $RUNTIME_BINARY_PATHS."
else
echo "Failed to set runtime to $RUNTIME_NAME."
exit 1
fi
Loading