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

podman + krun Support #25

Merged
merged 13 commits into from
Sep 27, 2024
Merged

podman + krun Support #25

merged 13 commits into from
Sep 27, 2024

Conversation

efrecon
Copy link
Owner

@efrecon efrecon commented Sep 27, 2024

This factors aways the microvm lifecycle to a separate "library" and arranges for the new package to support both the original krunvm and buidah runtime, but also krun under podman.

In that package, runtime choice is made through the KRUNVM_RUNNER_RUNTIME environment variable. The variable can be krunvm or podman+krun. In theory -- but this has never been tested -- the podman runtime appearing after the + sign could be any runtime supported by podman, e.g. crun.

When no runtime is specified at the command line or through an environment variable, the package will automatically choose depending on the presence of the relevant and necessary binaries. The implementation prefers podman+krun, as these are part of the mainstream containers project at GitHub.

efrecon added 8 commits April 5, 2024 14:15
Add a generic API to create microVMs in an "agnostic" way, and migrate
to the new API in the orchestrator.sh and runner.sh scripts. While the
API has code for podman, this update only focuses on migrating the
existing krunvm-based code to the new API.

The new API is implemented in lib/microvm.sh, and provides a set of
docker/podman lookalike commands to manage microVMs. The function
microvm_runtime can be used to pinpoint or auto-detect the runtime to
use depending on commands available at the host. The API is **not** able
to handle several krunvm-based microVMs at the same time.
Add support for multiple krunvm-based VMs in the API. This uses a
temporary directory that will store the mappings between the name of the
VM and the PID of the underlying (top) process. The directory should be
removed through microvm_cleanup upon process exit.
While the podman runtime is still enforced, the script now supports
several other runtimes. The KRUNVM_RUNNER_RUNTIME variable should
contain the word podman, followed by the plus sign, followed by the
runtime to use, e.g. podman+krun will pass the value of krun to the
--runtime option of podman create/run.
@efrecon efrecon self-assigned this Sep 27, 2024
Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces several changes across multiple files to enhance the management of microVMs within the project. Key updates include the addition of a new section in CONTRIBUTING.md for image cleanup instructions, revisions to README.md to clarify runtime dependencies, and the introduction of a new lib/microvm.sh file containing functions for managing microVMs. Additionally, existing scripts like orchestrator.sh and runner.sh have been modified to utilize these new functions, streamlining the process of creating and managing microVMs.

Changes

File(s) Change Summary
CONTRIBUTING.md Added a "Cleanup" section with instructions for removing unused images using krunvm, podman, and buildah.
README.md Updated to clarify that libkrun is used for creating microVMs, added support for krun with podman, and refined installation requirements and runtime notes.
lib/common.sh Modified check_command function to include -s (soft check) and -w (warning) options; removed run_krunvm function.
lib/microvm.sh Introduced a new file with functions for managing microVMs using krunvm and podman, including creation, execution, and cleanup functions.
orchestrator.sh Updated to include microvm.sh, added ORCHESTRATOR_RUNTIME variable, modified cleanup function to use new microVM functions, and exported RUNNER_RUNTIME.
runner.sh Sourced lib/microvm.sh, added -R option for runtime specification, removed vm_create and vm_start, and replaced with microvm_run.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Runner
    participant Orchestrator
    participant MicroVM

    User->>Runner: Specify runtime (-R option)
    Runner->>Orchestrator: Pass runtime information
    Orchestrator->>MicroVM: Create and start microVM
    MicroVM->>Orchestrator: Confirm microVM running
    Orchestrator->>Runner: Notify user of microVM status
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@efrecon efrecon linked an issue Sep 27, 2024 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 19

🧹 Outside diff range and nitpick comments (8)
README.md (2)

Line range hint 75-79: LGTM with a suggestion: Clear feature description with community engagement

The new feature description accurately reflects the added support for both krunvm and krun under podman, aligning with the PR objectives. The mention of potential compatibility with container-based solutions is a good way to encourage community involvement.

Consider adding a link to the project's issue tracker or contribution guidelines after the sentence "Reports and/or changes are welcome." This would make it easier for interested contributors to get involved.


98-102: LGTM with a minor formatting suggestion: Clear explanation of runtime requirements

The updated requirements section accurately reflects the new runtime options introduced in this PR. The note about podman not being required when using krunvm is a helpful clarification for users.

There's a minor formatting inconsistency. Consider removing the extra space before the krun bullet point to align it with the krunvm bullet point:

 + A compatible runtime, i.e. either:
-  + `krun` and [`podman`][podman].
+ + `krun` and [`podman`][podman].
   + `krunvm`, its [requirements] and `buildah`
🧰 Tools
🪛 LanguageTool

