Skip to content

Commit 00dc84d

Browse files
authored
Merge pull request #5493 from k8s-infra-cherrypick-robot/cherry-pick-5481-to-release-1.18
[release-1.18] Update handling Capabilities that have a float value
2 parents 98b455a + 8283a6b commit 00dc84d

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
@@ -101,6 +101,13 @@ func getResultVMSS() armcompute.VirtualMachineScaleSet {
101101
return resultVMSS
102102
}
103103

104+
func getMemFloatResultVMSS() armcompute.VirtualMachineScaleSet {
105+
resultVMSS := newDefaultVMSS("VM_SIZE_MEM_FLOAT")
106+
resultVMSS.ID = ptr.To(defaultVMSSID)
107+
108+
return resultVMSS
109+
}
110+
104111
func TestReconcileVMSS(t *testing.T) {
105112
defaultInstances := newDefaultInstances()
106113
resultVMSS := newDefaultVMSS("VM_SIZE")
@@ -214,6 +221,29 @@ func TestReconcileVMSS(t *testing.T) {
214221
s.ScaleSetSpec(gomockinternal.AContext()).Return(&spec).AnyTimes()
215222
},
216223
},
224+
{
225+
name: "validate spec success: Memory is float",
226+
expectedError: "",
227+
expect: func(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder, m *mock_scalesets.MockClientMockRecorder) {
228+
s.DefaultedAzureServiceReconcileTimeout().Return(reconciler.DefaultAzureServiceReconcileTimeout)
229+
spec := newVMSSSpecWithSKU(resourceskus.MemoryGB, "217.13")
230+
spec.Size = "VM_SIZE_MEM_FLOAT"
231+
spec.Capacity = 2
232+
spec.SSHKeyData = sshKeyData
233+
memFloatVMSS := newDefaultVMSS("VM_SIZE_MEM_FLOAT")
234+
memFloatVMSS.ID = ptr.To(defaultVMSSID)
235+
236+
s.ScaleSetSpec(gomockinternal.AContext()).Return(&spec).AnyTimes()
237+
m.Get(gomockinternal.AContext(), &spec).Return(memFloatVMSS, nil)
238+
m.ListInstances(gomockinternal.AContext(), spec.ResourceGroup, spec.Name).Return(defaultInstances, nil)
239+
fetchedMemFloatVMSS := converters.SDKToVMSS(getMemFloatResultVMSS(), defaultInstances)
240+
s.ReconcileReplicas(gomockinternal.AContext(), &fetchedMemFloatVMSS).Return(nil).Times(2)
241+
s.SetProviderID(azureutil.ProviderIDPrefix + defaultVMSSID).Times(2)
242+
s.SetVMSSState(&fetchedMemFloatVMSS).Times(2)
243+
r.CreateOrUpdateResource(gomockinternal.AContext(), &spec, serviceName).Return(getMemFloatResultVMSS(), nil)
244+
s.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, nil)
245+
},
246+
},
217247
{
218248
name: "validate spec failure: failed to get SKU",
219249
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",
@@ -633,6 +663,34 @@ func getFakeSkus() []armcompute.ResourceSKU {
633663
},
634664
},
635665
},
666+
{
667+
Name: ptr.To("VM_SIZE_MEM_FLOAT"),
668+
ResourceType: ptr.To(string(resourceskus.VirtualMachines)),
669+
Kind: ptr.To(string(resourceskus.VirtualMachines)),
670+
Locations: []*string{
671+
ptr.To("test-location"),
672+
},
673+
LocationInfo: []*armcompute.ResourceSKULocationInfo{
674+
{
675+
Location: ptr.To("test-location"),
676+
Zones: []*string{ptr.To("1"), ptr.To("3")},
677+
},
678+
},
679+
Capabilities: []*armcompute.ResourceSKUCapabilities{
680+
{
681+
Name: ptr.To(resourceskus.AcceleratedNetworking),
682+
Value: ptr.To(string(resourceskus.CapabilityUnsupported)),
683+
},
684+
{
685+
Name: ptr.To(resourceskus.VCPUs),
686+
Value: ptr.To("4"),
687+
},
688+
{
689+
Name: ptr.To(resourceskus.MemoryGB),
690+
Value: ptr.To("217.13"),
691+
},
692+
},
693+
},
636694
}
637695
}
638696

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

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

0 commit comments

Comments
 (0)