Skip to content

[virtual-machines] Introduce golden disks functionality - #1112

Merged
Andrei Kvapil (kvaps) merged 2 commits into
mainfrom
feat-cdi
Jul 3, 2025
Merged

[virtual-machines] Introduce golden disks functionality#1112
Andrei Kvapil (kvaps) merged 2 commits into
mainfrom
feat-cdi

Conversation

@gwynbleidd2106

@gwynbleidd2106 gwynbleidd2106 commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Use Golden Images to speed up VM / VMI deploy

Summary by CodeRabbit

  • New Features

    • Added support for using pre-imported "golden image" disks for virtual machines, enabling faster provisioning by referencing existing images instead of downloading via HTTP.
    • Introduced a script to automate the import of golden images into the system.
  • Improvements

    • Updated documentation and configuration to clarify and demonstrate how to use golden images.
    • Enhanced permission settings to support secure cloning of data volumes.
  • Versioning

    • Updated vm-disk package to version 0.3.0.
    • Updated virtual-machine app version to 0.12.0.

@coderabbitai

coderabbitai Bot commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new script is introduced to automate golden image DataVolume creation for Kubernetes CDI. Helm templates for VM and disk resources are updated to prefer golden image PVCs over HTTP sources. The CDI configuration is enhanced with clone strategy and RBAC permissions. Documentation and versioning for the vm-disk package are updated.

Changes

File(s) Change Summary
hack/cdi_golden_image_create.sh New script to create a CDI DataVolume from an HTTP URL as a golden image in Kubernetes.
packages/apps/virtual-machine/templates/vm.yaml, packages/apps/vm-disk/templates/dv.yaml Template logic updated to prefer golden image DataVolume PVCs if available, falling back to HTTP otherwise.
packages/apps/vm-disk/values.yaml Documentation updated to clarify golden image usage and provide an example.
packages/system/kubevirt-cdi/templates/cdi-cr.yaml CDI spec updated with clone strategy override and new RBAC resources for DataVolume cloning permissions.
packages/apps/versions_map Updated vm-disk version mapping: anchored 0.2.0 to a commit, added 0.3.0 as HEAD.
packages/apps/vm-disk/Chart.yaml Chart and app version incremented from 0.2.0 to 0.3.0.
packages/apps/virtual-machine/Chart.yaml App version updated from 0.11.0 to 0.12.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant Kubernetes API

    User->>Script: Run cdi_golden_image_create.sh <name> <url>
    Script->>Kubernetes API: Create DataVolume vm-image-<name> (HTTP source: <url>)
    Kubernetes API-->>User: DataVolume created in cozy-public namespace
Loading
sequenceDiagram
    participant VM_Template
    participant K8s_API

    VM_Template->>K8s_API: Lookup DataVolume vm-image-<imageName> in cozy-public
    alt DataVolume exists
        VM_Template->>K8s_API: Use PVC source from DataVolume
    else
        VM_Template->>K8s_API: Use HTTP source for image import
    end
Loading

Suggested labels

enhancement, size:L

Suggested reviewers

  • klinch0

Poem

🐇
Golden images hop to life,
With scripts and YAML, free from strife.
PVCs preferred, HTTP if not,
Version bumps and docs—what a lot!
CDI gets its clone and role,
The rabbit’s code now feels whole.
🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a562b82 and 986de71.

