Skip to content

Commit 9f4dd65

Browse files
Merge pull request #1401 from JoelSpeed/revert-1340-aws_legacy_sg_tags
OCPBUGS-2946: Revert: 1340: tag AWS security group at creation
2 parents ba02ba5 + e837ceb commit 9f4dd65

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

Diff for: staging/src/k8s.io/legacy-cloud-providers/aws/aws.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -3364,21 +3364,6 @@ func (c *Cloud) ensureSecurityGroup(name string, description string, additionalT
33643364
createRequest.VpcId = &c.vpcID
33653365
createRequest.GroupName = &name
33663366
createRequest.Description = &description
3367-
tags := c.tagging.buildTags(ResourceLifecycleOwned, additionalTags)
3368-
var awsTags []*ec2.Tag
3369-
for k, v := range tags {
3370-
tag := &ec2.Tag{
3371-
Key: aws.String(k),
3372-
Value: aws.String(v),
3373-
}
3374-
awsTags = append(awsTags, tag)
3375-
}
3376-
createRequest.TagSpecifications = []*ec2.TagSpecification{
3377-
{
3378-
ResourceType: aws.String(ec2.ResourceTypeSecurityGroup),
3379-
Tags: awsTags,
3380-
},
3381-
}
33823367

33833368
createResponse, err := c.ec2.CreateSecurityGroup(createRequest)
33843369
if err != nil {
@@ -3404,6 +3389,14 @@ func (c *Cloud) ensureSecurityGroup(name string, description string, additionalT
34043389
return "", fmt.Errorf("created security group, but id was not returned: %s", name)
34053390
}
34063391

3392+
err := c.tagging.createTags(c.ec2, groupID, ResourceLifecycleOwned, additionalTags)
3393+
if err != nil {
3394+
// If we retry, ensureClusterTags will recover from this - it
3395+
// will add the missing tags. We could delete the security
3396+
// group here, but that doesn't feel like the right thing, as
3397+
// the caller is likely to retry the create
3398+
return "", fmt.Errorf("error tagging security group: %q", err)
3399+
}
34073400
return groupID, nil
34083401
}
34093402

Diff for: staging/src/k8s.io/legacy-cloud-providers/aws/aws_loadbalancer.go

+19-17
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,6 @@ func (c *Cloud) createListenerV2(loadBalancerArn *string, mapping nlbPortMapping
528528
return nil, err
529529
}
530530

531-
elbTags := []*elbv2.Tag{}
532-
for k, v := range tags {
533-
elbTags = append(elbTags, &elbv2.Tag{
534-
Key: aws.String(k),
535-
Value: aws.String(v),
536-
})
537-
}
538-
539531
createListernerInput := &elbv2.CreateListenerInput{
540532
LoadBalancerArn: loadBalancerArn,
541533
Port: aws.Int64(mapping.FrontendPort),
@@ -544,7 +536,6 @@ func (c *Cloud) createListenerV2(loadBalancerArn *string, mapping nlbPortMapping
544536
TargetGroupArn: target.TargetGroupArn,
545537
Type: aws.String(elbv2.ActionTypeEnumForward),
546538
}},
547-
Tags: elbTags,
548539
}
549540
if mapping.FrontendProtocol == "TLS" {
550541
if mapping.SSLPolicy != "" {
@@ -604,24 +595,35 @@ func (c *Cloud) ensureTargetGroup(targetGroup *elbv2.TargetGroup, serviceName ty
604595
input.HealthCheckPath = aws.String(mapping.HealthCheckConfig.Path)
605596
}
606597

598+
result, err := c.elbv2.CreateTargetGroup(input)
599+
if err != nil {
600+
return nil, fmt.Errorf("error creating load balancer target group: %q", err)
601+
}
602+
if len(result.TargetGroups) != 1 {
603+
return nil, fmt.Errorf("expected only one target group on CreateTargetGroup, got %d groups", len(result.TargetGroups))
604+
}
605+
607606
if len(tags) != 0 {
608607
targetGroupTags := make([]*elbv2.Tag, 0, len(tags))
609608
for k, v := range tags {
610609
targetGroupTags = append(targetGroupTags, &elbv2.Tag{
611610
Key: aws.String(k), Value: aws.String(v),
612611
})
613612
}
614-
input.Tags = targetGroupTags
615-
}
616-
result, err := c.elbv2.CreateTargetGroup(input)
617-
if err != nil {
618-
return nil, fmt.Errorf("error creating load balancer target group: %q", err)
619-
}
620-
if len(result.TargetGroups) != 1 {
621-
return nil, fmt.Errorf("expected only one target group on CreateTargetGroup, got %d groups", len(result.TargetGroups))
613+
tgArn := aws.StringValue(result.TargetGroups[0].TargetGroupArn)
614+
if _, err := c.elbv2.AddTags(&elbv2.AddTagsInput{
615+
ResourceArns: []*string{aws.String(tgArn)},
616+
Tags: targetGroupTags,
617+
}); err != nil {
618+
return nil, fmt.Errorf("error adding tags for targetGroup %s due to %q", tgArn, err)
619+
}
622620
}
623621

624622
tg := result.TargetGroups[0]
623+
tgARN := aws.StringValue(tg.TargetGroupArn)
624+
if err := c.ensureTargetGroupTargets(tgARN, expectedTargets, nil); err != nil {
625+
return nil, err
626+
}
625627
return tg, nil
626628
}
627629

0 commit comments

Comments
 (0)