Skip to content

Commit

Permalink
Changes to support new optional fields of NutanixMachineProviderConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhua121 committed Feb 22, 2023
1 parent 350b0e2 commit 75323d0
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 61 deletions.
4 changes: 4 additions & 0 deletions pkg/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func TestMachineEvents(t *testing.T) {
pspec.VCPUSockets = 0
pspec.MemorySize = resource.MustParse("1.5Gi")
pspec.SystemDiskSize = resource.MustParse("18Gi")
pspec.BootType = "invalid-boottype"
pspec.Project.Type = "uuid"
return pspec
}(),
operation: func(actuator *Actuator, machine *machinev1beta1.Machine) {
Expand All @@ -176,6 +178,8 @@ 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\"",
"Missing project uuid",
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/actuators/machine/machine_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type machineScope struct {
machineToBePatched runtimeclient.Patch
providerSpec *machinev1.NutanixMachineProviderConfig
providerStatus *machinev1.NutanixMachineProviderStatus
// For Machine vm create/update use, take a copy of the providerSpec that we can mutate.
// This must never be written back to the Machine itself.
providerSpecValidated *machinev1.NutanixMachineProviderConfig
}

func newMachineScope(params machineScopeParams) (*machineScope, error) {
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: 13 additions & 7 deletions pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,20 @@ const (
NutanixCategoryValue = "owned"
)

// Add the category for installer clueanup the Machine VM at cluster torn-down time
// if the category exists in PC.
func addCategory(mscp *machineScope, vmMetadata *nutanixClientV3.Metadata) error {
// addCategories adds the category for installer clueanup the Machine VM
// at cluster torn-down time if the category exists in PC.
// Add the addtional categories to the Machine VM if configured
func addCategories(mscp *machineScope, vmMetadata *nutanixClientV3.Metadata) error {
var err error
if vmMetadata.Categories == nil {
vmMetadata.Categories = make(map[string]string, len(mscp.providerSpec.Categories)+1)
}

// The addtional categories are already verified
for _, category := range mscp.providerSpec.Categories {
vmMetadata.Categories[category.Key] = category.Value
}

clusterID, ok := getClusterID(mscp.machine)
if !ok || clusterID == "" {
err = fmt.Errorf("%s: failed to get the clusterID", mscp.machine.Name)
Expand All @@ -113,10 +123,6 @@ func addCategory(mscp *machineScope, vmMetadata *nutanixClientV3.Metadata) error
return err
}

// Add the category to the vm metadata
if vmMetadata.Categories == nil {
vmMetadata.Categories = make(map[string]string, 1)
}
vmMetadata.Categories[categoryKey] = NutanixCategoryValue

return nil
Expand Down
Loading

0 comments on commit 75323d0

Please sign in to comment.