Skip to content

Commit

Permalink
add option for all subnets in az
Browse files Browse the repository at this point in the history
Signed-off-by: David van der Spek <vanderspek.david@gmail.com>
  • Loading branch information
davidspek committed Sep 1, 2023
1 parent 8bb961c commit 10d8620
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ spec:
enum:
- public
- private
- all
type: string
availabilityZones:
description: AvailabilityZones is an array of availability zones instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ spec:
enum:
- public
- private
- all
type: string
availabilityZones:
description: AvailabilityZones is an array of availability zones instances
Expand Down
6 changes: 0 additions & 6 deletions exp/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
}
dst.Spec.AWSLaunchTemplate.InstanceMetadataOptions = restored.Spec.AWSLaunchTemplate.InstanceMetadataOptions
}

// Manually restore data.
restored := &infrav1exp.AWSManagedMachinePool{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}
if restored.Spec.AvailabilityZoneSubnetType != nil {
dst.Spec.AvailabilityZoneSubnetType = restored.Spec.AvailabilityZoneSubnetType
}
Expand Down
2 changes: 1 addition & 1 deletion exp/api/v1beta2/awsmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type AWSMachinePoolSpec struct {
AvailabilityZones []string `json:"availabilityZones,omitempty"`

// AvailabilityZoneSubnetType specifies which type of subnets to use when an availability zone is specified.
// +kubebuilder:validation:Enum:=public;private
// +kubebuilder:validation:Enum:=public;private;all
// +optional
AvailabilityZoneSubnetType *AZSubnetType `json:"availabilityZoneSubnetType,omitempty"`

Expand Down
2 changes: 1 addition & 1 deletion exp/api/v1beta2/awsmanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type AWSManagedMachinePoolSpec struct {
AvailabilityZones []string `json:"availabilityZones,omitempty"`

// AvailabilityZoneSubnetType specifies which type of subnets to use when an availability zone is specified.
// +kubebuilder:validation:Enum:=public;private
// +kubebuilder:validation:Enum:=public;private;all
// +optional
AvailabilityZoneSubnetType *AZSubnetType `json:"availabilityZoneSubnetType,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions exp/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ const (
AZSubnetTypePublic AZSubnetType = "public"
// AZSubnetTypePrivate is a private subnet.
AZSubnetTypePrivate AZSubnetType = "private"
// AZSubnetTypeAll is all subnets in an availability zone.
AZSubnetTypeAll AZSubnetType = "all"
)

// NewAZSubnetType returns a pointer to an AZSubnetType.
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloud/scope/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (p *defaultSubnetPlacementStrategy) getSubnetsForAZs(azs []string, controlP
subnets := controlPlaneSubnets.FilterByZone(zone)
if placementType != nil {
switch *placementType {
case expinfrav1.AZSubnetTypeAll:
// no-op
case expinfrav1.AZSubnetTypePublic:
subnets = subnets.FilterPublic()
case expinfrav1.AZSubnetTypePrivate:
Expand Down
74 changes: 74 additions & 0 deletions pkg/cloud/scope/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,43 @@ func TestSubnetPlacement(t *testing.T) {
expectedSubnetIDs: []string{"az2"},
expectError: false,
},
{
name: "spec all azs expected",
specSubnetIDs: []string{},
specAZs: []string{"eu-west-1b"},
parentAZs: []string{"eu-west-1c"},
subnetPlacementType: expinfrav1.NewAZSubnetType(expinfrav1.AZSubnetTypeAll),
controlPlaneSubnets: infrav1.Subnets{
infrav1.SubnetSpec{
ID: "az1",
AvailabilityZone: "eu-west-1a",
IsPublic: false,
},
infrav1.SubnetSpec{
ID: "az2",
AvailabilityZone: "eu-west-1b",
IsPublic: true,
},
infrav1.SubnetSpec{
ID: "az3",
AvailabilityZone: "eu-west-1b",
IsPublic: false,
},
infrav1.SubnetSpec{
ID: "az4",
AvailabilityZone: "eu-west-1c",
IsPublic: true,
},
infrav1.SubnetSpec{
ID: "az5",
AvailabilityZone: "eu-west-1c",
IsPublic: false,
},
},
logger: logger.NewLogger(klog.Background()),
expectedSubnetIDs: []string{"az2", "az3"},
expectError: false,
},
{
name: "spec public no azs found",
specSubnetIDs: []string{},
Expand Down Expand Up @@ -335,6 +372,43 @@ func TestSubnetPlacement(t *testing.T) {
expectedSubnetIDs: []string{"az4"},
expectError: false,
},
{
name: "parent all azs expected",
specSubnetIDs: []string{},
specAZs: []string{},
parentAZs: []string{"eu-west-1c"},
subnetPlacementType: expinfrav1.NewAZSubnetType(expinfrav1.AZSubnetTypeAll),
controlPlaneSubnets: infrav1.Subnets{
infrav1.SubnetSpec{
ID: "az1",
AvailabilityZone: "eu-west-1a",
IsPublic: false,
},
infrav1.SubnetSpec{
ID: "az2",
AvailabilityZone: "eu-west-1b",
IsPublic: true,
},
infrav1.SubnetSpec{
ID: "az3",
AvailabilityZone: "eu-west-1b",
IsPublic: false,
},
infrav1.SubnetSpec{
ID: "az4",
AvailabilityZone: "eu-west-1c",
IsPublic: true,
},
infrav1.SubnetSpec{
ID: "az5",
AvailabilityZone: "eu-west-1c",
IsPublic: false,
},
},
logger: logger.NewLogger(klog.Background()),
expectedSubnetIDs: []string{"az4", "az5"},
expectError: false,
},
{
name: "use control plane subnets",
specSubnetIDs: []string{},
Expand Down

0 comments on commit 10d8620

Please sign in to comment.