vmopv1

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrInvalidHostName is returned by ValidateHostAndDomainName if
	// either the provided host name does not adhere to RFC-1123.
	ErrInvalidHostName = "host name must adhere to RFC-1123"

	// ErrInvalidDomainName is returned by ValidateHostAndDomainName if
	// either the provided domain name does not adhere to RFC-1123.
	ErrInvalidDomainName = "domain name must adhere to RFC-1123"

	// ErrInvalidHostNameIPWithDomainName is returned by
	// ValidateHostAndDomainName if the provided host name is an IP4 or IP6
	// address and the provided domain name is non-empty.
	ErrInvalidHostNameIPWithDomainName = "host name may not be IP address when domain name is non-empty" //nolint:gosec

	// ErrInvalidHostNameWindows is returned by ValidateHostAndDomainName if the
	// provided host name exceeds 15 characters and the guest is Windows.
	ErrInvalidHostNameWindows = "host name may not exceed 15 characters for Windows"

	// ErrInvalidHostAndDomainName is returned by ValidateHostAndDomainName if
	// the provided host name and domain name, combined, exceed 255 characters.
	ErrInvalidHostAndDomainName = "host name and domain name combined exceed 255 characters"
)
View Source
const (
	// LastResizedAnnotationKey denotes the VM Class that the VM was last resized from.
	LastResizedAnnotationKey = vmopv1.GroupName + "/last-resized-vm-class"

	// LastResizedAnnotationKey denotes the
	// VirtualMachineClassInstance that the VM was last resized from.
	LastResizedInstanceAnnotationKey = vmopv1.GroupName + "/last-resized-vm-class-instance"
)
View Source
const KubernetesNodeLabelKey = "cluster.x-k8s.io/cluster-name"

KubernetesNodeLabelKey is the name of the label key used to identify a Kubernetes cluster node.

View Source
const (
	MicrosoftWSFCControllerSharingMode = vmopv1.VirtualControllerSharingModePhysical
)

Variables

View Source
var ErrImageNotSynced = errors.New("image not synced")

ErrImageNotSynced is returned from GetImageInfo when the underlying content library item is not synced.

Functions

func CnsRegisterVolumeToVirtualMachineMapper added in v1.10.0

func CnsRegisterVolumeToVirtualMachineMapper(
	ctx context.Context,
	k8sClient client.Client) handler.MapFunc

CnsRegisterVolumeToVirtualMachineMapper returns a mapper function used to enqueue reconcile requests for VMs in response to an event on the CnsRegisterVolume resource.

func ConvertPowerState added in v1.10.0

func ConvertPowerState(logger logr.Logger,
	powerState vimtypes.VirtualMachinePowerState) vmopv1.VirtualMachinePowerState

ConvertPowerState converts a govomomi type power state to a VM Operator type power state.

func DefaultControllerSharingMode added in v1.10.0

func DefaultControllerSharingMode(
	vol vmopv1.VirtualMachineVolume,
) vmopv1.VirtualControllerSharingMode

DefaultControllerSharingMode returns the default controller sharing mode for the specified volume.

func DetermineHardwareVersion

DetermineHardwareVersion returns the hardware version recommended for the provided VirtualMachine based on its own spec.minHardwareVersion, as well as the hardware in the provided ConfigSpec and requirements of the given VirtualMachineImage.

func EncryptionClassToVirtualMachineMapper

func EncryptionClassToVirtualMachineMapper(
	ctx context.Context,
	k8sClient client.Client) handler.MapFunc

EncryptionClassToVirtualMachineMapper returns a mapper function used to enqueue reconcile requests for VMs in response to an event on the EncryptionClass resource.

func FilterInstanceStorageVolumes

func FilterInstanceStorageVolumes(vm *vmopv1.VirtualMachine) []vmopv1.VirtualMachineVolume

FilterInstanceStorageVolumes returns instance storage volumes present in VM spec.

func FindByTargetID added in v1.10.0

