Skip to content

Commit

Permalink
Changes to support working with the Windows Machine VM
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhua121 committed Feb 2, 2023
1 parent 2cafa19 commit 7b2c35b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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\"",
},
},
{
Expand Down
10 changes: 6 additions & 4 deletions pkg/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/actuators/machine/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7b2c35b

Please sign in to comment.