Skip to content

Commit

Permalink
Merge pull request #437 from giantswarm/workaround-for-managed-subnets
Browse files Browse the repository at this point in the history
Workaround to get managed subnets working again
  • Loading branch information
AndiDog authored Feb 15, 2023
2 parents 94fb8c6 + 407bd98 commit 3ac448c
Show file tree
Hide file tree
Showing 20 changed files with 781 additions and 51 deletions.
20 changes: 11 additions & 9 deletions api/v1beta2/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (v *VPCSpec) IsIPv6Enabled() bool {
// SubnetSpec configures an AWS Subnet.
type SubnetSpec struct {
// ID defines a unique identifier to reference this resource.
ID string `json:"id"`
ID string `json:"id,omitempty"`

// CidrBlock is the CIDR block to be used when the provider creates a managed VPC.
CidrBlock string `json:"cidrBlock,omitempty"`
Expand Down Expand Up @@ -349,8 +349,6 @@ func (s *SubnetSpec) String() string {
}

// Subnets is a slice of Subnet.
// +listType=map
// +listMapKey=id
type Subnets []SubnetSpec

// ToMap returns a map from id to subnet.
Expand All @@ -373,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 @@ -386,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
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,8 @@ spec:
description: Tags is a collection of tags describing the
resource.
type: object
required:
- id
type: object
type: array
x-kubernetes-list-map-keys:
- id
x-kubernetes-list-type: map
vpc:
description: VPC configuration.
properties:
Expand Down Expand Up @@ -1802,13 +1797,8 @@ spec:
description: Tags is a collection of tags describing the
resource.
type: object
required:
- id
type: object
type: array
x-kubernetes-list-map-keys:
- id
x-kubernetes-list-type: map
vpc:
description: VPC configuration.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,13 +1173,8 @@ spec:
description: Tags is a collection of tags describing the
resource.
type: object
required:
- id
type: object
type: array
x-kubernetes-list-map-keys:
- id
x-kubernetes-list-type: map
vpc:
description: VPC configuration.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,8 @@ spec:
description: Tags is a collection of tags describing
the resource.
type: object
required:
- id
type: object
type: array
x-kubernetes-list-map-keys:
- id
x-kubernetes-list-type: map
vpc:
description: VPC configuration.
properties:
Expand Down
Loading

0 comments on commit 3ac448c

Please sign in to comment.