Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (c *CloudProvider) vmInstanceToNodeClaim(ctx context.Context, vm *armcomput
nodeClaim.Status.Allocatable = lo.PickBy(instanceType.Allocatable(), func(_ corev1.ResourceName, v resource.Quantity) bool { return !resources.IsZero(v) })
}

if zone, err := utils.GetZone(vm); err != nil {
if zone, err := utils.GetAKSLabelZoneFromVM(vm); err != nil {
log.FromContext(ctx).Info("failed to get zone for VM, zone label will be empty", "vmName", *vm.Name, "error", err)
} else {
labels[corev1.LabelTopologyZone] = zone
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/instance/vminstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (p *DefaultVMProvider) BeginCreate(
return nil, err
}
vm := vmPromise.VM
zone, err := utils.GetZone(vm)
zone, err := utils.GetAKSLabelZoneFromVM(vm)
if err != nil {
log.FromContext(ctx).V(1).Info("failed to get zone for VM", "vmName", *vm.Name, "error", err)
}
Expand Down Expand Up @@ -541,7 +541,7 @@ func newVMObject(opts *createVMOptions) *armcompute.VirtualMachine {
},
Priority: lo.ToPtr(KarpCapacityTypeToVMPriority[opts.CapacityType]),
},
Zones: utils.MakeVMZone(opts.Zone),
Zones: utils.GetARMZonesFromAKSLabelZone(opts.Zone),
Tags: opts.LaunchTemplate.Tags,
}
setVMPropertiesOSDiskType(vm.Properties, opts.LaunchTemplate)
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/instancetype/instancetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (p *DefaultProvider) instanceTypeZones(sku *skewer.SKU) sets.Set[string] {
skuZones := lo.Keys(sku.AvailabilityZones(p.region))
if len(skuZones) > 0 {
return sets.New(lo.Map(skuZones, func(zone string, _ int) string {
return utils.MakeZone(p.region, zone)
return utils.GetAKSLabelZoneFromARMZone(p.region, zone)
})...)
}
return sets.New("") // empty string means non-zonal offering
Expand Down
10 changes: 5 additions & 5 deletions pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var coreProvisioner, coreProvisionerNonZonal *provisioning.Provisioner
var cluster, clusterNonZonal *state.Cluster
var cloudProvider, cloudProviderNonZonal *cloudprovider.CloudProvider

var fakeZone1 = utils.MakeZone(fake.Region, "1")
var fakeZone1 = utils.GetAKSLabelZoneFromARMZone(fake.Region, "1")

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

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

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

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

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

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

Expand Down
14 changes: 7 additions & 7 deletions pkg/utils/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7"
)

// MakeZone returns the zone value in format of <region>-<zone-id>.
func MakeZone(location string, zoneID string) string {
// GetAKSLabelZoneFromARMZone returns the zone value in format of <region>-<zone-id>.
func GetAKSLabelZoneFromARMZone(location string, zoneID string) string {
if zoneID == "" {
return ""
}
return fmt.Sprintf("%s-%s", strings.ToLower(location), zoneID)
}

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

// GetZone returns the zone for the given virtual machine, or an empty string if there is no zone specified
func GetZone(vm *armcompute.VirtualMachine) (string, error) {
// GetAKSLabelZoneFromVM returns the zone for the given virtual machine, or an empty string if there is no zone specified
func GetAKSLabelZoneFromVM(vm *armcompute.VirtualMachine) (string, error) {
if vm == nil {
return "", fmt.Errorf("cannot pass in a nil virtual machine")
}
Expand All @@ -52,7 +52,7 @@ func GetZone(vm *armcompute.VirtualMachine) (string, error) {
if vm.Location == nil {
return "", fmt.Errorf("virtual machine is missing location")
}
return MakeZone(*vm.Location, *(vm.Zones)[0]), nil
return GetAKSLabelZoneFromARMZone(*vm.Location, *(vm.Zones)[0]), nil
}
if len(vm.Zones) > 1 {
return "", fmt.Errorf("virtual machine has multiple zones")
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestGetZone(t *testing.T) {
func TestGetAKSLabelZoneFromVM(t *testing.T) {
tc := []struct {
testName string
input *armcompute.VirtualMachine
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestGetZone(t *testing.T) {
}

for _, c := range tc {
zone, err := utils.GetZone(c.input)
zone, err := utils.GetAKSLabelZoneFromVM(c.input)
assert.Equal(t, c.expectedZone, zone, c.testName)
if err == nil && c.expectedError != "" {
assert.Fail(t, "expected error but got nil", c.testName)
Expand Down
Loading