📒 Files selected for processing (8)
  • hack/cdi_golden_image_create.sh (1 hunks)
  • packages/apps/versions_map (1 hunks)
  • packages/apps/virtual-machine/Chart.yaml (1 hunks)
  • packages/apps/virtual-machine/templates/vm.yaml (2 hunks)
  • packages/apps/vm-disk/Chart.yaml (1 hunks)
  • packages/apps/vm-disk/templates/dv.yaml (1 hunks)
  • packages/apps/vm-disk/values.yaml (1 hunks)
  • packages/system/kubevirt-cdi/templates/cdi-cr.yaml (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/apps/virtual-machine/Chart.yaml
  • hack/cdi_golden_image_create.sh
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/apps/vm-disk/values.yaml
  • packages/apps/vm-disk/Chart.yaml
  • packages/apps/virtual-machine/templates/vm.yaml
  • packages/apps/vm-disk/templates/dv.yaml
  • packages/apps/versions_map
  • packages/system/kubevirt-cdi/templates/cdi-cr.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@gwynbleidd2106
gwynbleidd2106 force-pushed the feat-cdi branch 12 times, most recently from 40df3b1 to a0d2f94 Compare June 30, 2025 04:13
@gwynbleidd2106
gwynbleidd2106 marked this pull request as ready for review June 30, 2025 05:35

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
packages/apps/virtual-machine/templates/vm.yaml (1)

42-61: Missing guards when systemDisk.image is empty can produce invalid manifests

If systemDisk.image is omitted or an unsupported value is supplied:
$goldenImageName evaluates to empty → lookup returns nil, the else branch is chosen, but the HTTP url stanza is also empty, leaving source: without children – the VM object will be rejected by the API server.

Add a sanity check or fallback:

-{{- $goldenImageName := .Values.systemDisk.image }}
+{{- $goldenImageName := required ".Values.systemDisk.image must be set" .Values.systemDisk.image }}

and optionally fail when the value is not one of the recognised images:

{{- fail (printf "Unsupported systemDisk.image: %s" $goldenImageName) }}
🧹 Nitpick comments (3)
hack/cdi_golden_image_create.sh (3)

3-3: Harden script flags

Add set -u -o pipefail to catch unset vars and pipeline errors.

-set -e
+set -euo pipefail

8-12: Improve usage message & exit code semantics

Return exit status 2 for bad usage (conventional) and print the script name automatically:

echo "Usage: $(basename "$0") <name> <url>" >&2
exit 2

14-32: kubectl create fails on reruns – prefer apply and pre-check namespace

Running the script twice currently errors with “already exists”. Using kubectl apply makes it idempotent, and ensuring the namespace exists avoids a race.

-kubectl create -f - <<EOF
+kubectl apply -f - <<EOF
 ...
-  namespace: cozy-public
+  namespace: cozy-public
 ...
 EOF

# ensure namespace beforehand
kubectl get ns cozy-public >/dev/null 2>&1 || kubectl create ns cozy-public
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78b4d06 and a0d2f94.

📒 Files selected for processing (5)
  • hack/cdi_golden_image_create.sh (1 hunks)
  • packages/apps/virtual-machine/templates/vm.yaml (2 hunks)
  • packages/apps/vm-disk/templates/dv.yaml (1 hunks)
  • packages/apps/vm-disk/values.yaml (1 hunks)
  • packages/system/kubevirt-cdi/templates/cdi-cr.yaml (2 hunks)
🔇 Additional comments (2)
packages/system/kubevirt-cdi/templates/cdi-cr.yaml (1)

6-6: Global clone‐strategy change may have unintended cluster-wide impact

Setting cloneStrategyOverride: copy affects all DataVolume clones handled by CDI.
• “copy” is slower and heavier on storage than “snapshot”/“csivolume” on back-ends that support them.
• There is no per-namespace escape hatch once the override is in place.

Double-check that every storage-class in every environment is comfortable with the forced copy strategy, or consider omitting the override and letting CDI auto-select the optimal clone strategy.

packages/apps/vm-disk/values.yaml (1)

3-7: Docs update looks good

Inline examples now clearly spell out that source.image expects a golden-image name – reduces ambiguity for chart users.

Comment thread packages/system/kubevirt-cdi/templates/cdi-cr.yaml
Comment thread packages/system/kubevirt-cdi/templates/cdi-cr.yaml
Comment thread packages/apps/vm-disk/templates/dv.yaml Outdated
Comment on lines +23 to +28
{{- $goldenImageName := .Values.source.image }}
{{- if $goldenImageName }}
{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" "cozy-public" (printf "goldenimage-%s" $goldenImageName) }}
pvc:
name: goldenimage-{{ $goldenImageName }}
namespace: cozy-public
{{- else if hasKey .Values.source "http" }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

PVC branch should verify that the golden image DataVolume actually exists

Unlike the VM template, this chart always emits a PVC reference even when the lookup returns nil, causing the DV creation to hang forever.

Wrap the PVC block with the same existence check or fail early:

-{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" "cozy-public" (printf "goldenimage-%s" $goldenImageName) }}
-pvc:
-  name: goldenimage-{{ $goldenImageName }}
-  namespace: cozy-public
+{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" "cozy-public" (printf "goldenimage-%s" $goldenImageName) }}
+{{- if $dv }}
+pvc:
+  name: goldenimage-{{ $goldenImageName }}
+  namespace: cozy-public
+{{- else }}
+{{- fail (printf "Golden image %s not found in cozy-public namespace" $goldenImageName) }}
+{{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- $goldenImageName := .Values.source.image }}
{{- if $goldenImageName }}
{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" "cozy-public" (printf "goldenimage-%s" $goldenImageName) }}
pvc:
name: goldenimage-{{ $goldenImageName }}
namespace: cozy-public
{{- else if hasKey .Values.source "http" }}
{{- $goldenImageName := .Values.source.image }}
{{- if $goldenImageName }}
{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" "cozy-public" (printf "goldenimage-%s" $goldenImageName) }}
{{- if $dv }}
pvc:
name: goldenimage-{{ $goldenImageName }}
namespace: cozy-public
{{- else }}
{{- fail (printf "Golden image %s not found in cozy-public namespace" $goldenImageName) }}
{{- end }}
{{- else if hasKey .Values.source "http" }}
🤖 Prompt for AI Agents
In packages/apps/vm-disk/templates/dv.yaml around lines 23 to 29, the PVC block
is emitted even when the lookup for the golden image DataVolume returns nil,
causing hangs. Fix this by wrapping the PVC block inside a conditional that
checks if the DataVolume exists (i.e., the lookup result is not nil), so the PVC
is only referenced when the DataVolume is present, or alternatively add an early
failure if it does not exist.

@gwynbleidd2106 gwynbleidd2106 changed the title [feat] CDI to clone golden disks for reuse [CDI] golden disks feature for reuse Jun 30, 2025
@gwynbleidd2106
gwynbleidd2106 force-pushed the feat-cdi branch 2 times, most recently from ecbf8b2 to 88cc13a Compare June 30, 2025 16:00
Use Golden Images to speed up VM / VMI deploy

Signed-off-by: gwynbleidd <gwynbleidd2106@yandex.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@kvaps Andrei Kvapil (kvaps) changed the title [CDI] golden disks feature for reuse [virtual-machines] Introduce golden disks functionality Jul 3, 2025

@kvaps Andrei Kvapil (kvaps) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just refactored a bit, renamed goldenimage- to vm-image-.
added check for image name input for vm-instance application
other things are LGTM

@kvaps
Andrei Kvapil (kvaps) merged commit c596805 into main Jul 3, 2025
@kvaps
Andrei Kvapil (kvaps) deleted the feat-cdi branch July 3, 2025 11:25
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.

3 participants