Skip to content

Commit 5db1a2f

Browse files
committed
handle race condition when tag sg at creation
1 parent 4c432ec commit 5db1a2f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

pkg/deploy/lb_security_group.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package deploy
22

33
import (
44
"context"
5+
"strings"
6+
"time"
7+
58
"github.com/aws/aws-sdk-go/aws"
69
"github.com/aws/aws-sdk-go/aws/arn"
710
"github.com/aws/aws-sdk-go/aws/awserr"
@@ -15,8 +18,6 @@ import (
1518
"sigs.k8s.io/aws-alb-ingress-controller/pkg/build"
1619
"sigs.k8s.io/aws-alb-ingress-controller/pkg/cloud"
1720
"sigs.k8s.io/aws-alb-ingress-controller/pkg/logging"
18-
"strings"
19-
"time"
2021
)
2122

2223
func NewLBSecurityGroupActuator(cloud cloud.Cloud, tagProvider TagProvider, stack *build.LoadBalancingStack) Actuator {

pkg/deploy/tags.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package deploy
22

33
import (
44
"context"
5+
"time"
6+
57
"github.com/aws/aws-sdk-go/aws"
8+
"github.com/aws/aws-sdk-go/aws/awserr"
69
"github.com/aws/aws-sdk-go/aws/awsutil"
710
"github.com/aws/aws-sdk-go/service/ec2"
811
"github.com/aws/aws-sdk-go/service/elbv2"
912
"k8s.io/apimachinery/pkg/util/sets"
13+
"k8s.io/apimachinery/pkg/util/wait"
1014
"sigs.k8s.io/aws-alb-ingress-controller/pkg/cloud"
1115
"sigs.k8s.io/aws-alb-ingress-controller/pkg/logging"
1216
)
@@ -91,10 +95,20 @@ func (p *defaultTagProvider) ReconcileEC2Tags(ctx context.Context, ec2ResID stri
9195
modify, remove := computeTagChangeSet(curTags, desiredTags)
9296
if len(modify) > 0 {
9397
logging.FromContext(ctx).Info("modifying tags", "ID", ec2ResID, "changes", awsutil.Prettify(modify))
94-
if _, err := p.cloud.EC2().CreateTagsWithContext(ctx, &ec2.CreateTagsInput{
95-
Resources: []*string{aws.String(ec2ResID)},
96-
Tags: convertToEC2Tags(modify),
97-
}); err != nil {
98+
99+
if err := wait.PollImmediateUntil(2*time.Second, func() (done bool, err error) {
100+
if _, err := p.cloud.EC2().CreateTagsWithContext(ctx, &ec2.CreateTagsInput{
101+
Resources: []*string{aws.String(ec2ResID)},
102+
Tags: convertToEC2Tags(modify),
103+
}); err != nil {
104+
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "InvalidGroup.NotFound" {
105+
return false, nil
106+
}
107+
return false, err
108+
}
109+
110+
return true, nil
111+
}, ctx.Done()); err != nil {
98112
return err
99113
}
100114
logging.FromContext(ctx).Info("modified tags", "ID", ec2ResID)

0 commit comments

Comments
 (0)