func FindByTargetID[T HasTargetID](
	controllerType vmopv1.VirtualControllerType,
	controllerBusNumber, unitNumber int32,
	hasTargetIDs ...T) *T

FindByTargetID returns the object with the matching target ID.

func GenerateControllerID added in v1.10.0

func GenerateControllerID(
	controller any,
) pkgutil.ControllerID

GenerateControllerID generates a controller ID from a controller specification. Returns a ControllerID with BusNumber set to negative one if the controller type is not supported.

func GetContextWithWorkloadDomainIsolation

func GetContextWithWorkloadDomainIsolation(
	ctx context.Context,
	vm vmopv1.VirtualMachine) context.Context

GetContextWithWorkloadDomainIsolation gets a new context with the WorkloadDomainIsolation capability set to a value based on the provided VM.

func GetControllerSharingMode added in v1.10.0

func GetControllerSharingMode(
	controller any,
) vmopv1.VirtualControllerSharingMode

GetControllerSharingMode returns the sharing mode for a controller. Returns the sharing mode from the controller if supported, or None otherwise.

func GetImage

func GetImage(
	ctx context.Context,
	k8sClient ctrlclient.Client,
	imgRef vmopv1.VirtualMachineImageRef,
	namespace string) (vmopv1.VirtualMachineImage, error)

GetImage returns the VirtualMachineImage or ClusterVirtualMachineImage for the provided image reference.

func GetLastResizedAnnotation

func GetLastResizedAnnotation(vm vmopv1.VirtualMachine) (string, string, int64, bool)

GetLastResizedAnnotation returns the VM Class Name, UID, Generation, and true from the last resize annotation if present. Otherwise returns false.

func GetLastResizedInstanceAnnotation added in v1.10.0

func GetLastResizedInstanceAnnotation(vm vmopv1.VirtualMachine) (string, string, int64, bool)

GetLastResizedInstanceAnnotation returns the VM Class Instance's Name, UID, Generation, and true from the last resize annotation if present. Otherwise returns false.

func GetStorageURIsForLibraryItemDisks

func GetStorageURIsForLibraryItemDisks(
	item imgregv1a1.ContentLibraryItem) ([]string, error)

GetStorageURIsForLibraryItemDisks returns the paths to the VMDK files from the provided library item.

func GetTargetID added in v1.10.0

func GetTargetID(obj HasTargetID) string

GetTargetID returns the object's target ID, i.e.:

CONTROLLER_TYPE:CONTROLLER_BUS_NUMBER:UNIT_NUMBER

If the controller type is empty, controller bus number is unset, or the unit number is unset, this function returns an empty string.

func GroupToMembersMapperFn added in v1.10.0

func GroupToMembersMapperFn(
	_ context.Context,
	client ctrlclient.Client,
	memberKind string) handler.MapFunc

GroupToMembersMapperFn returns a mapper function that can be used to queue reconcile requests for all the currently linked group members with given kind (VirtualMachine/VirtualMachineGroup) in response to VirtualMachineGroup watch.

func HasPVC

func HasPVC(vm vmopv1.VirtualMachine) bool

HasPVC returns true if any of spec.volumes contains a PVC.

func ImageRefsEqual

func ImageRefsEqual(ref1, ref2 *vmopv1.VirtualMachineImageRef) bool

ImageRefsEqual returns true if the two image refs match.

func IsClasslessVM

func IsClasslessVM(vm vmopv1.VirtualMachine) bool

IsClasslessVM returns true if the provided VM was not deployed from a VM class.

func IsFSRSupported added in v1.10.0

func IsFSRSupported(vm vmopv1.VirtualMachine) bool

IsFSRSupported checks if Fast-Suspend-Resume is supported for the VM. A VM does not support FSR if, - One of its physical shared SCSI controllers has an attached disk.

func IsImageOVF

func IsImageOVF(img vmopv1.VirtualMachineImage) error

func IsImageProviderReady

func IsImageProviderReady(img vmopv1.VirtualMachineImage) error

func IsImageReady

