Skip to content

Commit 39dfdb7

Browse files
committed
fix: increase validation cache
1 parent 4bb10c5 commit 39dfdb7

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

pkg/cache/cache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const (
4545
// DiscoveredCapacityCacheTTL is the time to drop discovered resource capacity data per-instance type
4646
// if it is not updated by a node creation event or refreshed during controller reconciliation
4747
DiscoveredCapacityCacheTTL = 60 * 24 * time.Hour
48+
// ValidationTTL is time to check authorization errors with validation controller
49+
ValidationTTL = 10 * time.Minute
4850
)
4951

5052
const (

pkg/controllers/nodeclass/validation.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ func (v *Validation) validateCreateFleetAuthorization(
160160
createFleetInput := instance.GetCreateFleetInput(nodeClass, karpv1.CapacityTypeOnDemand, tags, mockLaunchTemplateConfig())
161161
createFleetInput.DryRun = lo.ToPtr(true)
162162
if _, err := v.ec2api.CreateFleet(ctx, createFleetInput); awserrors.IgnoreDryRunError(err) != nil {
163+
if awserrors.IsRateLimitedError(err) {
164+
return "", true, nil
165+
}
163166
if awserrors.IgnoreUnauthorizedOperationError(err) != nil {
164167
// Dry run should only ever return UnauthorizedOperation or DryRunOperation so if we receive any other error
165168
// it would be an unexpected state
@@ -183,6 +186,9 @@ func (v *Validation) validateCreateLaunchTemplateAuthorization(
183186
createLaunchTemplateInput := launchtemplate.GetCreateLaunchTemplateInput(ctx, opts[0], corev1.IPv4Protocol, "")
184187
createLaunchTemplateInput.DryRun = lo.ToPtr(true)
185188
if _, err := v.ec2api.CreateLaunchTemplate(ctx, createLaunchTemplateInput); awserrors.IgnoreDryRunError(err) != nil {
189+
if awserrors.IsRateLimitedError(err) {
190+
return "", true, nil
191+
}
186192
if awserrors.IgnoreUnauthorizedOperationError(err) != nil {
187193
// Dry run should only ever return UnauthorizedOperation or DryRunOperation so if we receive any other error
188194
// it would be an unexpected state
@@ -234,7 +240,7 @@ func (v *Validation) validateRunInstancesAuthorization(
234240
if _, err = v.ec2api.RunInstances(ctx, runInstancesInput); awserrors.IgnoreDryRunError(err) != nil {
235241
// If we get InstanceProfile NotFound, but we have a resolved instance profile in the status,
236242
// this means there is most likely an eventual consistency issue and we just need to requeue
237-
if awserrors.IsInstanceProfileNotFound(err) {
243+
if awserrors.IsInstanceProfileNotFound(err) || awserrors.IsRateLimitedError(err) {
238244
return "", true, nil
239245
}
240246
if awserrors.IgnoreUnauthorizedOperationError(err) != nil {

pkg/errors/errors.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
RunInstancesInvalidParameterValueCode = "InvalidParameterValue"
2929
DryRunOperationErrorCode = "DryRunOperation"
3030
UnauthorizedOperationErrorCode = "UnauthorizedOperation"
31+
RateLimitingErrorCode = "RequestLimitExceeded"
3132
)
3233

3334
var (
@@ -129,6 +130,23 @@ func IgnoreUnauthorizedOperationError(err error) error {
129130
return err
130131
}
131132

133+
func IsRateLimitedError(err error) bool {
134+
if err == nil {
135+
return false
136+
}
137+
if apiErr, ok := lo.ErrorsAs[smithy.APIError](err); ok {
138+
return apiErr.ErrorCode() == RateLimitingErrorCode
139+
}
140+
return false
141+
}
142+
143+
func IgnoreRateLimitedError(err error) error {
144+
if IsUnauthorizedOperationError(err) {
145+
return nil
146+
}
147+
return err
148+
}
149+
132150
// IsUnfulfillableCapacity returns true if the Fleet err means capacity is temporarily unavailable for launching. This
133151
// could be due to account limits, insufficient ec2 capacity, etc.
134152
func IsUnfulfillableCapacity(err ec2types.CreateFleetError) bool {

pkg/operator/operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont
144144
}
145145
unavailableOfferingsCache := awscache.NewUnavailableOfferings()
146146
ssmCache := cache.New(awscache.SSMCacheTTL, awscache.DefaultCleanupInterval)
147-
validationCache := cache.New(awscache.DefaultTTL, awscache.DefaultCleanupInterval)
147+
validationCache := cache.New(awscache.ValidationTTL, awscache.DefaultCleanupInterval)
148148

149149
subnetProvider := subnet.NewDefaultProvider(ec2api, cache.New(awscache.DefaultTTL, awscache.DefaultCleanupInterval), cache.New(awscache.AvailableIPAddressTTL, awscache.DefaultCleanupInterval), cache.New(awscache.AssociatePublicIPAddressTTL, awscache.DefaultCleanupInterval))
150150
securityGroupProvider := securitygroup.NewDefaultProvider(ec2api, cache.New(awscache.DefaultTTL, awscache.DefaultCleanupInterval))

0 commit comments

Comments
 (0)