Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apis/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,34 @@ type VirtualMachineCloneSpec struct {
// +listMapKey=name
// +kubebuilder:validation:MaxItems=29
DataDisks []VSphereDisk `json:"dataDisks,omitempty"`
// nestedHV controls nested hardware-assisted virtualization.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// Check the compatibility with the ESXi version before setting the value.
// +optional
// +kubebuilder:validation:Enum=enabled;disabled
NestedHV string `json:"nestedHV,omitempty"`
// ftEncryptionMode is the encrypted fault tolerance mode.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// Check the compatibility with the ESXi version before setting the value.
// +optional
// +kubebuilder:validation:Enum=ftEncryptionDisabled;ftEncryptionOpportunistic;ftEncryptionRequired
FtEncryptionMode string `json:"ftEncryptionMode,omitempty"`
// migrateEncryption is the encrypted vMotion mode.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// Check the compatibility with the ESXi version before setting the value.
// +optional
// +kubebuilder:validation:Enum=disabled;opportunistic;required
MigrateEncryption string `json:"migrateEncryption,omitempty"`
// cryptoKeyID is the crypto key id.
// +optional
CryptoKeyID string `json:"cryptoKeyID,omitempty"`
// cryptoProfile of the storage encryption policy to use with this
// Virtual Machine
// +optional
CryptoProfile string `json:"cryptoProfile,omitempty"`
}

// VirtualMachineResources is the definition of the VM's cpu and memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ spec:
Defaults to LinkedClone, but fails gracefully to FullClone if the source
of the clone operation has no snapshots.
type: string
cryptoKeyID:
description: cryptoKeyID is the crypto key id.
type: string
cryptoProfile:
description: |-
cryptoProfile of the storage encryption policy to use with this
Virtual Machine
type: string
customVMXKeys:
additionalProperties:
type: string
Expand Down Expand Up @@ -152,6 +160,17 @@ spec:
Folder is the name, inventory path, managed object reference or the managed
object ID of the folder in which the virtual machine is created/located.
type: string
ftEncryptionMode:
description: |-
ftEncryptionMode is the encrypted fault tolerance mode.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- ftEncryptionDisabled
- ftEncryptionOpportunistic
- ftEncryptionRequired
type: string
guestSoftPowerOffTimeout:
description: |-
GuestSoftPowerOffTimeout sets the wait timeout for shutdown in the VM guest.
Expand All @@ -176,6 +195,17 @@ spec:
virtual machine is cloned.
format: int64
type: integer
migrateEncryption:
description: |-
migrateEncryption is the encrypted vMotion mode.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- disabled
- opportunistic
- required
type: string
namingStrategy:
description: NamingStrategy allows configuring the naming strategy
used when calculating the name of the VSphereVM.
Expand All @@ -198,6 +228,16 @@ spec:
so we highly recommend to use a template which leads to a name shorter than 63 characters.
type: string
type: object
nestedHV:
description: |-
nestedHV controls nested hardware-assisted virtualization.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- enabled
- disabled
type: string
network:
description: Network is the network configuration for this machine's
VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ spec:
Defaults to LinkedClone, but fails gracefully to FullClone if the source
of the clone operation has no snapshots.
type: string
cryptoKeyID:
description: cryptoKeyID is the crypto key id.
type: string
cryptoProfile:
description: |-
cryptoProfile of the storage encryption policy to use with this
Virtual Machine
type: string
customVMXKeys:
additionalProperties:
type: string
Expand Down Expand Up @@ -163,6 +171,17 @@ spec:
Folder is the name, inventory path, managed object reference or the managed
object ID of the folder in which the virtual machine is created/located.
type: string
ftEncryptionMode:
description: |-
ftEncryptionMode is the encrypted fault tolerance mode.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- ftEncryptionDisabled
- ftEncryptionOpportunistic
- ftEncryptionRequired
type: string
guestSoftPowerOffTimeout:
description: |-
GuestSoftPowerOffTimeout sets the wait timeout for shutdown in the VM guest.
Expand All @@ -187,6 +206,17 @@ spec:
virtual machine is cloned.
format: int64
type: integer
migrateEncryption:
description: |-
migrateEncryption is the encrypted vMotion mode.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- disabled
- opportunistic
- required
type: string
namingStrategy:
description: NamingStrategy allows configuring the naming
strategy used when calculating the name of the VSphereVM.
Expand All @@ -209,6 +239,16 @@ spec:
so we highly recommend to use a template which leads to a name shorter than 63 characters.
type: string
type: object
nestedHV:
description: |-
nestedHV controls nested hardware-assisted virtualization.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- enabled
- disabled
type: string
network:
description: Network is the network configuration for this
machine's VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ spec:
Defaults to LinkedClone, but fails gracefully to FullClone if the source
of the clone operation has no snapshots.
type: string
cryptoKeyID:
description: cryptoKeyID is the crypto key id.
type: string
cryptoProfile:
description: |-
cryptoProfile of the storage encryption policy to use with this
Virtual Machine
type: string
customVMXKeys:
additionalProperties:
type: string
Expand Down Expand Up @@ -179,6 +187,17 @@ spec:
Folder is the name, inventory path, managed object reference or the managed
object ID of the folder in which the virtual machine is created/located.
type: string
ftEncryptionMode:
description: |-
ftEncryptionMode is the encrypted fault tolerance mode.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- ftEncryptionDisabled
- ftEncryptionOpportunistic
- ftEncryptionRequired
type: string
guestSoftPowerOffTimeout:
description: |-
GuestSoftPowerOffTimeout sets the wait timeout for shutdown in the VM guest.
Expand All @@ -203,6 +222,27 @@ spec:
virtual machine is cloned.
format: int64
type: integer
migrateEncryption:
description: |-
migrateEncryption is the encrypted vMotion mode.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- disabled
- opportunistic
- required
type: string
nestedHV:
description: |-
nestedHV controls nested hardware-assisted virtualization.
Defaults to the eponymous property value in the template from which the
virtual machine is cloned.
Check the compatibility with the ESXi version before setting the value.
enum:
- enabled
- disabled
type: string
network:
description: Network is the network configuration for this machine's
VM.
Expand Down
45 changes: 45 additions & 0 deletions pkg/services/govmomi/vcenter/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/vmware/govmomi/crypto"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/pbm"
pbmTypes "github.com/vmware/govmomi/pbm/types"
Expand Down Expand Up @@ -365,6 +366,50 @@ func Clone(ctx context.Context, vmCtx *capvcontext.VMContext, bootstrapData []by
spec.Location.Disk = getDiskLocators(disks, *datastoreRef, isLinkedClone)
spec.Location.Datastore = datastoreRef

switch vmCtx.VSphereVM.Spec.NestedHV {
case "enabled":
spec.Config.NestedHVEnabled = ptr.To(true)
case "disabled":
spec.Config.NestedHVEnabled = ptr.To(false)
}
if vmCtx.VSphereVM.Spec.FtEncryptionMode != "" {
spec.Config.FtEncryptionMode = vmCtx.VSphereVM.Spec.FtEncryptionMode
}
if vmCtx.VSphereVM.Spec.MigrateEncryption != "" {
spec.Config.FtEncryptionMode = vmCtx.VSphereVM.Spec.MigrateEncryption
}
if vmCtx.VSphereVM.Spec.CryptoProfile != "" {
pbmClient, err := pbm.NewClient(ctx, vmCtx.Session.Client.Client)
if err != nil {
return errors.Wrapf(err, "unable to create pbm client for %q", vmCtx)
}

spbmStoragePolicyID, err := pbmClient.ProfileIDByName(ctx, vmCtx.VSphereVM.Spec.CryptoProfile)
if err != nil {
return errors.Wrapf(err, "unable to get storageProfileID from name %s for %q", vmCtx.VSphereVM.Spec.CryptoProfile, vmCtx)
}
profileSpec := types.VirtualMachineDefinedProfileSpec{
ProfileId: spbmStoragePolicyID,
}
spec.Config.VmProfile = append(spec.Config.VmProfile, &profileSpec)
}
if vmCtx.VSphereVM.Spec.CryptoKeyID != "" {
kmip, err := crypto.GetManagerKmip(vmCtx.Session.Client.Client)
if err != nil {
return errors.Wrapf(err, "unable to create kmip client for %q", vmCtx)
}
keyID, err := kmip.GenerateKey(ctx, vmCtx.VSphereVM.Spec.CryptoKeyID)
if err != nil {
return errors.Wrapf(err, "unable to generate a key for %q", vmCtx)
}
cryptoSpec := types.CryptoSpecEncrypt{
CryptoKeyId: types.CryptoKeyId{
KeyId: keyID,
},
}
spec.Config.Crypto = &cryptoSpec
}

log.Info(fmt.Sprintf("Cloning Machine with clone mode %s", vmCtx.VSphereVM.Status.CloneMode))
task, err := tpl.Clone(ctx, folder, vmCtx.VSphereVM.Name, spec)
if err != nil {
Expand Down