HTTP server route handler:
Call Kubernetes REST client directly:
End of investigation on Harvester side.
Since I knew that Harvester is based on KubeVirt, I went to KubeVirt next.
Refer to https://kubevirt.io/user-guide/architecture/, I knew that virt-launcher is responsible to communicate with libvirt:
So I searched something like CreateVMI
in virt-launcher but I found nothing.
So I alternatively located VirtualMachineInstance
struct, see if any method in virt-launcher used it, and I found about 143 usages. I filtered methods one by one, then I found a method called SyncVMI
.
It called CreateWithFlags
to create virtual machine:
...which was actually a C binding to libvirt:
Surprisingly, libvirt called virtual machine domain, which was very unusual.
Followed how I resolved the previous question, I focused on virt-launcher. SyncVMI
called getAttachedDisks
to get list of disk to be attached on virtual machine:
...but after I check checkIfDiskReadyToUse
method, I was getting confusing:
It called os.Stat
internally to check whether the disk is ready, so the disk must existed on node before SyncVMI
got things done:
Since Longhorn can provide volume as iSCSI target, I presumed one or more components must do the following things...
- A component requests Longhorn mount a volume as iSCSI target
- A component mounts the iSCSI target on specific nodes
- A component on specific node receives virtual machine or virtual machine instance request from scheduler, starts a new virtual machine and mount the iSCSI target in traditional Linux way (that's why we need
open-iscsi
package installed on node), and manipulates qemu to mount the disk
Then I found nothing related in code-base, so I go back to documentation, search for keyword "iSCSI", then I found a Markdown file:
So I put it simply:
- User puts information about iSCSI target on Kubernetes cluster, which is built-in function: https://github.com/kubernetes/website/blob/b50819e5f9d64784f5de2ee620ef667d59280efe/content/en/docs/concepts/storage/volumes.md#iscsi
- virt-handler converts VMI spec (YAML on Kubernetes) to libvirt configuration (XML on node)
- libvirt mounts iSCSI target directly with XML configuration