Skip to content
Open
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
39 changes: 38 additions & 1 deletion pkg/cloudprovider/suite_aksmachineapi_offerings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,50 @@ var _ = Describe("CloudProvider", func() {
ExpectApplied(ctx, env.Client, nodePool, nodeClass)
pod := coretest.UnschedulablePod()
ExpectProvisionedAndWaitForPromises(ctx, env.Client, clusterNonZonal, cloudProviderNonZonal, coreProvisionerNonZonal, azureEnvNonZonal, pod)
ExpectScheduled(ctx, env.Client, pod)
node := ExpectScheduled(ctx, env.Client, pod)
Expect(node.Labels).To(HaveKeyWithValue(v1.LabelTopologyZone, zones.Regional))
Expect(node.Labels).To(HaveKeyWithValue(v1beta1.LabelPlacementScope, v1beta1.PlacementScopeRegional))

Expect(azureEnvNonZonal.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(1))
aksMachine := azureEnvNonZonal.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Pop().AKSMachine
Expect(aksMachine.Zones).To(BeEmpty())
})

It("should support regional placement scope in non-zonal regions", func() {
coretest.ReplaceRequirements(nodePool, karpv1.NodeSelectorRequirementWithMinValues{
Key: v1beta1.LabelPlacementScope,
Operator: v1.NodeSelectorOpIn,
Values: []string{v1beta1.PlacementScopeRegional},
})
ExpectApplied(ctx, env.Client, nodePool, nodeClass)

pod := coretest.UnschedulablePod()
ExpectProvisionedAndWaitForPromises(ctx, env.Client, clusterNonZonal, cloudProviderNonZonal, coreProvisionerNonZonal, azureEnvNonZonal, pod)

node := ExpectScheduled(ctx, env.Client, pod)
Expect(node.Labels).To(HaveKeyWithValue(v1.LabelTopologyZone, zones.Regional))
Expect(node.Labels).To(HaveKeyWithValue(v1beta1.LabelPlacementScope, v1beta1.PlacementScopeRegional))

Expect(azureEnvNonZonal.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(1))
aksMachine := azureEnvNonZonal.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Pop().AKSMachine
Expect(aksMachine.Zones).To(BeEmpty())
})

It("should not provision in non-zonal regions when placement scope requires zonal", func() {
coretest.ReplaceRequirements(nodePool, karpv1.NodeSelectorRequirementWithMinValues{
Key: v1beta1.LabelPlacementScope,
Operator: v1.NodeSelectorOpIn,
Values: []string{v1beta1.PlacementScopeZonal},
})
ExpectApplied(ctx, env.Client, nodePool, nodeClass)

pod := coretest.UnschedulablePod()
ExpectProvisionedAndWaitForPromises(ctx, env.Client, clusterNonZonal, cloudProviderNonZonal, coreProvisionerNonZonal, azureEnvNonZonal, pod)

ExpectNotScheduled(ctx, env.Client, pod)
Expect(azureEnvNonZonal.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(0))
})

