Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.17] Update handling Capabilities that have a float value #5497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions azure/services/resourceskus/sku.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package resourceskus

import (
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -112,10 +113,11 @@
continue
}

intVal, err := strconv.ParseInt(*capability.Value, 10, 64)
floatVal, err := strconv.ParseFloat(*capability.Value, 64)

Check warning on line 116 in azure/services/resourceskus/sku.go

View check run for this annotation

Codecov / codecov/patch

azure/services/resourceskus/sku.go#L116

Added line #L116 was not covered by tests
if err != nil {
return false, errors.Wrapf(err, "failed to parse string '%s' as int64", *capability.Value)
return false, errors.Wrapf(err, "failed to parse string '%s' as float", *capability.Value)

Check warning on line 118 in azure/services/resourceskus/sku.go

View check run for this annotation

Codecov / codecov/patch

azure/services/resourceskus/sku.go#L118

Added line #L118 was not covered by tests
}
intVal := int64(math.Round(floatVal))

Check warning on line 120 in azure/services/resourceskus/sku.go

View check run for this annotation

Codecov / codecov/patch

azure/services/resourceskus/sku.go#L120

Added line #L120 was not covered by tests

if intVal >= value {
return true, nil
Expand Down
67 changes: 67 additions & 0 deletions azure/services/scalesets/scalesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func getResultVMSS() armcompute.VirtualMachineScaleSet {
return resultVMSS
}

func getMemFloatResultVMSS() armcompute.VirtualMachineScaleSet {
resultVMSS := newDefaultVMSS("VM_SIZE_MEM_FLOAT")
resultVMSS.ID = ptr.To(defaultVMSSID)

return resultVMSS
}

func TestReconcileVMSS(t *testing.T) {
defaultInstances := newDefaultInstances()
resultVMSS := newDefaultVMSS("VM_SIZE")
Expand Down Expand Up @@ -213,6 +220,29 @@ func TestReconcileVMSS(t *testing.T) {
s.ScaleSetSpec(gomockinternal.AContext()).Return(&spec).AnyTimes()
},
},
{
name: "validate spec success: Memory is float",
expectedError: "",
expect: func(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder, m *mock_scalesets.MockClientMockRecorder) {
s.DefaultedAzureServiceReconcileTimeout().Return(reconciler.DefaultAzureServiceReconcileTimeout)
spec := newVMSSSpecWithSKU(resourceskus.MemoryGB, "217.13")
spec.Size = "VM_SIZE_MEM_FLOAT"
spec.Capacity = 2
spec.SSHKeyData = sshKeyData
memFloatVMSS := newDefaultVMSS("VM_SIZE_MEM_FLOAT")
memFloatVMSS.ID = ptr.To(defaultVMSSID)

s.ScaleSetSpec(gomockinternal.AContext()).Return(&spec).AnyTimes()
m.Get(gomockinternal.AContext(), &spec).Return(memFloatVMSS, nil)
m.ListInstances(gomockinternal.AContext(), spec.ResourceGroup, spec.Name).Return(defaultInstances, nil)
fetchedMemFloatVMSS := converters.SDKToVMSS(getMemFloatResultVMSS(), defaultInstances)
s.ReconcileReplicas(gomockinternal.AContext(), &fetchedMemFloatVMSS).Return(nil).Times(2)
s.SetProviderID(azureutil.ProviderIDPrefix + defaultVMSSID).Times(2)
s.SetVMSSState(&fetchedMemFloatVMSS).Times(2)
r.CreateOrUpdateResource(gomockinternal.AContext(), &spec, serviceName).Return(getMemFloatResultVMSS(), nil)
s.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, nil)
},
},
{
name: "validate spec failure: failed to get SKU",
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",
Expand Down Expand Up @@ -634,6 +664,34 @@ func getFakeSkus() []armcompute.ResourceSKU {
},
},
},
{
Name: ptr.To("VM_SIZE_MEM_FLOAT"),
ResourceType: ptr.To(string(resourceskus.VirtualMachines)),
Kind: ptr.To(string(resourceskus.VirtualMachines)),
Locations: []*string{
ptr.To("test-location"),
},
LocationInfo: []*armcompute.ResourceSKULocationInfo{
{
Location: ptr.To("test-location"),
Zones: []*string{ptr.To("1"), ptr.To("3")},
},
},
Capabilities: []*armcompute.ResourceSKUCapabilities{
{
Name: ptr.To(resourceskus.AcceleratedNetworking),
Value: ptr.To(string(resourceskus.CapabilityUnsupported)),
},
{
Name: ptr.To(resourceskus.VCPUs),
Value: ptr.To("4"),
},
{
Name: ptr.To(resourceskus.MemoryGB),
Value: ptr.To("217.13"),
},
},
},
}
}

Expand Down Expand Up @@ -729,6 +787,15 @@ func newWindowsVMSSSpec() ScaleSetSpec {
vmss.OSDisk.OSType = azure.WindowsOS
return vmss
}
func newVMSSSpecWithSKU(capName string, capValue string) ScaleSetSpec {
vmsSpec := newDefaultVMSSSpec()
inputCapability := armcompute.ResourceSKUCapabilities{
Name: ptr.To(capName),
Value: ptr.To(capValue),
}
vmsSpec.SKU.Capabilities = append(vmsSpec.SKU.Capabilities, &inputCapability)
return vmsSpec
}

func newDefaultExistingVMSS() armcompute.VirtualMachineScaleSet {
vmss := newDefaultVMSS("VM_SIZE")
Expand Down