Skip to content

Commit

Permalink
Add test for provider-managed infrastructure, fix writing latest stat…
Browse files Browse the repository at this point in the history
…us back into `ClusterScope`
  • Loading branch information
AndiDog committed Feb 8, 2023
1 parent ce645ad commit 407bd98
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 28 deletions.
16 changes: 10 additions & 6 deletions api/v1beta2/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,12 @@ func (s Subnets) IDs() []string {
}

// FindByID returns a single subnet matching the given id or nil.
func (s Subnets) FindByID(id string) *SubnetSpec {
for _, x := range s {
//
// The returned pointer can be used to write back into the original slice.
func (s *Subnets) FindByID(id string) *SubnetSpec {
for i, x := range *s {
if x.ID == id {
return &x
return &(*s)[i] // pointer to original structure
}
}

Expand All @@ -384,10 +386,12 @@ func (s Subnets) FindByID(id string) *SubnetSpec {
// FindEqual returns a subnet spec that is equal to the one passed in.
// Two subnets are defined equal to each other if their id is equal
// or if they are in the same vpc and the cidr block is the same.
func (s Subnets) FindEqual(spec *SubnetSpec) *SubnetSpec {
for _, x := range s {
//
// The returned pointer can be used to write back into the original slice.
func (s *Subnets) FindEqual(spec *SubnetSpec) *SubnetSpec {
for i, x := range *s {
if (spec.ID != "" && x.ID == spec.ID) || (spec.CidrBlock == x.CidrBlock) || (spec.IPv6CidrBlock != "" && spec.IPv6CidrBlock == x.IPv6CidrBlock) {
return &x
return &(*s)[i] // pointer to original structure
}
}
return nil
Expand Down
5 changes: 5 additions & 0 deletions cmd/clusterawsadm/converters/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package converters

import (
"sort"

"github.com/awslabs/goformation/v4/cloudformation/tags"

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

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

return cfnTags
}

0 comments on commit 407bd98

Please sign in to comment.