Skip to content

Commit 2115e43

Browse files
sadasunawazkh
authored andcommitted
Update handling Capabilities that have a float value
In the case of "Standard_M8-4ms", their memory capability is specified as a float with value 218.75 GiB. Added a fix to handle capabilitites that have a float value instead of erroring from reconcile because of inability to parse float values.
1 parent 3d6f78f commit 2115e43

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

azure/services/resourceskus/sku.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package resourceskus
1818

1919
import (
20+
"math"
2021
"strconv"
2122
"strings"
2223

@@ -112,10 +113,11 @@ func (s SKU) HasCapabilityWithCapacity(name string, value int64) (bool, error) {
112113
continue
113114
}
114115

115-
intVal, err := strconv.ParseInt(*capability.Value, 10, 64)
116+
floatVal, err := strconv.ParseFloat(*capability.Value, 64)
116117
if err != nil {
117-
return false, errors.Wrapf(err, "failed to parse string '%s' as int64", *capability.Value)
118+
return false, errors.Wrapf(err, "failed to parse string '%s' as float", *capability.Value)
118119
}
120+
intVal := int64(math.Round(floatVal))
119121

120122
if intVal >= value {
121123
return true, nil

azure/services/scalesets/scalesets_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ func getResultVMSS() armcompute.VirtualMachineScaleSet {
100100
return resultVMSS
101101
}
102102

103+
func getMemFloatResultVMSS() armcompute.VirtualMachineScaleSet {
104+
resultVMSS := newDefaultVMSS("VM_SIZE_MEM_FLOAT")
105+
resultVMSS.ID = ptr.To(defaultVMSSID)
106+
107+
return resultVMSS
108+
}
109+
103110
func TestReconcileVMSS(t *testing.T) {
104111
defaultInstances := newDefaultInstances()
105112
resultVMSS := newDefaultVMSS("VM_SIZE")
@@ -213,6 +220,29 @@ func TestReconcileVMSS(t *testing.T) {
213220
s.ScaleSetSpec(gomockinternal.AContext()).Return(&spec).AnyTimes()
214221
},
215222
},
223+
{
224+
name: "validate spec success: Memory is float",
225+
expectedError: "",
226+
expect: func(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder, m *mock_scalesets.MockClientMockRecorder) {
227+
s.DefaultedAzureServiceReconcileTimeout().Return(reconciler.DefaultAzureServiceReconcileTimeout)
228+
spec := newVMSSSpecWithSKU(resourceskus.MemoryGB, "217.13")
229+
spec.Size = "VM_SIZE_MEM_FLOAT"
230+
spec.Capacity = 2
231+
spec.SSHKeyData = sshKeyData
232+
memFloatVMSS := newDefaultVMSS("VM_SIZE_MEM_FLOAT")
233+
memFloatVMSS.ID = ptr.To(defaultVMSSID)
234+
235+
s.ScaleSetSpec(gomockinternal.AContext()).Return(&spec).AnyTimes()
236+
m.Get(gomockinternal.AContext(), &spec).Return(memFloatVMSS, nil)
237+
m.ListInstances(gomockinternal.AContext(), spec.ResourceGroup, spec.Name).Return(defaultInstances, nil)
238+
fetchedMemFloatVMSS := converters.SDKToVMSS(getMemFloatResultVMSS(), defaultInstances)
239+
s.ReconcileReplicas(gomockinternal.AContext(), &fetchedMemFloatVMSS).Return(nil).Times(2)
240+
s.SetProviderID(azureutil.ProviderIDPrefix + defaultVMSSID).Times(2)
241+
s.SetVMSSState(&fetchedMemFloatVMSS).Times(2)
242+
r.CreateOrUpdateResource(gomockinternal.AContext(), &spec, serviceName).Return(getMemFloatResultVMSS(), nil)
243+
s.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, nil)
244+
},
245+
},
216246
{
217247
name: "validate spec failure: failed to get SKU",
218248
expectedError: "failed to get SKU INVALID_VM_SIZE in compute api: reconcile error that cannot be recovered occurred: resource sku with name 'INVALID_VM_SIZE' and category 'virtualMachines' not found in location 'test-location'. Object will not be requeued",
@@ -634,6 +664,34 @@ func getFakeSkus() []armcompute.ResourceSKU {
634664
},
635665
},
636666
},
667+
{
668+
Name: ptr.To("VM_SIZE_MEM_FLOAT"),
669+
ResourceType: ptr.To(string(resourceskus.VirtualMachines)),
670+
Kind: ptr.To(string(resourceskus.VirtualMachines)),
671+
Locations: []*string{
672+
ptr.To("test-location"),
673+
},
674+
LocationInfo: []*armcompute.ResourceSKULocationInfo{
675+
{
676+
Location: ptr.To("test-location"),
677+
Zones: []*string{ptr.To("1"), ptr.To("3")},
678+
},
679+
},
680+
Capabilities: []*armcompute.ResourceSKUCapabilities{
681+
{
682+
Name: ptr.To(resourceskus.AcceleratedNetworking),
683+
Value: ptr.To(string(resourceskus.CapabilityUnsupported)),
684+
},
685+
{
686+
Name: ptr.To(resourceskus.VCPUs),
687+
Value: ptr.To("4"),
688+
},
689+
{
690+
Name: ptr.To(resourceskus.MemoryGB),
691+
Value: ptr.To("217.13"),
692+
},
693+
},
694+
},
637695
}
638696
}
639697

@@ -729,6 +787,15 @@ func newWindowsVMSSSpec() ScaleSetSpec {
729787
vmss.OSDisk.OSType = azure.WindowsOS
730788
return vmss
731789
}
790+
func newVMSSSpecWithSKU(capName string, capValue string) ScaleSetSpec {
791+
vmsSpec := newDefaultVMSSSpec()
792+
inputCapability := armcompute.ResourceSKUCapabilities{
793+
Name: ptr.To(capName),
794+
Value: ptr.To(capValue),
795+
}
796+
vmsSpec.SKU.Capabilities = append(vmsSpec.SKU.Capabilities, &inputCapability)
797+
return vmsSpec
798+
}
732799

733800
func newDefaultExistingVMSS() armcompute.VirtualMachineScaleSet {
734801
vmss := newDefaultVMSS("VM_SIZE")

0 commit comments

Comments
 (0)