func IsImageReady(img vmopv1.VirtualMachineImage) error

func IsImagelessVM

func IsImagelessVM(vm vmopv1.VirtualMachine) bool

IsImagelessVM returns true if the provided VM was not deployed from a VM image.

func IsInstanceStoragePresent

func IsInstanceStoragePresent(vm *vmopv1.VirtualMachine) bool

IsInstanceStoragePresent checks if VM Spec has instance volumes added to its Volumes list.

func IsInsufficientQuota

func IsInsufficientQuota(err error) bool

func IsKubernetesNode

func IsKubernetesNode(vm vmopv1.VirtualMachine) bool

IsKubernetesNode returns true if the provided VM has the label cluster.x-k8s.io/cluster-name.

func IsLibraryItemSynced

func IsLibraryItemSynced(item imgregv1a1.ContentLibraryItem) error

func IsObjectUpgraded added in v1.10.0

func IsObjectUpgraded(
	ctx context.Context,
	obj ctrlclient.Object) error

IsObjectUpgraded returns nil if below conditions are all met by checking the upgrade annotations:

  1. The object's build version has been upgraded to the current build version.
  2. The object's schema version has been upgraded to the current schema version.
  3. The object's feature version has been upgraded to the current feature version.

func MemberToGroupMapperFn added in v1.10.0

func MemberToGroupMapperFn(_ context.Context) handler.MapFunc

MemberToGroupMapperFn returns a MapFunc that reconciles a VirtualMachineGroup when a linked member (VM or VMGroup) changes. This ensures the group's status is updated in time to reflect the current member latest state (e.g. ready condition for VMGroup kind members or power state for VM kind members).

func MustSetLastResizedAnnotation

func MustSetLastResizedAnnotation(
	vm *vmopv1.VirtualMachine,
	vmClass vmopv1.VirtualMachineClass)

MustSetLastResizedAnnotation sets the resize annotation to match the given class. Panic if fails.

func NextAvailableUnitNumber added in v1.10.0

func NextAvailableUnitNumber(
	controller ControllerSpec,
	occupiedSlots sets.Set[int32],
) int32

NextAvailableUnitNumber returns the first available unit number for the specified controller. The occupiedSlots parameter should contain all unit numbers that are already in use on the specified bus. Returns the first available unit number, or negative one if no slots are available.

func OverwriteAlwaysResizeConfigSpec

OverwriteAlwaysResizeConfigSpec applies any set fields in the VM Spec or changes required from the current VM state to the ConfigSpec. These are fields that change without the VM Class.

func OverwriteResizeConfigSpec

OverwriteResizeConfigSpec applies any set fields in the VM Spec or changes required from the current VM state to the ConfigSpec. These are fields that we can change without the VM Class.

func PVCToVirtualMachineVolumeClaimNameMapper added in v1.10.0

func PVCToVirtualMachineVolumeClaimNameMapper(
	_ context.Context,
	k8sClient client.Client) handler.TypedMapFunc[*corev1.PersistentVolumeClaim, reconcile.Request]

PVCToVirtualMachineVolumeClaimNameMapper returns a mapper function used to enqueue reconcile requests for VirtualMachines that reference the Spec.Volumes.

func PolicyEvalToVMToVMGroupMapperFunc added in v1.10.0

func PolicyEvalToVMToVMGroupMapperFunc(
	_ context.Context,
	client ctrlclient.Client,
) handler.MapFunc

PolicyEvalToVMToVMGroupMapperFunc returns a MapFunc that reconciles a VirtualMachineGroup when the PolicyEval for a VM that linked to the group but not yet placed changes. This is needed so that during VM Group placement the policy is ready, group placement is done.

func ReconcileInstanceStoragePVCs added in v1.10.0

func ReconcileInstanceStoragePVCs(
	ctx *pkgctx.VolumeContext,
	k8sClient client.Client,
	reader client.Reader,
	recorder record.Recorder,
) (bool, error)

