@@ -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