libvirttools

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2018 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ContainerNsUUID template for container ns uuid generation
	ContainerNsUUID = "67b7fb47-7735-4b64-86d2-6d062d121966"

	// KubernetesPodNameLabel is pod name container label (copied from kubetypes).
	KubernetesPodNameLabel = "io.kubernetes.pod.name"
	// KubernetesPodNamespaceLabel is pod namespace container label (copied from kubetypes),
	KubernetesPodNamespaceLabel = "io.kubernetes.pod.namespace"
	// KubernetesPodUIDLabel is uid container label (copied from kubetypes).
	KubernetesPodUIDLabel = "io.kubernetes.pod.uid"
	// KubernetesContainerNameLabel is container name label (copied from kubetypes)
	KubernetesContainerNameLabel = "io.kubernetes.container.name"
)

Variables

This section is empty.

Functions

func ChownForEmulator

func ChownForEmulator(filePath string, recursive bool) error

ChownForEmulator makes a file or directory owned by the emulator user.

func ChownR

func ChownR(path string, uid, gid int) error

ChownR makes a file or directory owned by the emulator user recursively.

func SetConfigIsoDir

func SetConfigIsoDir(dir string)

SetConfigIsoDir sets a directory for config iso dir. It can be useful in tests

Types

type CloudInitGenerator

type CloudInitGenerator struct {
	// contains filtered or unexported fields
}

CloudInitGenerator provides a common part for Cloud Init ISO drive preparation for NoCloud and ConfigDrive volume sources.

func NewCloudInitGenerator

func NewCloudInitGenerator(config *types.VMConfig, isoDir string) *CloudInitGenerator

NewCloudInitGenerator returns new CloudInitGenerator.

func (*CloudInitGenerator) DiskDef

DiskDef returns a DomainDisk definition for Cloud Init ISO image to be included in VM pod libvirt domain definition.

func (*CloudInitGenerator) GenerateImage

func (g *CloudInitGenerator) GenerateImage(volumeMap diskPathMap) error

GenerateImage collects metadata, userdata and network configuration and uses them to prepare an ISO image for NoCloud or ConfigDrive selecting the type using an info from pod annotations.

func (*CloudInitGenerator) IsoPath

func (g *CloudInitGenerator) IsoPath() string

IsoPath returns a full path to iso image with configuration for VM pod.

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection combines accessors for methods which operated on libvirt storage and domains.

func NewConnection

func NewConnection(uri string) (*Connection, error)

NewConnection uses uri to construct connection to libvirt used later by both storage and domains manipulators.

func (Connection) CreateStoragePool

func (sc Connection) CreateStoragePool(def *libvirtxml.StoragePool) (virt.StoragePool, error)

func (Connection) DefineDomain

func (dc Connection) DefineDomain(def *libvirtxml.Domain) (virt.Domain, error)

func (Connection) DefineSecret

func (dc Connection) DefineSecret(def *libvirtxml.Secret) (virt.Secret, error)

func (Connection) ListDomains

func (dc Connection) ListDomains() ([]virt.Domain, error)

func (Connection) ListPools

func (sc Connection) ListPools() ([]virt.StoragePool, error)

func (Connection) LookupDomainByName

func (dc Connection) LookupDomainByName(name string) (virt.Domain, error)

func (Connection) LookupDomainByUUIDString

func (dc Connection) LookupDomainByUUIDString(uuid string) (virt.Domain, error)

func (Connection) LookupSecretByUUIDString

func (dc Connection) LookupSecretByUUIDString(uuid string) (virt.Secret, error)

func (Connection) LookupSecretByUsageName

func (dc Connection) LookupSecretByUsageName(usageType string, usageName string) (virt.Secret, error)

func (Connection) LookupStoragePoolByName

func (sc Connection) LookupStoragePoolByName(name string) (virt.StoragePool, error)

type ImageManager

type ImageManager interface {
	// GetImagePathDigestAndVirtualSize returns the path, image
	// digest ("sha256:...") and the size in bytes for the
	// specified image.
	GetImagePathDigestAndVirtualSize(ref string) (string, digest.Digest, uint64, error)
	// FilesystemStats returns filesystem statistics for the specified image.
	FilesystemStats() (*types.FilesystemStats, error)
	// BytesUsedBy returns the size of the specified file.
	BytesUsedBy(path string) (uint64, error)
}

ImageManager describes an image info provider.

type LibvirtDiagSource

type LibvirtDiagSource struct {
	// contains filtered or unexported fields
}

