Skip to content

Commit 3b99382

Browse files
committed
simplify retry
1 parent 6ab3af5 commit 3b99382

9 files changed

Lines changed: 27 additions & 1168 deletions

File tree

cmd/manager/main.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ var (
4747
deleteCNRRequeue = app.Flag("delete-cnr-requeue", "How often to check if a CNR can be deleted").Default("24h").Duration()
4848
defaultCNScyclingExpiry = app.Flag("default-cns-cycling-expiry", "Fail the CNS if it has been cycling for this long").Default("3h").Duration()
4949
unhealthyPodTerminationThreshold = app.Flag("unhealthy-pod-termination-after", "How long to tolerate an un-evictable yet unhealthy pod before forcefully removing it").Default("5m").Duration()
50-
51-
// Retry configuration flags
52-
awsRetryEnabled = app.Flag("aws-retry-enabled", "Enable retry logic for transient AWS API errors").Default("true").Bool()
53-
awsMaxRetries = app.Flag("aws-max-retries", "Maximum number of retry attempts for transient AWS errors").Default("5").Int()
54-
awsInitialDelayMs = app.Flag("aws-initial-delay-ms", "Initial delay in milliseconds before the first retry (exponential backoff)").Default("5000").Int()
55-
awsMaxDelayMs = app.Flag("aws-max-delay-ms", "Maximum delay in milliseconds between retry attempts").Default("60000").Int()
5650
)
5751

5852
var log = logf.Log.WithName("cmd")
@@ -101,8 +95,9 @@ func main() {
10195
// Register the custom metrics
10296
metrics.Register(mgr.GetClient(), log, *namespace)
10397

104-
// Setup the cloud provider with retry configuration
105-
cloudProvider, err := builder.BuildCloudProviderWithRetryConfig(*cloudProviderName, logger, *awsRetryEnabled, *awsMaxRetries, *awsInitialDelayMs, *awsMaxDelayMs)
98+
// Setup the cloud provider
99+
// Uses AWS SDK's built-in retry behavior
100+
cloudProvider, err := builder.BuildCloudProvider(*cloudProviderName, logger)
106101
if err != nil {
107102
log.Error(err, "Unable to build cloud provider")
108103
os.Exit(1)

pkg/cloudprovider/aws/aws.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ type provider struct {
7171
autoScalingService autoscalingiface.AutoScalingAPI
7272
ec2Service ec2iface.EC2API
7373
logger logr.Logger
74-
retryConfig RetryConfig
7574
}
7675

7776
type autoscalingGroups struct {
7877
autoScalingService autoscalingiface.AutoScalingAPI
7978
ec2Service ec2iface.EC2API
8079
groups []*autoscaling.Group
8180
logger logr.Logger
82-
retryConfig RetryConfig
8381
}
8482

8583
type instance struct {
@@ -95,17 +93,9 @@ func (p *provider) Name() string {
9593

9694
// GetNodeGroups gets a Autoscaling groups
9795
func (p *provider) GetNodeGroups(names []string) (cloudprovider.NodeGroups, error) {
98-
var result *autoscaling.DescribeAutoScalingGroupsOutput
99-
var err error
100-
101-
// Retry with exponential backoff for transient errors
102-
err = retryOnTransientErrorWithConfig(func() error {
103-
result, err = p.autoScalingService.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{
104-
AutoScalingGroupNames: aws.StringSlice(names),
105-
})
106-
return err
107-
}, p.logger, p.retryConfig)
108-
96+
result, err := p.autoScalingService.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{
97+
AutoScalingGroupNames: aws.StringSlice(names),
98+
})
10999
if err != nil {
110100
return nil, err
111101
}
@@ -120,7 +110,6 @@ func (p *provider) GetNodeGroups(names []string) (cloudprovider.NodeGroups, erro
120110
autoScalingService: p.autoScalingService,
121111
ec2Service: p.ec2Service,
122112
logger: p.logger,
123-
retryConfig: p.retryConfig,
124113
}, nil
125114
}
126115

@@ -140,19 +129,11 @@ func (p *provider) InstancesExist(providerIDs []string) (map[string]interface{},
140129
instanceIDs = append(instanceIDs, instanceID)
141130
}
142131

143-
var output *ec2.DescribeInstancesOutput
144-
var err error
145-
146-
// Retry with exponential backoff for transient errors
147-
err = retryOnTransientErrorWithConfig(func() error {
148-
output, err = p.ec2Service.DescribeInstances(
149-
&ec2.DescribeInstancesInput{
150-
InstanceIds: aws.StringSlice(instanceIDs),
151-
},
152-
)
153-
return err
154-
}, p.logger, p.retryConfig)
155-
132+
output, err := p.ec2Service.DescribeInstances(
133+
&ec2.DescribeInstancesInput{
134+
InstanceIds: aws.StringSlice(instanceIDs),
135+
},
136+
)
156137
if err != nil {
157138
return nil, err
158139
}
@@ -179,14 +160,9 @@ func (p *provider) TerminateInstance(providerID string) error {
179160
return err
180161
}
181162

182-
// Retry with exponential backoff for transient errors
183-
err = retryOnTransientErrorWithConfig(func() error {
184-
_, err := p.ec2Service.TerminateInstances(&ec2.TerminateInstancesInput{
185-
InstanceIds: aws.StringSlice([]string{instanceID}),
186-
})
187-
return err
188-
}, p.logger, p.retryConfig)
189-
163+
_, err = p.ec2Service.TerminateInstances(&ec2.TerminateInstancesInput{
164+
InstanceIds: aws.StringSlice([]string{instanceID}),
165+
})
190166
return err
191167
}
192168

0 commit comments

Comments
 (0)