[uncategorized] ~100-~100: Loose punctuation mark.
Context: ...un and [podman][podman]. + krunvm, its [requirements] and buildah` Note:...

(UNLIKELY_OPENING_PUNCTUATION)

lib/microvm.sh (3)

115-115: Use consistent DNS default value

The default DNS server is set to 1.1.1.1. Consider using a more widely recognized default DNS server like 8.8.8.8, or making it configurable to suit different environments.


183-184: Fix comment regarding job control

The comment states Disable job control, but set -m actually enables job control (monitor mode). Update the comment to reflect the correct behavior.

Correct the comment:

       optstate=$(set +o)
-      set -m; # Disable job control
+      set -m; # Enable job control

235-235: Typo in comment

There's a typo in the comment: "Specify howlog to wait between TERM and KILL?" It should be "Specify how long to wait between TERM and KILL?"

Correct the comment:

     # TODO: Specify howlog to wait between TERM and KILL?
+    # TODO: Specify how long to wait between TERM and KILL?
runner.sh (3)

Line range hint 215-289: Potential issue with argument handling in vm_run function

The vm_run function uses set -- multiple times, which can overwrite previously set positional parameters and lead to unexpected behavior.

Consider using an array to collect arguments to prevent overwriting. Here's a suggested refactor:

+args=()
...
  if [ -n "$RUNNER_ENVIRONMENT" ]; then
    ...
    # Pass the location of the env. file to the runner script
-   set -- -E "/${RUNNER_VM_ENVDIR}/${_id}.env"
-   set -- -k "/${RUNNER_VM_ENVDIR}/${_id}.tkn" "$@"
+   args+=("-E" "/${RUNNER_VM_ENVDIR}/${_id}.env")
+   args+=("-k" "/${RUNNER_VM_ENVDIR}/${_id}.tkn")
  else
    ...
    # Collect arguments
+   args+=(
+     -g "$RUNNER_GITHUB"
+     -G "$RUNNER_GROUP"
+     -i "$_id"
+     -l "$RUNNER_LOG"
+     -L "$RUNNER_LABELS"
+     -p "$RUNNER_PRINCIPAL"
+     -s "$RUNNER_SCOPE"
+     -S "$RUNNER_SECRET"
+     -T "$RUNNER_PAT"
+     -u "$RUNNER_USER"
+   )
    if is_true "$RUNNER_EPHEMERAL"; then
-     set -- -e "$@"
+     args+=("-e")
    fi
    for _ in $(seq 1 "$RUNNER_VERBOSE"); do
-     set -- -v "$@"
+     args+=("-v")
    done
  fi

  # Add image to create from
- set -- -- "$RUNNER_IMAGE" "$@"
+ args=( "--" "$RUNNER_IMAGE" "${args[@]}" )

  # Add microVM options
- set -- \
-     -c "$RUNNER_CPUS" \
-     -m "$RUNNER_MEMORY" \
-     -d "$RUNNER_DNS" \
-     -n "${RUNNER_PREFIX}-$_id" \
-     -e "$RUNNER_ENTRYPOINT" \
-     "$@"
+ args=(
+   -c "$RUNNER_CPUS"
+   -m "$RUNNER_MEMORY"
+   -d "$RUNNER_DNS"
+   -n "${RUNNER_PREFIX}-$_id"
+   -e "$RUNNER_ENTRYPOINT"
+   "${args[@]}"
+ )

  if [ -n "${RUNNER_DIR:-}" ]; then
-   set -- -v "${RUNNER_ROOTDIR}:${RUNNER_DIR}" "$@"
+   args+=("-v" "${RUNNER_ROOTDIR}:${RUNNER_DIR}")
  fi
  if [ -n "${RUNNER_ENVIRONMENT:-}" ]; then
-   set -- -v "${RUNNER_ENVIRONMENT}:/${RUNNER_VM_ENVDIR}" "$@"
+   args+=("-v" "${RUNNER_ENVIRONMENT}:/${RUNNER_VM_ENVDIR}")
  fi
  if [ -n "$RUNNER_MOUNT" ]; then
    while IFS= read -r mount || [ -n "$mount" ]; do
      if [ -n "$mount" ]; then
-       set -- -v "$mount" "$@"
+       args+=("-v" "$mount")
      fi
    done <<EOF
$(printf %s\\n "$RUNNER_MOUNT")
EOF
  fi

  trace "Running microVM with: ${args[*]}"
  microvm_run "${args[@]}"

278-286: Simplify mounting multiple directories

The loop handling RUNNER_MOUNT can be simplified for clarity and efficiency.

Consider using a for loop:

- while IFS= read -r mount || [ -n "$mount" ]; do
-   if [ -n "$mount" ]; then
-     set -- -v "$mount" "$@"
-   fi
- done <<EOF
- $(printf %s\\n "$RUNNER_MOUNT")
- EOF
+ for mount in $RUNNER_MOUNT; do
+   [ -n "$mount" ] && args+=("-v" "$mount")
+ done

Line range hint 42-45: Duplicate definitions of RUNNER_DIR and RUNNER_MOUNT

The variables RUNNER_DIR and RUNNER_MOUNT are defined twice in the script, which may cause confusion and unexpected behavior.

Remove the duplicate definitions to maintain clarity:

-# Name of top directory in VM where to host a copy of the root directory of this
-# script. When this is set, the runner starter script from that directory will
-# be used -- instead of the one already in the OCI image. This option is mainly
-# usefull for development and testing.
-RUNNER_DIR=${RUNNER_DIR:-""}
-
-RUNNER_MOUNT=${RUNNER_MOUNT:-""}

Also applies to: 83-86

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 471b2f6 and 01cf390.

📒 Files selected for processing (6)
  • CONTRIBUTING.md (1 hunks)
  • README.md (4 hunks)
  • lib/common.sh (1 hunks)
  • lib/microvm.sh (1 hunks)
  • orchestrator.sh (5 hunks)
  • runner.sh (6 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~100-~100: Loose punctuation mark.
Context: ...un and [podman][podman]. + krunvm, its [requirements] and buildah` Note:...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (18)
README.md (6)

