Skip to content

Commit 3e62fbf

Browse files
committed
Add test for provider-managed infrastructure, fix writing latest status back into ClusterScope
1 parent 50a7f5b commit 3e62fbf

File tree

11 files changed

+695
-31
lines changed

11 files changed

+695
-31
lines changed

api/v1beta2/network_types.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,13 @@ func (s Subnets) IDs() []string {
457457
}
458458

459459
// FindByID returns a single subnet matching the given id or nil.
460+
//
461+
// The returned pointer can be used to write back into the original slice.
460462
func (s Subnets) FindByID(id string) *SubnetSpec {
461-
for _, x := range s {
463+
for i := range s {
464+
x := &(s[i]) // pointer to original structure
462465
if x.GetResourceID() == id {
463-
return &x
466+
return x
464467
}
465468
}
466469
return nil
@@ -469,12 +472,15 @@ func (s Subnets) FindByID(id string) *SubnetSpec {
469472
// FindEqual returns a subnet spec that is equal to the one passed in.
470473
// Two subnets are defined equal to each other if their id is equal
471474
// or if they are in the same vpc and the cidr block is the same.
475+
//
476+
// The returned pointer can be used to write back into the original slice.
472477
func (s Subnets) FindEqual(spec *SubnetSpec) *SubnetSpec {
473-
for _, x := range s {
478+
for i := range s {
479+
x := &(s[i]) // pointer to original structure
474480
if (spec.GetResourceID() != "" && x.GetResourceID() == spec.GetResourceID()) ||
475481
(spec.CidrBlock == x.CidrBlock) ||
476482
(spec.IPv6CidrBlock != "" && spec.IPv6CidrBlock == x.IPv6CidrBlock) {
477-
return &x
483+
return x
478484
}
479485
}
480486
return nil

cmd/clusterawsadm/converters/cloudformation.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package converters
1818

1919
import (
20+
"sort"
21+
2022
"github.com/awslabs/goformation/v4/cloudformation/tags"
2123

2224
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -35,5 +37,8 @@ func MapToCloudFormationTags(src infrav1.Tags) []tags.Tag {
3537
cfnTags = append(cfnTags, tag)
3638
}
3739

40+
// Sort so that unit tests can expect a stable order
41+
sort.Slice(cfnTags, func(i, j int) bool { return cfnTags[i].Key < cfnTags[j].Key })
42+
3843
return cfnTags
3944
}

0 commit comments

Comments
 (0)