Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
phuhung273 committed Dec 19, 2024
1 parent 0fe7e43 commit c679bfd
Show file tree
Hide file tree
Showing 2 changed files with 298 additions and 169 deletions.
25 changes: 23 additions & 2 deletions pkg/networking/backend_sg_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/smithy-go"
"regexp"
"sort"
"strings"
"sync"
"time"

ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/smithy-go"

awssdk "github.com/aws/aws-sdk-go-v2/aws"
ec2sdk "github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -234,6 +235,12 @@ func (p *defaultBackendSGProvider) allocateBackendSG(ctx context.Context, resour
if len(sgID) > 1 {
p.logger.V(1).Info("Existing SG found", "id", sgID)
p.autoGeneratedSG = sgID

if err = p.syncBackendSGTags(ctx, sgID); err != nil {
p.logger.Error(err, "failed to synchronize tags of existing securityGroup", sgID)
return err
}
p.logger.Info("added resource tags", "resourceID", sgID)
return nil
}

Expand All @@ -253,6 +260,20 @@ func (p *defaultBackendSGProvider) allocateBackendSG(ctx context.Context, resour
return nil
}

func (p *defaultBackendSGProvider) syncBackendSGTags(ctx context.Context, sgID string) error {
tagSpecifications := p.buildBackendSGTags(ctx)

createReq := &ec2sdk.CreateTagsInput{
Resources: []string{sgID},
Tags: tagSpecifications[0].Tags,
}

if _, err := p.ec2Client.CreateTagsWithContext(ctx, createReq); err != nil {
return err
}
return nil
}

func (p *defaultBackendSGProvider) buildBackendSGTags(_ context.Context) []ec2types.TagSpecification {
var defaultTags []ec2types.Tag
for key, val := range p.defaultTags {
Expand Down
Loading

0 comments on commit c679bfd

Please sign in to comment.