// Ported from VM test: "should support provisioning non-zonal instance types in zonal regions"
It("should support provisioning non-zonal instance types in zonal regions", func() {
coretest.ReplaceRequirements(nodePool, karpv1.NodeSelectorRequirementWithMinValues{
Expand Down
21 changes: 21 additions & 0 deletions pkg/providers/allocationstrategy/allocation_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,27 @@ func TestFilterInstanceOfferings_ZonalOfferingsBeforeRegionalAtSamePriceAndCapac
g.Expect(filtered[0].Offerings[0].Requirements.Get(corev1.LabelTopologyZone).Any()).To(Equal("westus-1"))
}

func TestFilterInstanceOfferings_ZonalPlacementScopeRejectsRegionalOfferings(t *testing.T) {
g := NewWithT(t)
provider := allocationstrategy.NewProvider()
requirements := scheduling.NewRequirements(
scheduling.NewRequirement(v1beta1.LabelPlacementScope, corev1.NodeSelectorOpIn, v1beta1.PlacementScopeZonal),
)

instanceTypes := []*corecloudprovider.InstanceType{
{
Name: "Standard_Regional",
Offerings: corecloudprovider.Offerings{
newOfferingWithZone(0.1, karpv1.CapacityTypeOnDemand, zones.Regional),
newOfferingWithZone(0.1, karpv1.CapacityTypeSpot, zones.Regional),
},
},
}

filtered := provider.FilterInstanceOfferings(context.Background(), allocationstrategy.NewInstanceOfferings(instanceTypes), requirements)
g.Expect(filtered).To(BeEmpty())
}

func TestFilterInstanceOfferings_SpotRegionalOfferingBeforeOnDemandZonalAtSamePrice(t *testing.T) {
g := NewWithT(t)
provider := allocationstrategy.NewProvider()
Expand Down
37 changes: 36 additions & 1 deletion pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1860,12 +1860,47 @@ var _ = Describe("InstanceType Provider", func() {
ExpectApplied(ctx, env.Client, nodePool, nodeClass)
pod := coretest.UnschedulablePod()
ExpectProvisionedAndWaitForPromises(ctx, env.Client, clusterNonZonal, cloudProviderNonZonal, coreProvisionerNonZonal, azureEnvNonZonal, pod)
ExpectScheduled(ctx, env.Client, pod)
node := ExpectScheduled(ctx, env.Client, pod)
Expect(node.Labels).To(HaveKeyWithValue(v1.LabelTopologyZone, zones.Regional))
Expect(node.Labels).To(HaveKeyWithValue(v1beta1.LabelPlacementScope, v1beta1.PlacementScopeRegional))

Expect(azureEnvNonZonal.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(1))
vm := azureEnvNonZonal.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM
Expect(vm.Zones).To(BeEmpty())
})
It("should support regional placement scope in non-zonal regions", func() {
coretest.ReplaceRequirements(nodePool, karpv1.NodeSelectorRequirementWithMinValues{
Key: v1beta1.LabelPlacementScope,
Operator: v1.NodeSelectorOpIn,
Values: []string{v1beta1.PlacementScopeRegional},
})
ExpectApplied(ctx, env.Client, nodePool, nodeClass)

pod := coretest.UnschedulablePod()
ExpectProvisionedAndWaitForPromises(ctx, env.Client, clusterNonZonal, cloudProviderNonZonal, coreProvisionerNonZonal, azureEnvNonZonal, pod)

node := ExpectScheduled(ctx, env.Client, pod)
Expect(node.Labels).To(HaveKeyWithValue(v1.LabelTopologyZone, zones.Regional))
Expect(node.Labels).To(HaveKeyWithValue(v1beta1.LabelPlacementScope, v1beta1.PlacementScopeRegional))

Expect(azureEnvNonZonal.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(1))
vm := azureEnvNonZonal.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop().VM
Expect(vm.Zones).To(BeEmpty())
})
It("should not provision in non-zonal regions when placement scope requires zonal", func() {
coretest.ReplaceRequirements(nodePool, karpv1.NodeSelectorRequirementWithMinValues{
Key: v1beta1.LabelPlacementScope,
Operator: v1.NodeSelectorOpIn,
Values: []string{v1beta1.PlacementScopeZonal},
})
ExpectApplied(ctx, env.Client, nodePool, nodeClass)

pod := coretest.UnschedulablePod()
ExpectProvisionedAndWaitForPromises(ctx, env.Client, clusterNonZonal, cloudProviderNonZonal, coreProvisionerNonZonal, azureEnvNonZonal, pod)

ExpectNotScheduled(ctx, env.Client, pod)
Expect(azureEnvNonZonal.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Len()).To(Equal(0))
})
It("should provision non-zonal instance types in zonal regions with zone label 0", func() {
coretest.ReplaceRequirements(nodePool, karpv1.NodeSelectorRequirementWithMinValues{
Key: v1.LabelInstanceTypeStable,
Expand Down