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

feat(core, kubevirt): add patch for hotplug container-disk #564

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

yaroslavborbat
Copy link
Member

@yaroslavborbat yaroslavborbat commented Dec 10, 2024

Description

Add patch for hotplug container-disk

container-disk

The container-disk is a program written in C used within KubeVirt to facilitate the mounting of container-based disk images into virtual machines. Its core function is to start up and create a UNIX socket within a specific directory. The program terminates when the socket is removed or upon receiving a SIGTERM signal.

Key Workflow: container-disk

Initialization

  • A sidecar container, running the container-disk image, is created alongside the virt-launcher pod.
  • An init-container in the virt-launcher pod copies the container-disk program to a shared emptyDir volume. This setup allows the sidecar to execute the program.

Socket Creation

  • The container-disk program creates a socket in the emptyDir volume.
  • This shared volume allows the virt-handler to locate the socket on the host machine at:
    /var/lib/kubelet/pods/.../volumes/kubernetes.io~empty-dir/.

Socket Detection and Mounting

  • Upon detecting the socket, virt-handler identifies it as a container-disk volume and retrieves its parent mount point.
  • For a container runtime like containerd, the mount point resolves to the root filesystem of the pulled image, typically at:
    /run/containerd/io.containerd.runtime.v2.task/k8s.io/<uid>/rootfs/.
  • The disk image must be located at disk/disk.img within this filesystem and is mounted into the VM.

HotPlug in KubeVirt

The HotPlug mechanism allows dynamic attachment of PVCs and container-disk volumes to a running VM by leveraging a separate hotplug pod.

HotPlug Pod Setup

  • A hotplug pod is created with the target PVCs mounted into an emptyDir volume under the /hp directory.
  • The container-disk program runs in the hotplug pod to create the necessary sockets for these volumes.

Volume Detection and Mounting

  • The virt-handler locates the sockets on the host system at:
    /var/lib/kubelet/pods/<uid-hotplug-pod>/volumes/empty-dir/hp-disks/....
  • For block devices, virt-handler creates a block device on the VM using mknodat.
  • For file systems, the volume is mounted as a file.

Unmounting

  • The unmount process is identical to that of hotplug PVCs.
  • The emptyDir resources are retained and cleaned up later by Kubernetes.

Why do we need it, and what problem does it solve?

What is the expected result?

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

@yaroslavborbat yaroslavborbat changed the title add feat(core, kubevirt): add patch for hotplug container-disk Dec 10, 2024
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch from 5133be7 to a78c659 Compare December 19, 2024 09:12
@yaroslavborbat yaroslavborbat marked this pull request as ready for review December 19, 2024 09:12
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch 3 times, most recently from 96ee51e to dffb2f7 Compare December 19, 2024 09:53
@diafour
Copy link
Member

diafour commented Dec 23, 2024

If there are some modifications over the upstream code, it'd be better to split into 2 patches: 1st with the untouched code from the upstream and 2nd with modifications from us.

Resolved: there is no code from upstream.

@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch 2 times, most recently from 48ccceb to 5b6e7d0 Compare December 23, 2024 09:45
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch from 5b6e7d0 to 2bfd1b7 Compare January 9, 2025 13:41
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch 4 times, most recently from 8612ac0 to 27a1aa0 Compare January 15, 2025 01:41
@Isteb4k Isteb4k added this to the v0.15.0 milestone Jan 15, 2025
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch 4 times, most recently from 13c8da2 to e0dc596 Compare January 18, 2025 20:00
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch from 94e3bb4 to 01ca237 Compare January 20, 2025 15:24
Signed-off-by: yaroslavborbat <[email protected]>
@yaroslavborbat yaroslavborbat force-pushed the feat/kubevirt/add-hotplug-container-image branch from 01ca237 to 9861407 Compare January 20, 2025 15:25
@yaroslavborbat yaroslavborbat requested a review from fl64 January 20, 2025 15:26
@yaroslavborbat yaroslavborbat merged commit fb01c70 into main Jan 20, 2025
12 checks passed
@yaroslavborbat yaroslavborbat deleted the feat/kubevirt/add-hotplug-container-image branch January 20, 2025 15:27
hardcoretime pushed a commit that referenced this pull request Jan 23, 2025
Add patch for hotplug container-disk

Signed-off-by: yaroslavborbat <[email protected]>
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.

4 participants