-
Notifications
You must be signed in to change notification settings - Fork 65
controllers: Validates kata version aginst the Kata RPM version present in the extension image. #1514
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
base: devel
Are you sure you want to change the base?
controllers: Validates kata version aginst the Kata RPM version present in the extension image. #1514
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,51 +47,31 @@ update_config() { | |
| # 0 on success | ||
| ####################################### | ||
| install_addons() { | ||
| local addon_image="${ADDON_IMAGE:?}" | ||
|
|
||
| echo "Installing addon artifacts from: $addon_image" | ||
|
|
||
| local kernel_src="${ADDON_KERNEL_PATH:?}" | ||
| local kernel_file | ||
| kernel_file="$(basename "$kernel_src")" | ||
|
|
||
| if [ -z "$kernel_src" ]; then | ||
| echo "ERROR: ADDON_KERNEL_PATH is mandatory but was not provided." >&2 | ||
| local staged_dir="/host/var/lib/kata/addons" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is used in multiple functions so I think it should be a global variable.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other function is |
||
| local staged_kernel="${staged_dir}/${kernel_src}" | ||
|
|
||
| if [[ ! -f "$staged_kernel" ]]; then | ||
| echo "ERROR: Staged kernel not found: $staged_kernel" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Standard installation directory | ||
| local install_dir="/host/etc/kata-containers" | ||
| local temp_dir="/tmp/kata-addons-$$" | ||
| local auth_file="/tmp/regauth/auth.json" | ||
|
|
||
| mkdir -p "$install_dir" | ||
| mkdir -p "$temp_dir" | ||
|
|
||
| local kernel_installed="" | ||
| local kernel_path="" | ||
|
|
||
| # Extract and install kernel | ||
| echo "Extracting kernel from: $kernel_src" | ||
|
|
||
| # Reuse extract_container_image from lib.sh | ||
| if extract_container_image "$addon_image" "$kernel_src" "$temp_dir" "$auth_file"; then | ||
| local kernel_file=$(basename "$kernel_src") | ||
| if [ -f "$temp_dir/$kernel_file" ]; then | ||
| kernel_installed="$install_dir/$kernel_file" | ||
| kernel_path="/etc/kata-containers/$kernel_file" | ||
| cp "$temp_dir/$kernel_file" "$kernel_installed" | ||
| chmod 644 "$kernel_installed" | ||
| echo "Kernel installed: $kernel_installed" | ||
| local kernel_installed="${install_dir}/${kernel_file}" | ||
| local kernel_path="/etc/kata-containers/${kernel_file}" | ||
|
|
||
| # Print checksum of the installed kernel | ||
| echo "Kernel image $kernel_file checksum (sha256):" | ||
| sha256sum "$kernel_installed" | ||
| fi | ||
| fi | ||
| cp "$staged_kernel" "$kernel_installed" | ||
|
|
||
| rm -rf $staged_dir | ||
|
|
||
| echo "Kernel installed: $kernel_installed" | ||
| echo "Kernel image $kernel_file checksum (sha256):" | ||
| sha256sum "$kernel_installed" | ||
|
|
||
| # Cleanup | ||
| rm -rf "$temp_dir" | ||
|
|
||
| # Update kata configuration | ||
| update_config "$kernel_path" | ||
|
|
||
| echo "Addon installation completed" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,42 @@ set_status_uninstalled() { | |
| label_node "uninstalled" | ||
| } | ||
|
|
||
| extract_kata_version_from_rpm() { | ||
| local rpm="$1" | ||
| basename "$rpm" | sed -E 's/^kata-containers-([0-9]+\.[0-9]+(\.[0-9]+)?).*/\1/' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use rpm -q --qf "%{VERSION}\n" "$rpm" |
||
| } | ||
|
|
||
| extract_kata_addon_image() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be two functions. One to extract the addon and one to get the version. It would be easier to understand what it does imo. |
||
| local addon_image="$1" | ||
| local addon_stage_dir="/host/var/lib/kata/addons" | ||
|
|
||
| mkdir -p $addon_stage_dir | ||
|
|
||
| extract_container_image \ | ||
| "$addon_image" \ | ||
| "/artifacts" \ | ||
| "$addon_stage_dir" \ | ||
| "/tmp/regauth/auth.json" >/dev/null | ||
|
|
||
|
|
||
| if [[ ! -f "$addon_stage_dir/artifacts/version.json" ]]; then | ||
| echo "ERROR: version.json not found in addon image" | ||
| exit 1 | ||
| fi | ||
|
|
||
| dnf install -y jq >/dev/null 2>&1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The jq installation should be moved in the Dockerfile imo. |
||
|
|
||
| local kata_version | ||
| kata_version=$(jq -r '.kata_version' "$addon_stage_dir/artifacts/version.json") | ||
|
|
||
| if [[ -z "$kata_version" || "$kata_version" == "null" ]]; then | ||
| echo "ERROR: kata_version missing in version.json" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "$kata_version" | ||
| } | ||
|
|
||
| install() { | ||
| # Initial wait: avoid doing anything if a previous staged update is pending | ||
| wait_for_reboot_clear | ||
|
|
@@ -104,6 +140,20 @@ install() { | |
| continue | ||
| fi | ||
|
|
||
| if [[ "$package" == "kata-containers" && -n "${ADDON_IMAGE:-}" ]]; then | ||
| rpm_kata_version=$(extract_kata_version_from_rpm "$rpm_path") | ||
| addon_kata_version=$(extract_kata_addon_image "$ADDON_IMAGE") | ||
|
|
||
| if [[ "$addon_kata_version" != "$rpm_kata_version" ]]; then | ||
| echo "ERROR: Kata version mismatch between addon image and host RPM" | ||
| echo "Addon image kata version: $addon_kata_version" | ||
| echo "Host kata RPM version: $rpm_kata_version" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Addon image kata version validated: $addon_kata_version" | ||
| fi | ||
|
|
||
| # Get available version | ||
| available_version=$(rpm -qp "$rpm_path") | ||
|
|
||
|
|
||
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.
@ANJANA-A-R-K Could you explain why do you need this?