ReconcileInstanceStoragePVCs reconciles instance storage PVCs for a VM. This is the core reconciliation logic shared between volume controllers. Returns (ready bool, error):

  • (true, nil): All instance storage PVCs are bound
  • (false, nil): PVCs exist but not yet bound (caller should requeue)
  • (false, err): Error occurred

func RemoveStaleGroupOwnerRef added in v1.10.0

func RemoveStaleGroupOwnerRef(newObj, oldObj VirtualMachineOrGroup) bool

RemoveStaleGroupOwnerRef removes an object's owner reference to the previous group if the object's group name is deleted or changed to a different group. Returns true if any owner references were modified, false otherwise.

func ResizeNeeded

func ResizeNeeded(
	vm vmopv1.VirtualMachine,
	vmClass vmopv1.VirtualMachineClass) bool

func ResolveImageName

func ResolveImageName(
	ctx context.Context,
	k8sClient client.Client,
	namespace, imgName string) (client.Object, error)

ResolveImageName resolves the provided name of a VM image either to a VirtualMachineImage resource or ClusterVirtualMachineImage resource.

func RetrieveVMGroupMembers added in v1.10.0

func RetrieveVMGroupMembers(ctx context.Context, c ctrlclient.Client,
	vmGroupKey ctrlclient.ObjectKey, visitedGroups *sets.Set[string]) (sets.Set[string], error)

RetrieveVMGroupMembers retrieves all the group linked VMs under a VM group recursively. An error is return if a loop is detected among nested groups or a group has duplicated members.

func SetLastResizedAnnotation

func SetLastResizedAnnotation(
	vm *vmopv1.VirtualMachine,
	vmClass vmopv1.VirtualMachineClass) error

SetLastResizedAnnotation sets the resize annotation to match the given class.

func SetLastResizedAnnotationClassInstanceName added in v1.10.0

func SetLastResizedAnnotationClassInstanceName(
	vm *vmopv1.VirtualMachine,
	classInstanceName string) error

SetLastResizedAnnotationClassInstanceName sets the resize VM class instance annotation to the name of the VM class instance. This is only called from the VM mutation webhook to record the prior class instance name of a VM that does not already have the annotation (so that ResizeNeeded() will return true). Note instance name may be empty if the VM was classless.

func SetLastResizedAnnotationClassName

func SetLastResizedAnnotationClassName(
	vm *vmopv1.VirtualMachine,
	className string) error

SetLastResizedAnnotationClassName sets the resize annotation to just of the class name. This is called from the VM mutation wehbook to record the prior class name of a VM that does not already have the annotation (so that ResizeNeeded() will return true). Note className may be empty if the VM was classless.

func ShouldRequeueForInstanceStoragePVCs added in v1.10.0

func ShouldRequeueForInstanceStoragePVCs(
	ctx context.Context, vm *vmopv1.VirtualMachine) ctrl.Result

ShouldRequeueForInstanceStoragePVCs checks if a reconciliation should be requeued while waiting for instance storage PVCs to be bound. Returns a ctrl.Result with RequeueAfter set if requeue is needed, or an empty ctrl.Result otherwise.

func SnapshotToVMMapperFn added in v1.10.0

func SnapshotToVMMapperFn(
	ctx context.Context,
	logger logr.Logger,
) func(_ context.Context, o client.Object) []reconcile.Request

SnapshotToVMMapperFn returns a mapper function that can be used to queue reconcile requests for the VirtualMachines in response to an event on the VirtualMachineSnapshot resource.

func SyncStorageUsageForNamespace

func SyncStorageUsageForNamespace(
	ctx context.Context,
	namespace, storageClass string)

SyncStorageUsageForNamespace updates the StoragePolicyUsage resource for the given namespace and storage class with the reported usage information for VMs in that namespace that use the specified storage class.

func UpdateGroupLinkedCondition added in v1.10.0

func UpdateGroupLinkedCondition(
	ctx context.Context,
	member VirtualMachineOrGroup,
	c ctrlclient.Client) error

