Skip to content

Commit 53097e9

Browse files
authored
Merge pull request #2111 from crossplane-contrib/backport-2110-to-release-0.50
2 parents 89313d7 + 423f4d4 commit 53097e9

File tree

9 files changed

+287
-60
lines changed

9 files changed

+287
-60
lines changed

pkg/clients/ec2/address.go

-29
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ec2
33
import (
44
"context"
55
"errors"
6-
"sort"
76

87
"github.com/aws/aws-sdk-go-v2/aws"
98
"github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -101,31 +100,3 @@ func BuildFromEC2Tags(tags []ec2types.Tag) []v1beta1.Tag {
101100

102101
return res
103102
}
104-
105-
// CompareTags compares arrays of v1beta1.Tag and ec2types.Tag
106-
func CompareTags(tags []v1beta1.Tag, ec2Tags []ec2types.Tag) bool {
107-
if len(tags) != len(ec2Tags) {
108-
return false
109-
}
110-
111-
SortTags(tags, ec2Tags)
112-
113-
for i, t := range tags {
114-
if t.Key != *ec2Tags[i].Key || t.Value != *ec2Tags[i].Value {
115-
return false
116-
}
117-
}
118-
119-
return true
120-
}
121-
122-
// SortTags sorts array of v1beta1.Tag and ec2types.Tag on 'Key'
123-
func SortTags(tags []v1beta1.Tag, ec2Tags []ec2types.Tag) {
124-
sort.Slice(tags, func(i, j int) bool {
125-
return tags[i].Key < tags[j].Key
126-
})
127-
128-
sort.Slice(ec2Tags, func(i, j int) bool {
129-
return *ec2Tags[i].Key < *ec2Tags[j].Key
130-
})
131-
}

pkg/clients/ec2/internetgateway.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func IsIgUpToDate(p v1beta1.InternetGatewayParameters, ig ec2types.InternetGatew
9696
// if the attachment in spec exists in ig.Attachments, compare the tags and return
9797
for _, a := range ig.Attachments {
9898
if aws.ToString(p.VPCID) == aws.ToString(a.VpcId) {
99-
return CompareTagsV1Beta1(p.Tags, ig.Tags)
99+
return CompareTags(p.Tags, ig.Tags)
100100
}
101101
}
102102

pkg/clients/ec2/routetable.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func CreateRTPatch(in ec2types.RouteTable, target v1beta1.RouteTableParameters)
160160
targetCopy := target.DeepCopy()
161161
currentParams := &v1beta1.RouteTableParameters{}
162162

163-
SortTagsV1Beta1(target.Tags, in.Tags)
163+
CompareTags(target.Tags, in.Tags)
164164

165165
if !pointer.BoolValue(target.IgnoreRoutes) {
166166
// Add the default route for fair comparison.

pkg/clients/ec2/subnet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ func IsSubnetUpToDate(p v1beta1.SubnetParameters, s ec2types.Subnet) bool {
8585
if aws.ToBool(p.AssignIPv6AddressOnCreation) != aws.ToBool(s.AssignIpv6AddressOnCreation) {
8686
return false
8787
}
88-
return CompareTagsV1Beta1(p.Tags, s.Tags)
88+
return CompareTags(p.Tags, s.Tags)
8989
}

pkg/clients/ec2/tags_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ func TestDiffEC2Tags(t *testing.T) {
7070
remove: []ec2types.Tag{},
7171
},
7272
},
73+
"TagsWithSameKeyValuesButDifferentOrder": {
74+
args: args{
75+
local: []ec2types.Tag{
76+
{
77+
Key: aws.String("val"),
78+
Value: aws.String("key"),
79+
},
80+
{
81+
Key: aws.String("name"),
82+
Value: aws.String("somename"),
83+
},
84+
},
85+
remote: []ec2types.Tag{
86+
{
87+
Key: aws.String("name"),
88+
Value: aws.String("somename"),
89+
},
90+
{
91+
Key: aws.String("val"),
92+
Value: aws.String("key"),
93+
},
94+
},
95+
},
96+
want: want{
97+
add: []ec2types.Tag{},
98+
remove: []ec2types.Tag{},
99+
},
100+
},
73101
"TagsWithSameKeyDifferentValuesAndSameLength": {
74102
args: args{
75103
local: []ec2types.Tag{

pkg/clients/ec2/tags_v1beta1.go

+5-26
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package ec2
1818

1919
import (
20-
"sort"
21-
2220
"github.com/aws/aws-sdk-go-v2/aws"
2321
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
2422

@@ -47,30 +45,11 @@ func GenerateEC2TagsV1Beta1(tags []svcapitypes.Tag) []ec2types.Tag {
4745
return res
4846
}
4947

50-
// CompareTags compares arrays of v1beta1.Tag and ec2type.Tag
51-
func CompareTagsV1Beta1(tags []svcapitypes.Tag, ec2Tags []ec2types.Tag) bool {
52-
if len(tags) != len(ec2Tags) {
48+
// CompareTags compares arrays of v1beta1.Tag and ec2types.Tag
49+
func CompareTags(spec []svcapitypes.Tag, current []ec2types.Tag) bool {
50+
if len(spec) != len(current) {
5351
return false
5452
}
55-
56-
SortTagsV1Beta1(tags, ec2Tags)
57-
58-
for i, t := range tags {
59-
if t.Key != *ec2Tags[i].Key || t.Value != *ec2Tags[i].Value {
60-
return false
61-
}
62-
}
63-
64-
return true
65-
}
66-
67-
// SortTags sorts array of v1beta1.Tag and ec2type.Tag on 'Key'
68-
func SortTagsV1Beta1(tags []svcapitypes.Tag, ec2Tags []ec2types.Tag) {
69-
sort.Slice(tags, func(i, j int) bool {
70-
return tags[i].Key < tags[j].Key
71-
})
72-
73-
sort.Slice(ec2Tags, func(i, j int) bool {
74-
return *ec2Tags[i].Key < *ec2Tags[j].Key
75-
})
53+
toAdd, toRemove := DiffEC2Tags(GenerateEC2TagsV1Beta1(spec), current)
54+
return len(toAdd) == 0 && len(toRemove) == 0
7655
}

pkg/clients/ec2/vpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func IsVpcUpToDate(spec v1beta1.VPCParameters, vpc ec2types.Vpc, attributes ec2.
5353
return false
5454
}
5555

56-
return CompareTagsV1Beta1(spec.Tags, vpc.Tags)
56+
return CompareTags(spec.Tags, vpc.Tags)
5757
}
5858

5959
// GenerateVpcObservation is used to produce v1beta1.VPCObservation from

pkg/controller/ec2/natgateway/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (e *external) Observe(ctx context.Context, mgd resource.Managed) (managed.E
142142

143143
return managed.ExternalObservation{
144144
ResourceExists: true,
145-
ResourceUpToDate: ec2.CompareTagsV1Beta1(cr.Spec.ForProvider.Tags, observed.Tags),
145+
ResourceUpToDate: ec2.CompareTags(cr.Spec.ForProvider.Tags, observed.Tags),
146146
}, nil
147147
}
148148

0 commit comments

Comments
 (0)