Skip to content

Commit 087a342

Browse files
authored
feat: Add ICE filtering for MaxFleetCountExceeded (#8698)
1 parent de7bb84 commit 087a342

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pkg/errors/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
RateLimitingErrorCode = "RequestLimitExceeded"
3232
ServiceLinkedRoleCreationNotPermittedErrorCode = "AuthFailure.ServiceLinkedRoleCreationNotPermitted"
3333
InsufficientFreeAddressesInSubnetErrorCode = "InsufficientFreeAddressesInSubnet"
34+
MaxFleetCountExceededErrorCode = "MaxFleetCountExceeded"
3435
)
3536

3637
var (
@@ -58,6 +59,7 @@ var (
5859
"UnfulfillableCapacity",
5960
"Unsupported",
6061
"InsufficientFreeAddressesInSubnet",
62+
"MaxFleetCountExceeded",
6163
reservationCapacityExceededErrorCode,
6264
)
6365
)

pkg/providers/instance/suite_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,43 @@ var _ = Describe("InstanceProvider", func() {
214214
// Expect that an event is fired for Spot SLR not being created
215215
awsEnv.EventRecorder.DetectedEvent(`Attempted to launch a spot instance but failed due to "AuthFailure.ServiceLinkedRoleCreationNotPermitted"`)
216216
})
217+
It("should return an ICE error when max fleet count is reached", func() {
218+
ExpectApplied(ctx, env.Client, nodeClaim, nodePool, nodeClass)
219+
nodeClass = ExpectExists(ctx, env.Client, nodeClass)
220+
awsEnv.EC2API.CreateFleetBehavior.Output.Set(&ec2.CreateFleetOutput{
221+
Errors: []ec2types.CreateFleetError{
222+
{
223+
ErrorCode: lo.ToPtr("MaxFleetCountExceeded"),
224+
ErrorMessage: lo.ToPtr("You've reached your quota for maximum Fleet Requests for this account."),
225+
LaunchTemplateAndOverrides: &ec2types.LaunchTemplateAndOverridesResponse{
226+
Overrides: &ec2types.FleetLaunchTemplateOverrides{
227+
InstanceType: "m5.xlarge",
228+
AvailabilityZone: lo.ToPtr("test-zone-1a"),
229+
},
230+
},
231+
},
232+
},
233+
})
234+
instanceTypes, err := cloudProvider.GetInstanceTypes(ctx, nodePool)
235+
Expect(err).ToNot(HaveOccurred())
236+
237+
// Filter down to a single instance type
238+
instanceTypes = lo.Filter(instanceTypes, func(i *corecloudprovider.InstanceType, _ int) bool {
239+
return i.Name == "m5.xlarge"
240+
})
241+
242+
// Since all the capacity pools are ICEd. This should return back an ICE error
243+
instance, err := awsEnv.InstanceProvider.Create(ctx, nodeClass, nodeClaim, nil, instanceTypes)
244+
fmt.Println(instance)
245+
Expect(corecloudprovider.IsInsufficientCapacityError(err)).To(BeTrue())
246+
Expect(instance).To(BeNil())
247+
248+
// Capacity should get ICEd when this error is received
249+
Expect(awsEnv.UnavailableOfferingsCache.IsUnavailable("m5.xlarge", "test-zone-1a", karpv1.CapacityTypeSpot)).To(BeTrue())
250+
Expect(awsEnv.UnavailableOfferingsCache.IsUnavailable("m5.xlarge", "test-zone-1b", karpv1.CapacityTypeSpot)).To(BeFalse())
251+
Expect(awsEnv.UnavailableOfferingsCache.IsUnavailable("m5.xlarge", "test-zone-1a", karpv1.CapacityTypeOnDemand)).To(BeFalse())
252+
Expect(awsEnv.UnavailableOfferingsCache.IsUnavailable("m5.xlarge", "test-zone-1b", karpv1.CapacityTypeOnDemand)).To(BeFalse())
253+
})
217254
It("should return an ICE error when all attempted instance types return a ReservedCapacityReservation error", func() {
218255
const targetReservationID = "cr-m5.large-1a-1"
219256
// Ensure that Karpenter believes a reservation is available, but the API returns no capacity when attempting to launch

0 commit comments

Comments
 (0)