Skip to content

Commit bd4dd60

Browse files
committed
refactor: rename zone util functions to be more accurate
1 parent f8d89d7 commit bd4dd60

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

pkg/cloudprovider/cloudprovider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func (c *CloudProvider) vmInstanceToNodeClaim(ctx context.Context, vm *armcomput
481481
nodeClaim.Status.Allocatable = lo.PickBy(instanceType.Allocatable(), func(_ corev1.ResourceName, v resource.Quantity) bool { return !resources.IsZero(v) })
482482
}
483483

484-
if zone, err := utils.GetZone(vm); err != nil {
484+
if zone, err := utils.GetAKSLabelZoneFromVM(vm); err != nil {
485485
log.FromContext(ctx).Info("failed to get zone for VM, zone label will be empty", "vmName", *vm.Name, "error", err)
486486
} else {
487487
labels[corev1.LabelTopologyZone] = zone

pkg/providers/instance/vminstance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (p *DefaultVMProvider) BeginCreate(
185185
return nil, err
186186
}
187187
vm := vmPromise.VM
188-
zone, err := utils.GetZone(vm)
188+
zone, err := utils.GetAKSLabelZoneFromVM(vm)
189189
if err != nil {
190190
log.FromContext(ctx).V(1).Info("failed to get zone for VM", "vmName", *vm.Name, "error", err)
191191
}
@@ -539,7 +539,7 @@ func newVMObject(opts *createVMOptions) *armcompute.VirtualMachine {
539539
CapacityTypeToVMPriority[opts.CapacityType]),
540540
),
541541
},
542-
Zones: utils.MakeVMZone(opts.Zone),
542+
Zones: utils.GetARMZonesFromAKSLabelZone(opts.Zone),
543543
Tags: opts.LaunchTemplate.Tags,
544544
}
545545
setVMPropertiesOSDiskType(vm.Properties, opts.LaunchTemplate)