UpdateGroupLinkedCondition updates the group linked condition for a member. If the member has no group name, the group linked condition is deleted.

func ValidateHostAndDomainName

func ValidateHostAndDomainName(vm vmopv1.VirtualMachine) *field.Error

ValidateHostAndDomainName returns nil if the provided host and domain names are valid; otherwise an error is returned. If the isWindows parameter is true, then the host name may not exceed 15 characters.

func VirtualMachineImageCacheToItemMapper added in v1.10.0

func VirtualMachineImageCacheToItemMapper(
	ctx context.Context,
	logger logr.Logger,
	k8sClient ctrlclient.Client,
	groupVersion schema.GroupVersion,
	kind string) handler.MapFunc

VirtualMachineImageCacheToItemMapper returns a mapper function used to enqueue reconcile requests for resources in response to an event on a VirtualMachineImageCache resource.

Types

type ControllerSpec added in v1.10.0

type ControllerSpec interface {
	// MaxSlots returns the maximum number of slots per controller type.
	MaxSlots() int32

	// MaxCount returns the maximum number of controllers per VM.
	MaxCount() int32

	// ReservedUnitNumber returns any reserved unit numbers or negative one
	// if no reserved unit numbers are present.
	ReservedUnitNumber() int32
}

ControllerSpec is an interface describing a controller specification.

func CreateNewController added in v1.10.0

func CreateNewController(
	controllerType vmopv1.VirtualControllerType,
	busNumber int32,
	sharingMode vmopv1.VirtualControllerSharingMode,
) ControllerSpec

CreateNewController creates a new controller with the specified controller type, bus number, and sharing mode. For SCSI controller type, the type is ParaVirtualSCSI by default.

type ControllerSpecs added in v1.10.0

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

ControllerSpecs is a collection of controller specifications.

func NewControllerSpecs added in v1.10.0

func NewControllerSpecs(
	vm vmopv1.VirtualMachine,
) ControllerSpecs

NewControllerSpecs creates a new ControllerSpecs from the specified VM's spec.hardware.controllers.

func (ControllerSpecs) CountControllers added in v1.10.0

func (c ControllerSpecs) CountControllers(
	controllerType vmopv1.VirtualControllerType,
) int

CountControllers returns the number of controllers for the specified controller type.

func (ControllerSpecs) Get added in v1.10.0

func (c ControllerSpecs) Get(
	controllerType vmopv1.VirtualControllerType,
	busNumber int32,
) (ControllerSpec, bool)

Get returns the controller specification for the specified controller type and bus number. Returns (nil, false) if not found.

func (ControllerSpecs) Set added in v1.10.0

func (c ControllerSpecs) Set(
	controllerType vmopv1.VirtualControllerType,
	busNumber int32,
	controller ControllerSpec,
)

Set sets the controller specification for the specified controller type and bus number.

type ErrImageNotFound

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

ErrImageNotFound is returned from ResolveImageName if the image cannot be found at the namespace or cluster scopes. This type will return true when provided to the apierrors.IsNotFound function.

func (ErrImageNotFound) Error

func (e ErrImageNotFound) Error() string

func (ErrImageNotFound) Status

func (e ErrImageNotFound) Status() metav1.Status

type FeatureVersion added in v1.10.0

type FeatureVersion uint16

FeatureVersion is a bitmask of the activated features and is used to track which features were activated when an object's data was upgraded.

const (
	// FeatureVersionBase is the basic feature version.
	FeatureVersionBase FeatureVersion = 1 << iota // 1

	// FeatureVersionVMSharedDisks refers to the VMSharedDisks capability.
	FeatureVersionVMSharedDisks // 2

	// FeatureVersionAllDisksArePVCs refers to the AllDisksArePVCs capability.
	FeatureVersionAllDisksArePVCs // 4
)
const (
	// FeatureVersionEmpty is the empty feature version.
	FeatureVersionEmpty FeatureVersion = 0

	// FeatureVersionAll is all valid feature bits OR'd together.
	FeatureVersionAll = FeatureVersionBase |
		FeatureVersionVMSharedDisks |
		FeatureVersionAllDisksArePVCs // 7
)

