Skip to content

Commit

Permalink
Merge pull request #4637 from AndiDog/managed-subnet-test
Browse files Browse the repository at this point in the history
✨ Add test for provider-managed infrastructure, fix writing latest status back into `ClusterScope`
  • Loading branch information
k8s-ci-robot committed Feb 20, 2024
2 parents 3cfa2a8 + 3e62fbf commit bf0cabd
Show file tree
Hide file tree
Showing 11 changed files with 695 additions and 31 deletions.
14 changes: 10 additions & 4 deletions api/v1beta2/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,13 @@ func (s Subnets) IDs() []string {
}

// FindByID returns a single subnet matching the given id or nil.
//
// The returned pointer can be used to write back into the original slice.
func (s Subnets) FindByID(id string) *SubnetSpec {
for _, x := range s {
for i := range s {
x := &(s[i]) // pointer to original structure
if x.GetResourceID() == id {
return &x
return x
}
}
return nil
Expand All @@ -469,12 +472,15 @@ 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.
//
// The returned pointer can be used to write back into the original slice.
func (s Subnets) FindEqual(spec *SubnetSpec) *SubnetSpec {
for _, x := range s {
for i := range s {
x := &(s[i]) // pointer to original structure
if (spec.GetResourceID() != "" && x.GetResourceID() == spec.GetResourceID()) ||
(spec.CidrBlock == x.CidrBlock) ||
(spec.IPv6CidrBlock != "" && spec.IPv6CidrBlock == x.IPv6CidrBlock) {
return &x
return x
}
}
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 bf0cabd

Please sign in to comment.