Skip to content

Commit

Permalink
fix: Updated instanceTypeZones logic to handle non-zonal SKUs in zona…
Browse files Browse the repository at this point in the history
…l regions (#410)
  • Loading branch information
rakechill authored Jun 20, 2024
1 parent bb69e07 commit a1cd78e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/providers/instancetype/instancetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ func instanceTypeZones(sku *skewer.SKU, region string) sets.Set[string] {
// skewer returns numerical zones, like "1" (as keys in the map);
// prefix each zone with "<region>-", to have them match the labels placed on Node (e.g. "westus2-1")
// Note this data comes from LocationInfo, then skewer is used to get the SKU info
if hasZonalSupport(region) {
return sets.New(lo.Map(lo.Keys(sku.AvailabilityZones(region)), func(zone string, _ int) string {
// If an offering is non-zonal, the availability zones will be empty.
skuZones := lo.Keys(sku.AvailabilityZones(region))
if hasZonalSupport(region) && len(skuZones) > 0 {
return sets.New(lo.Map(skuZones, func(zone string, _ int) string {
return fmt.Sprintf("%s-%s", region, zone)
})...)
}

return sets.New("") // empty string means non-zonal offering
}

Expand Down
20 changes: 19 additions & 1 deletion pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ var _ = Describe("InstanceType Provider", func() {
It("should not include confidential SKUs", func() {
Expect(instanceTypes).ShouldNot(ContainElement(WithTransform(getName, Equal("Standard_DC8s_v3"))))
})

})
Context("Filtering GPU SKUs ProviderList(AzureLinux)", func() {
var instanceTypes corecloudprovider.InstanceTypes
Expand Down Expand Up @@ -1186,6 +1185,25 @@ var _ = Describe("InstanceType Provider", func() {
vm := azureEnvNonZonal.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM
Expect(vm.Zones).To(BeEmpty())
})
It("should support provisioning non-zonal instance types in zonal regions", func() {
coretest.ReplaceRequirements(nodePool, corev1beta1.NodeSelectorRequirementWithMinValues{
NodeSelectorRequirement: v1.NodeSelectorRequirement{
Key: v1.LabelInstanceTypeStable,
Operator: v1.NodeSelectorOpIn,
Values: []string{"Standard_NC6s_v3"},
}})
ExpectApplied(ctx, env.Client, nodePool, nodeClass)

pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)

node := ExpectScheduled(ctx, env.Client, pod)
Expect(node.Labels).To(HaveKeyWithValue(v1alpha2.AlternativeLabelTopologyZone, ""))

Expect(azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(1))
vm := azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM
Expect(vm.Zones).To(BeEmpty())
})
})
})

Expand Down

0 comments on commit a1cd78e

Please sign in to comment.