func ActivatedFeatureVersion added in v1.10.0

func ActivatedFeatureVersion(ctx context.Context) FeatureVersion

ActivatedFeatureVersion returns the feature version when considering all possible, activated features and capabilities.

func FeatureVersions added in v1.10.0

func FeatureVersions() []FeatureVersion

FeatureVersions returns all possible, valid FeatureVersion elements.

func ParseFeatureVersion added in v1.10.0

func ParseFeatureVersion(s string) FeatureVersion

ParseFeatureVersion parses the provided string and returns the FeatureVersion. If the string is empty or invalid, then FeatureVersionEmpty is returned.

func (FeatureVersion) Has added in v1.10.0

Has returns true if the given feature version includes the specified feature version.

func (FeatureVersion) IsOrSuperset added in v1.10.0

func (a FeatureVersion) IsOrSuperset(b FeatureVersion) bool

IsOrSuperset returns true if the given feature version is equal to the specified feature version or if the specified feature version's members all exist in the given version.

func (FeatureVersion) IsValid added in v1.10.0

func (a FeatureVersion) IsValid() bool

IsValid returns true if the feature version contains only valid feature bits and is non-zero.

func (*FeatureVersion) Set added in v1.10.0

func (a *FeatureVersion) Set(b FeatureVersion)

Set adds the specified feature to the feature version.

func (FeatureVersion) String added in v1.10.0

func (a FeatureVersion) String() string

String returns the string-ified version of the feature version.

type HasTargetID added in v1.10.0

type HasTargetID interface {
	GetControllerType() vmopv1.VirtualControllerType
	GetControllerBusNumber() *int32
	GetUnitNumber() *int32
}

HasTargetID is a device connected to a controller and thus has a target ID.

type ImageDiskInfo

type ImageDiskInfo struct {
	ItemID             string
	ItemContentVersion string
	DiskURIs           []string
}

ImageDiskInfo contains information about a VM image that is used to create a VM.

func GetImageDiskInfo

func GetImageDiskInfo(
	ctx context.Context,
	k8sClient ctrlclient.Client,
	imgRef vmopv1.VirtualMachineImageRef,
	namespace string) (ImageDiskInfo, error)

GetImageDiskInfo returns the information about a VM image's disks, used to create a VM. This method returns an error for images that are not OVFs.

type NotUpgradedErr added in v1.10.0

type NotUpgradedErr struct {
	Type   string
	Object string
	Target string
}

NotUpgradedErr is returned by IsVirtualMachineSchemaUpgraded when an object has not yet been upgraded to the target build, schema, or feature version.

func (NotUpgradedErr) Error added in v1.10.0

func (e NotUpgradedErr) Error() string

func (NotUpgradedErr) String added in v1.10.0

func (e NotUpgradedErr) String() string

type TargetID added in v1.10.0

type TargetID struct {
	ControllerType vmopv1.VirtualControllerType
	ControllerBus  int32
	UnitNumber     int32
}

TargetID is the controller:bus:slot target ID at which a device is located.

func (TargetID) String added in v1.10.0

func (t TargetID) String() string

String returns the stringified target ID, i.e.:

CONTROLLER_TYPE:CONTROLLER_BUS_NUMBER:UNIT_NUMBER.

type VirtualMachineOrGroup added in v1.10.0

type VirtualMachineOrGroup interface {
	metav1.Object
	runtime.Object
	DeepCopyObject() runtime.Object
	GetMemberKind() string
	GetGroupName() string
	SetGroupName(value string)
	GetPowerState() vmopv1.VirtualMachinePowerState
	SetPowerState(value vmopv1.VirtualMachinePowerState)
	GetConditions() []metav1.Condition
	SetConditions([]metav1.Condition)
}

VirtualMachineOrGroup is an internal interface that represents a VirtualMachine or VirtualMachineGroup object.

Jump to

Keyboard shortcuts

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