pkg/providers/instancetype/instancetypes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (p *DefaultProvider) instanceTypeZones(sku *skewer.SKU) sets.Set[string] {
192192
skuZones := lo.Keys(sku.AvailabilityZones(p.region))
193193
if len(skuZones) > 0 {
194194
return sets.New(lo.Map(skuZones, func(zone string, _ int) string {
195-
return utils.MakeZone(p.region, zone)
195+
return utils.GetAKSLabelZoneFromARMZone(p.region, zone)
196196
})...)
197197
}
198198
return sets.New("") // empty string means non-zonal offering

pkg/providers/instancetype/suite_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var coreProvisioner, coreProvisionerNonZonal *provisioning.Provisioner
8989
var cluster, clusterNonZonal *state.Cluster
9090
var cloudProvider, cloudProviderNonZonal *cloudprovider.CloudProvider
9191

92-
var fakeZone1 = utils.MakeZone(fake.Region, "1")
92+
var fakeZone1 = utils.GetAKSLabelZoneFromARMZone(fake.Region, "1")
9393

9494
var defaultTestSKU = &skewer.SKU{Name: lo.ToPtr("Standard_D2_v3"), Family: lo.ToPtr("standardD2v3Family")}
9595

@@ -400,7 +400,7 @@ var _ = Describe("InstanceType Provider", func() {
400400
ExpectNotScheduled(ctx, env.Client, pod)
401401

402402
// ensure that initial zone was made unavailable
403-
zone, err := utils.GetZone(&azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM)
403+
zone, err := utils.GetAKSLabelZoneFromVM(&azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM)
404404
Expect(err).ToNot(HaveOccurred())
405405
ExpectUnavailable(azureEnv, defaultTestSKU, zone, karpv1.CapacityTypeSpot)
406406

@@ -470,7 +470,7 @@ var _ = Describe("InstanceType Provider", func() {
470470
// ensure that initial VM size was made unavailable
471471
vm := azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM
472472
initialVMSize := *vm.Properties.HardwareProfile.VMSize
473-
zone, err := utils.GetZone(&vm)
473+
zone, err := utils.GetAKSLabelZoneFromVM(&vm)
474474
Expect(err).ToNot(HaveOccurred())
475475
ExpectUnavailable(azureEnv, &skewer.SKU{Name: lo.ToPtr(string(initialVMSize))}, zone, karpv1.CapacityTypeSpot)
476476

@@ -1152,7 +1152,7 @@ var _ = Describe("InstanceType Provider", func() {
11521152
Eventually(func() []*karpv1.NodeClaim { return ExpectNodeClaims(ctx, env.Client) }).To(HaveLen(0))
11531153

11541154
By("marking whatever zone was picked as unavailable - for both spot and on-demand")
1155-
zone, err := utils.GetZone(&azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM)
1155+
zone, err := utils.GetAKSLabelZoneFromVM(&azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM)
11561156
Expect(err).ToNot(HaveOccurred())
11571157
for _, skuToCheck := range expectedUnavailableSKUs {
11581158
Expect(azureEnv.UnavailableOfferingsCache.IsUnavailable(skuToCheck, zone, karpv1.CapacityTypeSpot)).To(BeTrue())
@@ -1292,7 +1292,7 @@ var _ = Describe("InstanceType Provider", func() {
12921292
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)
12931293
ExpectNotScheduled(ctx, env.Client, pod)
12941294
for _, zoneID := range []string{"1", "2", "3"} {
1295-
ExpectUnavailable(azureEnv, sku, utils.MakeZone(fake.Region, zoneID), capacityType)
1295+
ExpectUnavailable(azureEnv, sku, utils.GetAKSLabelZoneFromARMZone(fake.Region, zoneID), capacityType)
12961296
}
12971297
}
12981298

pkg/utils/zone.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ import (
2323
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
2424
)
2525

26-
// MakeZone returns the zone value in format of <region>-<zone-id>.
27-
func MakeZone(location string, zoneID string) string {
26+
// GetAKSLabelZoneFromARMZone returns the zone value in format of <region>-<zone-id>.
27+
func GetAKSLabelZoneFromARMZone(location string, zoneID string) string {
2828
if zoneID == "" {
2929
return ""
3030
}
3131
return fmt.Sprintf("%s-%s", strings.ToLower(location), zoneID)
3232
}
3333

34-
// VM Zones field expects just the zone number, without region
35-
func MakeVMZone(zone string) []*string {
34+
// GetARMZonesFromAKSLabelZone returns the zone ID from <region>-<zone-id>.
35+
func GetARMZonesFromAKSLabelZone(zone string) []*string {
3636
if zone == "" {
3737
return []*string{}
3838
}
3939
zoneNum := zone[len(zone)-1:]
4040
return []*string{&zoneNum}
4141
}
4242

43-
// GetZone returns the zone for the given virtual machine, or an empty string if there is no zone specified
44-
func GetZone(vm *armcompute.VirtualMachine) (string, error) {
43+
// GetAKSLabelZoneFromVM returns the zone for the given virtual machine, or an empty string if there is no zone specified
44+
func GetAKSLabelZoneFromVM(vm *armcompute.VirtualMachine) (string, error) {
4545
if vm == nil {
4646
return "", fmt.Errorf("cannot pass in a nil virtual machine")
4747
}
@@ -52,7 +52,7 @@ func GetZone(vm *armcompute.VirtualMachine) (string, error) {
5252
if vm.Location == nil {
5353
return "", fmt.Errorf("virtual machine is missing location")
5454
}
55-
return MakeZone(*vm.Location, *(vm.Zones)[0]), nil
55+
return GetAKSLabelZoneFromARMZone(*vm.Location, *(vm.Zones)[0]), nil
5656
}
5757
if len(vm.Zones) > 1 {
5858
return "", fmt.Errorf("virtual machine has multiple zones")

pkg/utils/zone_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/stretchr/testify/assert"
2626
)
2727

28-
func TestGetZone(t *testing.T) {
28+
func TestGetAKSLabelZoneFromVM(t *testing.T) {
2929
tc := []struct {
3030
testName string
3131
input *armcompute.VirtualMachine
@@ -74,7 +74,7 @@ func TestGetZone(t *testing.T) {
7474
}
7575

7676
for _, c := range tc {
77-
zone, err := utils.GetZone(c.input)
77+
zone, err := utils.GetAKSLabelZoneFromVM(c.input)
7878
assert.Equal(t, c.expectedZone, zone, c.testName)
7979
if err == nil && c.expectedError != "" {
8080
assert.Fail(t, "expected error but got nil", c.testName)

0 commit comments

Comments
 (0)