4-9: LGTM: Clear and accurate updates to project capabilities

The changes in this section accurately reflect the new support for krun and podman as alternatives to krunvm. The wording is clear, and the added links to the new tools are helpful for users.


15-21: LGTM: Helpful addition of resource links

The new links to libkrun, crun, and podman are well-placed and provide valuable resources for users to learn more about the newly supported tools.


93-94: LGTM: Helpful reference for users with older systems

The added reference to the original issue for installation on older versions provides valuable context for users with older systems. This is a good addition to the documentation.


106-106: LGTM: Helpful link to installation issue

The added link to the installation issue provides valuable additional context for users. This is a good addition to the documentation.


140-142: LGTM: Clear update to runner creation process

The updated description of the runner creation process accurately reflects the new capability to use podman as an alternative to krunvm for creating microVMs. The wording is clear and concise, providing users with a good understanding of the process.


Line range hint 1-184: Overall: Excellent updates to README reflecting new capabilities

The changes to the README.md file effectively communicate the new support for krun under podman and align well with the PR objectives. The documentation has been consistently updated throughout, maintaining clarity and providing users with a good understanding of the project's new capabilities and requirements.

Key improvements include:

  1. Clear explanation of the new runtime options (krunvm or krun with podman).
  2. Updated requirements section reflecting the new runtime choices.
  3. Addition of helpful links to new resources (libkrun, crun, podman).
  4. Consistent updates to the project description and architecture sections.

These changes significantly enhance the documentation, making it easier for users to understand and use the new features introduced in this PR.

orchestrator.sh (7)

34-35: Sourcing 'microvm.sh' for microVM management

Including microvm.sh integrates microVM management functions into the orchestrator script, which is appropriate for the new functionality.


61-63: Initializing 'ORCHESTRATOR_RUNTIME' variable

Defining ORCHESTRATOR_RUNTIME with a default empty value allows the script to auto-detect the runtime if none is specified, enhancing flexibility.


Line range hint 68-81: Addition of '-R' option for specifying runtime

The -R option is correctly implemented in getopts, allowing users to specify the runtime via the command line. This enhances configurability.


109-115: Ensure proper deletion of microVMs in the cleanup function

The cleanup function effectively iterates over microVMs with the specified prefix and deletes them using microvm_delete, ensuring resources are freed appropriately.


123-123: Calling 'microvm_cleanup' after microVM deletions

Invoking microvm_cleanup ensures any additional cleanup tasks related to microVMs are performed, which is a good practice.


127-127: Initializing microVM runtime with 'microvm_runtime'

Setting the runtime with microvm_runtime "$ORCHESTRATOR_RUNTIME" ensures the microVM functions operate with the correct runtime, enhancing reliability.


146-147: Exporting 'RUNNER_RUNTIME' for use in runner scripts

Adding RUNNER_RUNTIME to the exported variables allows runner scripts to access the specified runtime, maintaining consistency across scripts.

runner.sh (5)

34-35: Approved inclusion of microvm.sh

The microVM management functions are correctly sourced, allowing the script to utilize the new microVM functionalities.


120-121: Approved addition of RUNNER_RUNTIME variable

The RUNNER_RUNTIME variable is correctly initialized and will allow users to specify the runtime as intended.


128-128: Added runtime option '-R' to getopts parsing

The addition of the -R option enables users to specify the runtime via command-line arguments.


160-161: Approved handling of '-R' option in getopts

The script correctly captures the runtime specified with the -R option and assigns it to RUNNER_RUNTIME.


210-211: Passing runtime to microVM script

The call to microvm_runtime "$RUNNER_RUNTIME" correctly passes the selected runtime to the microVM script.

CONTRIBUTING.md Outdated Show resolved Hide resolved
lib/common.sh Show resolved Hide resolved
lib/common.sh Show resolved Hide resolved
lib/common.sh Show resolved Hide resolved
orchestrator.sh Show resolved Hide resolved
lib/microvm.sh Show resolved Hide resolved
runner.sh Show resolved Hide resolved
runner.sh Show resolved Hide resolved
runner.sh Show resolved Hide resolved
runner.sh Show resolved Hide resolved
@efrecon efrecon merged commit 22b231a into main Sep 27, 2024
4 of 8 checks passed
@efrecon efrecon deleted the feature/podman branch September 27, 2024 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using podman
1 participant