Skip to content

Commit

Permalink
Do not change the original fd object
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Schlotter <[email protected]>
  • Loading branch information
rikatz and chrischdi authored Jul 3, 2023
1 parent 08aecde commit 405077c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/services/vimmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,18 @@ func (v *VimMachineService) generateOverrideFunc(ctx *context.VIMMachineContext)
vm.Spec.Datastore = vsphereFailureDomain.Spec.Topology.Datastore
}

// Some old cases may still use Networks instead of NetworkConfigs, so we should use the old fields
if len(vsphereFailureDomain.Spec.Topology.NetworkConfigs) == 0 && len(vsphereFailureDomain.Spec.Topology.Networks) > 0 {
vsphereFailureDomain.Spec.Topology.NetworkConfigs = make([]infrav1.FailureDomainNetwork, len(vsphereFailureDomain.Spec.Topology.Networks))
networkConfigs := vsphereFailureDomain.Spec.Topology.NetworkConfigs
// Convert the deprecated vsphereFailureDomain.Spec.Topology to networkConfigs if necessary.
if len(networkConfigs) == 0 && len(vsphereFailureDomain.Spec.Topology.Networks) > 0 {
networkConfigs = make([]infrav1.FailureDomainNetwork, len(vsphereFailureDomain.Spec.Topology.Networks))
for i := range vsphereFailureDomain.Spec.Topology.Networks {
vsphereFailureDomain.Spec.Topology.NetworkConfigs[i].NetworkName = vsphereFailureDomain.Spec.Topology.Networks[i]
networkConfigs[i].NetworkName = vsphereFailureDomain.Spec.Topology.Networks[i]
}

}

if len(vsphereFailureDomain.Spec.Topology.NetworkConfigs) > 0 {
vm.Spec.Network.Devices = overrideNetworkDeviceSpecs(vm.Spec.Network.Devices, vsphereFailureDomain.Spec.Topology.NetworkConfigs)
if len(networkConfigs) > 0 {
vm.Spec.Network.Devices = overrideNetworkDeviceSpecs(vm.Spec.Network.Devices, networkConfigs)
}
}
return overrideWithFailureDomainFunc, true
Expand Down

0 comments on commit 405077c

Please sign in to comment.