Skip to content

Commit 9534ec4

Browse files
committed
Feature #4784: SubnetSchema support
1 parent 6e43273 commit 9534ec4

12 files changed

+876
-12
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
104104
dst.Spec.NetworkSpec.VPC.EmptyRoutesDefaultVPCSecurityGroup = restored.Spec.NetworkSpec.VPC.EmptyRoutesDefaultVPCSecurityGroup
105105
dst.Spec.NetworkSpec.VPC.PrivateDNSHostnameTypeOnLaunch = restored.Spec.NetworkSpec.VPC.PrivateDNSHostnameTypeOnLaunch
106106
dst.Spec.NetworkSpec.VPC.CarrierGatewayID = restored.Spec.NetworkSpec.VPC.CarrierGatewayID
107+
dst.Spec.NetworkSpec.VPC.SubnetSchema = restored.Spec.NetworkSpec.VPC.SubnetSchema
107108

108109
if restored.Spec.NetworkSpec.VPC.ElasticIPPool != nil {
109110
if dst.Spec.NetworkSpec.VPC.ElasticIPPool == nil {

api/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awscluster_webhook_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ func TestAWSClusterDefaultCNIIngressRules(t *testing.T) {
10621062
defaultVPCSpec := VPCSpec{
10631063
AvailabilityZoneUsageLimit: &AZUsageLimit,
10641064
AvailabilityZoneSelection: &AZSelectionSchemeOrdered,
1065+
SubnetSchema: &SubnetSchemaPreferPrivate,
10651066
}
10661067
g := NewWithT(t)
10671068
tests := []struct {

api/v1beta2/network_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,16 @@ type VPCSpec struct {
461461
// the API Server.
462462
// +optional
463463
ElasticIPPool *ElasticIPPool `json:"elasticIpPool,omitempty"`
464+
465+
// SubnetSchema specifies how CidrBlock should be divided on subnets in the VPC depending on the number of AZs.
466+
// PreferPrivate - one private subnet for each AZ plus one other subnet that will be further sub-divided for the public subnets.
467+
// PreferPublic - have the reverse logic of PreferPrivate, one public subnet for each AZ plus one other subnet
468+
// that will be further sub-divided for the private subnets.
469+
// Defaults to PreferPrivate
470+
// +optional
471+
// +kubebuilder:default=PreferPrivate
472+
// +kubebuilder:validation:Enum=PreferPrivate;PreferPublic
473+
SubnetSchema *SubnetSchemaType `json:"subnetSchema,omitempty"`
464474
}
465475

466476
// String returns a string representation of the VPC.

api/v1beta2/types.go

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

1919
import (
20+
"strings"
21+
2022
"k8s.io/apimachinery/pkg/util/sets"
2123

2224
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -439,3 +441,19 @@ type PrivateDNSName struct {
439441
// +kubebuilder:validation:Enum:=ip-name;resource-name
440442
HostnameType *string `json:"hostnameType,omitempty"`
441443
}
444+
445+
// SubnetSchemaType specifies how given network should be divided on subnets
446+
// in the VPC depending on the number of AZs.
447+
type SubnetSchemaType string
448+
449+
// Name returns subnet schema type name without prefix.
450+
func (s *SubnetSchemaType) Name() string {
451+
return strings.ToLower(strings.TrimPrefix(string(*s), "Prefer"))
452+
}
453+
454+
var (
455+
// SubnetSchemaPreferPrivate allocates more subnets in the VPC to private subnets.
456+
SubnetSchemaPreferPrivate = SubnetSchemaType("PreferPrivate")
457+
// SubnetSchemaPreferPublic allocates more subnets in the VPC to public subnets.
458+
SubnetSchemaPreferPublic = SubnetSchemaType("PreferPublic")
459+
)

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,18 @@ spec:
759759
- ip-name
760760
- resource-name
761761
type: string
762+
subnetSchema:
763+
default: PreferPrivate
764+
description: |-
765+
SubnetSchema specifies how CidrBlock should be divided on subnets in the VPC depending on the number of AZs.
766+
PreferPrivate - one private subnet for each AZ plus one other subnet that will be further sub-divided for the public subnets.
767+
PreferPublic - have the reverse logic of PreferPrivate, one public subnet for each AZ plus one other subnet
768+
that will be further sub-divided for the private subnets.
769+
Defaults to PreferPrivate
770+
enum:
771+
- PreferPrivate
772+
- PreferPublic
773+
type: string
762774
tags:
763775
additionalProperties:
764776
type: string
@@ -2750,6 +2762,18 @@ spec:
27502762
- ip-name
27512763
- resource-name
27522764
type: string
2765+
subnetSchema:
2766+
default: PreferPrivate
2767+
description: |-
2768+
SubnetSchema specifies how CidrBlock should be divided on subnets in the VPC depending on the number of AZs.
2769+
PreferPrivate - one private subnet for each AZ plus one other subnet that will be further sub-divided for the public subnets.
2770+
PreferPublic - have the reverse logic of PreferPrivate, one public subnet for each AZ plus one other subnet
2771+
that will be further sub-divided for the private subnets.
2772+
Defaults to PreferPrivate
2773+
enum:
2774+
- PreferPrivate
2775+
- PreferPublic
2776+
type: string
27532777
tags:
27542778
additionalProperties:
27552779
type: string

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,18 @@ spec:
16991699
- ip-name
17001700
- resource-name
17011701
type: string
1702+
subnetSchema:
1703+
default: PreferPrivate
1704+
description: |-
1705+
SubnetSchema specifies how CidrBlock should be divided on subnets in the VPC depending on the number of AZs.
1706+
PreferPrivate - one private subnet for each AZ plus one other subnet that will be further sub-divided for the public subnets.
1707+
PreferPublic - have the reverse logic of PreferPrivate, one public subnet for each AZ plus one other subnet
1708+
that will be further sub-divided for the private subnets.
1709+
Defaults to PreferPrivate
1710+
enum:
1711+
- PreferPrivate
1712+
- PreferPublic
1713+
type: string
17021714
tags:
17031715
additionalProperties:
17041716
type: string

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclustertemplates.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,18 @@ spec:
12981298
- ip-name
12991299
- resource-name
13001300
type: string
1301+
subnetSchema:
1302+
default: PreferPrivate
1303+
description: |-
1304+
SubnetSchema specifies how CidrBlock should be divided on subnets in the VPC depending on the number of AZs.
1305+
PreferPrivate - one private subnet for each AZ plus one other subnet that will be further sub-divided for the public subnets.
1306+
PreferPublic - have the reverse logic of PreferPrivate, one public subnet for each AZ plus one other subnet
1307+
that will be further sub-divided for the private subnets.
1308+
Defaults to PreferPrivate
1309+
enum:
1310+
- PreferPrivate
1311+
- PreferPublic
1312+
type: string
13011313
tags:
13021314
additionalProperties:
13031315
type: string

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestDefaultingWebhook(t *testing.T) {
4545
defaultVPCSpec := infrav1.VPCSpec{
4646
AvailabilityZoneUsageLimit: &AZUsageLimit,
4747
AvailabilityZoneSelection: &infrav1.AZSelectionSchemeOrdered,
48+
SubnetSchema: &infrav1.SubnetSchemaPreferPrivate,
4849
}
4950
defaultIdentityRef := &infrav1.AWSIdentityReference{
5051
Kind: infrav1.ControllerIdentityKind,

0 commit comments

Comments
 (0)