-
Notifications
You must be signed in to change notification settings - Fork 29
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
dougsland
wants to merge
1
commit into
main
Choose a base branch
from
libkrun
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.