package
1.5.0-rc.1
Repository: https://github.com/kubevirt/kubevirt.git
Documentation: pkg.go.dev

# README

libvmi

libvmi is a VMI manifest composer.

Overview

Motivation

While reading code, especially test code, a difficulty has been observed to understand in an easy and clear manner, what is the content of a VMI object. In a long chain of function call stack, different portions of the VMI got updated, sometime overriding previously set fields.

Goal

  • Simplify the creation of VMI objects.
  • Easily understand what VMI objects contain.

How

libvmi is aimed to build the vmi manifest.

It uses the builder pattern, allowing a modular construction of VMI different sections.

Rules

In order to keep the package useful and easy to maintain, a few rules are in order.

The main goal of these rules are to keep the package simple to use and easy to grow. While exceptions may apply, they will need a wide consensus and should not be overused. It would be better to just ask to change the rules.

  • Use only the existing builder pattern to support editing fields.
  • Place builders in a proper subject file, either one that exists or in a new one with a good name. A common developer should be able to find the relevant content based on the file name.
    • Do not fill up the vmi.go file, unless you have a very good reason.
  • Do not add logic in builders, unless they fell into these categories:
    • It is a factory that is widely used. (e.g. amount of memory depending on the architecture).
    • It is a widely used abstraction that combines several fields that have some dependency on each other.
  • Any builder can be added if it has no logic (except for lazy creation of the path to the relevant fields). In practice, this implies that even builders that are used by a small amount of callers can be added, as long as they do not possess logic.
  • Do not add commands on objects, e.g. calls through clients.
  • Building general annotations or labels which have special meaning are a fit if they related to VM or VMI objects. To clarify, annotation that relate to pods, are not a perfect fit here. Annotations that relate to a specific subject (e.g. network) may fit here or under a more dedicated library/package.

Note: A builder is considered widely used when it is needed from multiple packages. In case a single package or test file is using it, it may fit better under that package or test. The reason is simple, it has more context closer to the usage and known by the developers in a more accurate manner.

Structure

  • VMI: vmi.go contains the most basic tooling to start building VMI manifests. It contains the most basic factory (New), the definition of how the builders look like and any other helper that serves the whole libvmi package.
  • Subject builders: Various files in which builders and defined. These files should group builders with some commonality, such that they can be easily found. With time, the grouping and naming may change (e.g. subjects split when they grow too much).

Maintenance and Ownership

Maintainers are expected to follow the above rules or ask for exceptions. Possibly asking to change a rule with a good reasoning.

Make sure to always keep things in focus, simple and clean. When things get out of control, things get slower, not faster.

# Packages

Package status provides utility options to manage the vmi status.

# Functions

InterfaceDeviceWithBridgeBinding returns an Interface with bridge binding.
InterfaceDeviceWithMasqueradeBinding returns an Interface named "default" with masquerade binding.
InterfaceDeviceWithSRIOVBinding returns an Interface with SRIOV binding.
InterfaceWithMac decorates an existing Interface with a MAC address.
InterfaceWithMacvtapBindingPlugin returns an Interface named "default" with "macvtap" binding plugin.
InterfaceWithPasstBinding returns an Interface named "default" with passt binding plugin.
MultusNetwork returns a Network with the given name, associated to the given nad.
New instantiates a new VMI configuration, building its properties based on the specified With* options.
WithAccessCredentialSSHPublicKey adds an AccessCredential that propagates the public keys found in secretName to the authorized_keys file of the user with name userName via the qemu-guest-agent.
WithAccessCredentialUserPassword adds an AccessCredential that propagates the user passwords found in secretName via the qemu-guest-agent.
WithAnnotation adds an annotation with specified value.
WithAutoAttachPodInterface sets the autoattachPodInterface parameter.
WithCDRom specifies a CDRom drive backed by a PVC to be used.
WithCDRomAndVolume specifies a CDRom drive backed by given volume and given bus.
WithCloudInitConfigDrive adds cloud-init config-drive sources.
WithCloudInitNoCloud adds cloud-init no-cloud sources.
WithContainerDisk specifies the disk name and the name of the container image to be used.
WithContainerDiskAndPullPolicy specifies the disk name, the name of the container image and Pull Policy to be used.
WithContainerSATADisk specifies the disk name and the name of the container image to be used.
WithDataVolume specifies the name of the DataVolume to be used.
WithEmptyDisk specifies the name of the EmptyDisk to be used.
WithEphemeralCDRom specifies a CDRom drive to be used.
WithEphemeralPersistentVolumeClaim specifies the name of the Ephemeral.PersistentVolumeClaim to be used.
WithFilesystemDV specifies a filesystem backed by a DV to be used.
WithFilesystemPVC specifies a filesystem backed by a PVC to be used.
WithHostname sets the hostname parameter.
WithInterface adds a Domain Device Interface.
WithIOThreadsPolicy sets the WithIOThreadPolicy parameter.
WithLabel sets a label with specified value.
WithLimitCPU specifies the VMI CPU limit.
WithLimitMemory specifies the VMI memory limit.
WithNetwork adds a network object.
WithNodeSelector ensures that the VMI gets scheduled on a node with specified key/value label.
WithNodeSelectorFor ensures that the VMI gets scheduled on the specified node.
WithPersistentVolumeClaim specifies the name of the PersistentVolumeClaim to be used.
WithResourceCPU specifies the vmi CPU resource.
WithResourceMemory specifies the vmi memory resource.
WithRng adds `rng` to the vmi devices.
WithSEV adds `launchSecurity` with `sev`.
WithSubdomain sets the subdomain parameter.
WithTablet adds tablet device with given name and bus.
WithTerminationGracePeriod specifies the termination grace period in seconds.
WithUefi configures EFI bootloader and SecureBoot.
WithWatchdog adds a watchdog to the vmi devices.

# Constants

# Type aliases

Option represents an action that enables an option.