Skip to content

Commit

Permalink
Add consistent locking around mock EC2 tags
Browse files Browse the repository at this point in the history
  • Loading branch information
johngmyers committed Aug 4, 2020
1 parent 0ee7de9 commit 3fc8a00
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cloudmock/aws/mockec2/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (m *MockEC2) addTags(resourceId string, tags ...*ec2.Tag) {
} else {
klog.Fatalf("Unknown resource-type in create tags: %v", resourceId)
}

m.mutex.Lock()
defer m.mutex.Unlock()

for _, tag := range tags {
t := &ec2.TagDescription{
Key: tag.Key,
Expand All @@ -96,6 +100,9 @@ func (m *MockEC2) DescribeTagsWithContext(aws.Context, *ec2.DescribeTagsInput, .
}

func (m *MockEC2) hasTag(resourceType string, resourceId string, filter *ec2.Filter) bool {
m.mutex.Lock()
defer m.mutex.Unlock()

name := *filter.Name
if strings.HasPrefix(name, "tag:") {
tagKey := name[4:]
Expand Down Expand Up @@ -138,6 +145,9 @@ func (m *MockEC2) hasTag(resourceType string, resourceId string, filter *ec2.Fil
}

func (m *MockEC2) getTags(resourceType string, resourceId string) []*ec2.Tag {
m.mutex.Lock()
defer m.mutex.Unlock()

var tags []*ec2.Tag
for _, tag := range m.Tags {
if *tag.ResourceId != resourceId {
Expand Down

0 comments on commit 3fc8a00

Please sign in to comment.