LibvirtDiagSource dumps libvirt domains, storage pools and storage volumes as a set of XML files.

func NewLibvirtDiagSource

func NewLibvirtDiagSource(domainConn virt.DomainConnection, storageConn virt.StorageConnection) *LibvirtDiagSource

NewLibvirtDiagSource creates a new LibvirtDiagSource.

func (*LibvirtDiagSource) DiagnosticInfo

func (s *LibvirtDiagSource) DiagnosticInfo() (diag.Result, error)

DiagnosticInfo implements DiagnosticInfo method of the Source interface.

type VMVolume

type VMVolume interface {
	UUID() string
	Setup() (*libvirtxml.DomainDisk, *libvirtxml.DomainFilesystem, error)
	WriteImage(diskPathMap) error
	Teardown() error
}

VMVolume describes a volume provider.

func GetBlockVolumes

func GetBlockVolumes(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

GetBlockVolumes returns VMVolume objects for block devices that are passed to the pod.

func GetConfigVolume

func GetConfigVolume(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

GetConfigVolume returns a config volume source which will produce an ISO image with CloudInit compatible configuration data.

func GetFileSystemVolumes

func GetFileSystemVolumes(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

GetFileSystemVolumes using prepared by kubelet volumes and contained in pod sandbox annotations prepares volumes to be passed to libvirt as a DomainFileSystem definitions.

func GetRootVolume

func GetRootVolume(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

GetRootVolume returns volume source for root volume clone.

func ScanFlexVolumes

func ScanFlexVolumes(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

ScanFlexVolumes returns VMVolume objects for Virtlet flexvolumes mounted into the pod.

type VMVolumeSource

type VMVolumeSource func(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error)

VMVolumeSource is a function that provides `VMVolume`s for VMs

func CombineVMVolumeSources

func CombineVMVolumeSources(srcs ...VMVolumeSource) VMVolumeSource

CombineVMVolumeSources returns a function which will pass VM configuration to all listed volumes sources combining returned by them `VMVolume`s.

func GetDefaultVolumeSource

func GetDefaultVolumeSource() VMVolumeSource

GetDefaultVolumeSource returns a volume source that supports root volume, flexvolumes and a ConfigSource for cloud-init

type VirtualizationConfig

type VirtualizationConfig struct {
	// True if KVM should be disabled
	DisableKVM bool
	// True if SR-IOV support needs to be enabled
	EnableSriov bool
	// List of raw devices that can be accessed by the VM.
	RawDevices []string
	// Kubelet's root dir
	// FIXME: kubelet's --root-dir may be something other than /var/lib/kubelet
	// Need to remove it from daemonset mounts (both dev and non-dev)
	// Use 'nsenter -t 1 -m -- tar ...' or something to grab the path
	// from root namespace
	KubeletRootDir string
	// The path of streamer socket used for
	// logging. By default, the path is empty. When the path is empty,
	// logging is disabled for the VMs.
	StreamerSocketPath string
	// The name of libvirt volume pool to use for the VMs.
	VolumePoolName string
	// CPUModel contains type (can be overloaded by pod annotation)
	// of cpu model to be passed in libvirt domain definition.
	// Empty value denotes libvirt defaults usage.
	CPUModel string
	// Path to the directory used for shared filesystems
	SharedFilesystemPath string
}

VirtualizationConfig specifies configuration options for VirtualizationTool.

type VirtualizationTool

type VirtualizationTool struct {
	// contains filtered or unexported fields
}

VirtualizationTool provides methods to operate on libvirt.

func NewVirtualizationTool

func NewVirtualizationTool(domainConn virt.DomainConnection,
	storageConn virt.StorageConnection, imageManager ImageManager,
	metadataStore metadata.Store, volumeSource VMVolumeSource,
	config VirtualizationConfig, mounter utils.Mounter,
	mountPointChecker utils.MountPointChecker,
	commander utils.Commander) *VirtualizationTool

NewVirtualizationTool verifies existence of volumes pool in libvirt store and returns initialized VirtualizationTool.

func (*VirtualizationTool) Commander

func (v *VirtualizationTool) Commander() utils.Commander

Commander implements volumeOwner Commander method

func (*VirtualizationTool) ContainerInfo

func (v *VirtualizationTool) ContainerInfo(containerID string) (*types.ContainerInfo, error)

ContainerInfo returns info for the specified container, making sure it's also present among libvirt domains. If it isn't, the function returns nil

func (*VirtualizationTool) CreateContainer

func (v *VirtualizationTool) CreateContainer(config *types.VMConfig, netFdKey string) (string, error)

CreateContainer defines libvirt domain for VM, prepares it's disks and stores all info in metadata store. It returns domain uuid generated basing on pod sandbox id.

func (*VirtualizationTool) DomainConnection

func (v *VirtualizationTool) DomainConnection() virt.DomainConnection

DomainConnection implements volumeOwner DomainConnection method

func (*VirtualizationTool) GarbageCollect

func (v *VirtualizationTool) GarbageCollect() (allErrors []error)

GarbageCollect retrieves from metadata store list of container ids, passes it to all GC submodules, collecting from them list of possible errors, which is returned to outer scope

func (*VirtualizationTool) ImageManager

func (v *VirtualizationTool) ImageManager() ImageManager

ImageManager implements volumeOwner ImageManager method

func (*VirtualizationTool) KubeletRootDir

func (v *VirtualizationTool) KubeletRootDir() string

KubeletRootDir implements volumeOwner KubeletRootDir method

func (*VirtualizationTool) ListContainers

func (v *VirtualizationTool) ListContainers(filter *types.ContainerFilter) ([]*types.ContainerInfo, error)

ListContainers queries libvirt for domains denoted by container id or pod standbox id or for all domains and after gathering theirs description from metadata and conversion of status from libvirt to kubeapi compatible returns them as a list of kubeapi Containers.

func (*VirtualizationTool) ListVMStats

func (v *VirtualizationTool) ListVMStats(filter *types.VMStatsFilter) ([]types.VMStats, error)

ListVMStats returns statistics (same as VMStats) for all containers matching provided filter (id AND podstandboxid AND labels)

func (*VirtualizationTool) Mounter

func (v *VirtualizationTool) Mounter() utils.Mounter

Mounter implements volumeOwner Mounter method

func (*VirtualizationTool) RawDevices

func (v *VirtualizationTool) RawDevices() []string

RawDevices implements volumeOwner RawDevices method

func (*VirtualizationTool) RemoveContainer

func (v *VirtualizationTool) RemoveContainer(containerID string) error

RemoveContainer tries to gracefully stop domain, then forcibly removes it even if it's still running. It waits up to 5 sec for doing the job by libvirt.

func (*VirtualizationTool) SetClock

func (v *VirtualizationTool) SetClock(clock clockwork.Clock)

SetClock sets the clock to use (used in tests)

func (*VirtualizationTool) SharedFilesystemPath

func (v *VirtualizationTool) SharedFilesystemPath() string

SharedFilesystemPath implements volumeOwner SharedFilesystemPath method

func (*VirtualizationTool) StartContainer

func (v *VirtualizationTool) StartContainer(containerID string) error

StartContainer calls libvirt to start domain, waits up to 10 seconds for DOMAIN_RUNNING state, then updates it's state in metadata store. If there was an error it will be returned to caller after an domain removal attempt. If also it had an error - both of them will be combined.

func (*VirtualizationTool) StopContainer

func (v *VirtualizationTool) StopContainer(containerID string, timeout time.Duration) error

StopContainer calls graceful shutdown of domain and if it was non successful it calls libvirt to destroy that domain. Successful shutdown or destroy of domain is followed by removal of VM info from metadata store. Succeeded removal of metadata is followed by volumes cleanup.

func (*VirtualizationTool) StoragePool

func (v *VirtualizationTool) StoragePool() (virt.StoragePool, error)

StoragePool implements volumeOwner StoragePool method

func (*VirtualizationTool) UpdateCpusetsForEmulatorProcess

func (v *VirtualizationTool) UpdateCpusetsForEmulatorProcess(containerID, cpusets string) (bool, error)

UpdateCpusetsForEmulatorProcess looks through /proc for emulator process to find its cgroup manager for cpusets then uses it to adjust the setting

func (*VirtualizationTool) UpdateCpusetsInContainerDefinition

func (v *VirtualizationTool) UpdateCpusetsInContainerDefinition(containerID, cpusets string) error

UpdateCpusetsInContainerDefinition updates libvirt domain definition for the VM setting the environment variable which is used by vmwrapper to pin to the specified cpuset

func (*VirtualizationTool) VMStats

func (v *VirtualizationTool) VMStats(containerID string, name string) (*types.VMStats, error)

VMStats returns current cpu/memory/disk usage for VM

func (*VirtualizationTool) VolumePoolName

func (v *VirtualizationTool) VolumePoolName() string

VolumePoolName implements volumeOwner VolumePoolName method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL