From 7b2c35b837a2b266e3b68e5edc8b3445e38ded78 Mon Sep 17 00:00:00 2001 From: Yanhua Li Date: Thu, 26 Jan 2023 15:05:50 -0500 Subject: [PATCH] Changes to support working with the Windows Machine VM --- pkg/actuators/machine/actuator_test.go | 2 ++ pkg/actuators/machine/reconciler.go | 10 ++++++---- pkg/actuators/machine/vm.go | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pkg/actuators/machine/actuator_test.go b/pkg/actuators/machine/actuator_test.go index fb00c926..65455fa9 100644 --- a/pkg/actuators/machine/actuator_test.go +++ b/pkg/actuators/machine/actuator_test.go @@ -164,6 +164,7 @@ func TestMachineEvents(t *testing.T) { pspec.VCPUSockets = 0 pspec.MemorySize = resource.MustParse("1.5Gi") pspec.SystemDiskSize = resource.MustParse("18Gi") + pspec.BootType = "invalid-boottype" return pspec }(), operation: func(actuator *Actuator, machine *machinev1beta1.Machine) { @@ -176,6 +177,7 @@ func TestMachineEvents(t *testing.T) { "The minimum vCPU sockets of the VM is 1", "The minimum memorySize is 2Gi bytes", "The minimum systemDiskSize is 20Gi bytes", + "Invalid bootType, the valid bootType values are: \"\", \"Legacy\", \"UEFI\", \"SecureBoot\"", }, }, { diff --git a/pkg/actuators/machine/reconciler.go b/pkg/actuators/machine/reconciler.go index ce3bbf25..268b0790 100644 --- a/pkg/actuators/machine/reconciler.go +++ b/pkg/actuators/machine/reconciler.go @@ -267,11 +267,13 @@ func (r *Reconciler) setProviderID(vmUUID *string) error { klog.Infof("%s: ProviderID set at machine.spec: %s", r.machine.Name, providerID) } - // update the corresponding node.Spec.ProviderID - var nodeName string - if r.machine.Status.NodeRef != nil { - nodeName = r.machine.Status.NodeRef.Name + if r.machine.Status.NodeRef == nil { + klog.Infof("%s: the Machine node is not ready yet.", r.machine.Name) + return nil } + + // update the corresponding node.Spec.ProviderID + nodeName := r.machine.Status.NodeRef.Name if len(nodeName) == 0 { nodeName = r.machine.Name } diff --git a/pkg/actuators/machine/vm.go b/pkg/actuators/machine/vm.go index a8deece4..c4ab1d4c 100644 --- a/pkg/actuators/machine/vm.go +++ b/pkg/actuators/machine/vm.go @@ -74,6 +74,17 @@ func validateVMConfig(mscp *machineScope) field.ErrorList { errList = append(errList, field.Invalid(fldPath.Child("systemDiskSize"), fmt.Sprintf("%vGib", diskSizeMib/1024), "The minimum systemDiskSize is 20Gi bytes")) } + // verify the bootType configurations + // Type bootType field is optional, and valid values include: "", Legacy, UEFI, SecureBoot + switch mscp.providerSpec.BootType { + case "", machinev1.NutanixLegacyBoot, machinev1.NutanixUEFIBoot, machinev1.NutanixSecureBoot: + // valid bootType + default: + errMsg = fmt.Sprintf("Invalid bootType, the valid bootType values are: \"\", %q, %q, %q.", + machinev1.NutanixLegacyBoot, machinev1.NutanixUEFIBoot, machinev1.NutanixSecureBoot) + errList = append(errList, field.Invalid(fldPath.Child("bootType"), mscp.providerSpec.BootType, errMsg)) + } + return errList } @@ -265,6 +276,15 @@ func createVM(mscp *machineScope, userData []byte) (*nutanixClientV3.VMIntentRes UUID: mscp.providerSpec.Cluster.UUID, } + // Set boot_type if configured in the machine's providerSpec + if mscp.providerSpec.BootType == machinev1.NutanixUEFIBoot { + vmSpec.Resources.BootConfig.BootType = utils.StringPtr("UEFI") + } else if mscp.providerSpec.BootType == machinev1.NutanixSecureBoot { + vmSpec.Resources.BootConfig.BootType = utils.StringPtr("SECURE_BOOT") + } else { + // The vm uses the default "LEGACY" boot type + } + vmInput.Spec = &vmSpec vmInput.Metadata = &vmMetadata vm, err = mscp.nutanixClient.V3.CreateVM(&vmInput)