Skip to content

Commit 41e5ef6

Browse files
committed
feat: add VPC ID and Subnet IDs patch
1 parent 1fd3181 commit 41e5ef6

File tree

17 files changed

+566
-32
lines changed

17 files changed

+566
-32
lines changed

api/v1alpha1/aws_clusterconfig_types.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
type AWSSpec struct {
1111
// +optional
1212
Region *Region `json:"region,omitempty"`
13+
// +optional
14+
Network *AWSNetwork `json:"network,omitempty"`
1315
}
1416

1517
func (AWSSpec) VariableSchema() clusterv1.VariableSchema {
@@ -18,7 +20,8 @@ func (AWSSpec) VariableSchema() clusterv1.VariableSchema {
1820
Description: "AWS cluster configuration",
1921
Type: "object",
2022
Properties: map[string]clusterv1.JSONSchemaProps{
21-
"region": Region("").VariableSchema().OpenAPIV3Schema,
23+
"region": Region("").VariableSchema().OpenAPIV3Schema,
24+
"network": AWSNetwork{}.VariableSchema().OpenAPIV3Schema,
2225
},
2326
},
2427
}
@@ -29,8 +32,84 @@ type Region string
2932
func (Region) VariableSchema() clusterv1.VariableSchema {
3033
return clusterv1.VariableSchema{
3134
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
32-
Type: "string",
3335
Description: "AWS region to create cluster in",
36+
Type: "string",
37+
},
38+
}
39+
}
40+
41+
type AWSNetwork struct {
42+
// +optional
43+
VPC *VPC `json:"vpc,omitempty"`
44+
45+
// +optional
46+
Subnets Subnets `json:"subnets,omitempty"`
47+
}
48+
49+
func (AWSNetwork) VariableSchema() clusterv1.VariableSchema {
50+
return clusterv1.VariableSchema{
51+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
52+
Description: "AWS network configuration",
53+
Type: "object",
54+
Properties: map[string]clusterv1.JSONSchemaProps{
55+
"vpc": VPC{}.VariableSchema().OpenAPIV3Schema,
56+
"subnets": Subnets{}.VariableSchema().OpenAPIV3Schema,
57+
},
58+
},
59+
}
60+
}
61+
62+
type VPC struct {
63+
// ID is the vpc-id of the VPC this provider should use to create resources.
64+
ID string `json:"id,omitempty"`
65+
}
66+
67+
func (VPC) VariableSchema() clusterv1.VariableSchema {
68+
return clusterv1.VariableSchema{
69+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
70+
Description: "AWS VPC configuration",
71+
Type: "object",
72+
Properties: map[string]clusterv1.JSONSchemaProps{
73+
"id": {
74+
Description: "Existing VPC ID to use for the cluster",
75+
Type: "string",
76+
},
77+
},
78+
},
79+
}
80+
}
81+
82+
type Subnets []SubnetSpec
83+
84+
func (Subnets) VariableSchema() clusterv1.VariableSchema {
85+
resourceSchema := SubnetSpec{}.VariableSchema().OpenAPIV3Schema
86+
87+
return clusterv1.VariableSchema{
88+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
89+
Description: "AWS Subnet configurations",
90+
Type: "array",
91+
Items: &resourceSchema,
92+
},
93+
}
94+
}
95+
96+
// SubnetSpec configures an AWS Subnet.
97+
type SubnetSpec struct {
98+
// ID defines a unique identifier to reference this resource.
99+
ID string `json:"id"`
100+
}
101+
102+
func (SubnetSpec) VariableSchema() clusterv1.VariableSchema {
103+
return clusterv1.VariableSchema{
104+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
105+
Description: "An AWS Subnet configuration",
106+
Type: "object",
107+
Properties: map[string]clusterv1.JSONSchemaProps{
108+
"id": {
109+
Description: "Existing Subnet ID to use for the cluster",
110+
Type: "string",
111+
},
112+
},
34113
},
35114
}
36115
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
5151
maps.Copy(
5252
clusterConfigProps.OpenAPIV3Schema.Properties,
5353
map[string]clusterv1.JSONSchemaProps{
54-
"aws": AWSSpec{}.VariableSchema().OpenAPIV3Schema,
54+
AWSVariableName: AWSSpec{}.VariableSchema().OpenAPIV3Schema,
5555
"controlPlane": NodeConfigSpec{
5656
AWS: &AWSNodeSpec{},
5757
}.VariableSchema().OpenAPIV3Schema,

api/v1alpha1/constants.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
const (
7+
// AWSVariableName is the AWS config patch variable name.
8+
AWSVariableName = "aws"
9+
)

api/v1alpha1/node_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
3939
maps.Copy(
4040
nodeConfigProps.OpenAPIV3Schema.Properties,
4141
map[string]clusterv1.JSONSchemaProps{
42-
"aws": AWSNodeSpec{}.VariableSchema().OpenAPIV3Schema,
42+
AWSVariableName: AWSNodeSpec{}.VariableSchema().OpenAPIV3Schema,
4343
},
4444
)
4545
case s.Docker != nil:

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 80 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
+++
2+
title = "Network"
3+
+++
4+
5+
The network customization allows the user to specify existing infrastructure to use for the cluster.
6+
7+
This customization will be available when the
8+
[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`.
9+
10+
## Example
11+
12+
To specify existing AWS VPC, use the following configuration:
13+
14+
```yaml
15+
apiVersion: cluster.x-k8s.io/v1beta1
16+
kind: Cluster
17+
metadata:
18+
name: <NAME>
19+
spec:
20+
topology:
21+
variables:
22+
- name: clusterConfig
23+
value:
24+
aws:
25+
network:
26+
vpc:
27+
id: vpc-1234567890
28+
```
29+
30+
To also specify existing AWS Subnets, use the following configuration:
31+
32+
```yaml
33+
apiVersion: cluster.x-k8s.io/v1beta1
34+
kind: Cluster
35+
metadata:
36+
name: <NAME>
37+
spec:
38+
topology:
39+
variables:
40+
- name: clusterConfig
41+
value:
42+
aws:
43+
network:
44+
vpc:
45+
id: vpc-1234567890
46+
subnets:
47+
- id: subnet-1
48+
- id: subnet-2
49+
- id: subnet-3
50+
```
51+
52+
Applying this configuration will result in the following value being set:
53+
54+
- `AWSClusterTemplate`:
55+
56+
- ```yaml
57+
network:
58+
subnets:
59+
- id: subnet-1
60+
- id: subnet-2
61+
- id: subnet-3
62+
vpc:
63+
id: vpc-1234567890
64+
```

pkg/handlers/aws/clusterconfig/variables.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ var (
2323
const (
2424
// HandlerNameVariable is the name of the variable handler.
2525
HandlerNameVariable = "AWSClusterConfigVars"
26-
27-
// AWSVariableName is the AWS config patch variable name.
28-
AWSVariableName = "aws"
2926
)
3027

3128
func NewVariable() *awsClusterConfigVariableHandler {

pkg/handlers/aws/clusterconfig/variables_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,48 @@ func TestVariableValidation(t *testing.T) {
4242
},
4343
},
4444
},
45+
capitest.VariableTestDef{
46+
Name: "specified VPC ID",
47+
Vals: v1alpha1.ClusterConfigSpec{
48+
AWS: &v1alpha1.AWSSpec{
49+
Network: &v1alpha1.AWSNetwork{
50+
VPC: &v1alpha1.VPC{
51+
ID: "vpc-1234",
52+
},
53+
},
54+
},
55+
},
56+
},
57+
capitest.VariableTestDef{
58+
Name: "specified subnet IDs",
59+
Vals: v1alpha1.ClusterConfigSpec{
60+
AWS: &v1alpha1.AWSSpec{
61+
Network: &v1alpha1.AWSNetwork{
62+
Subnets: v1alpha1.Subnets{
63+
{ID: "subnet-1"},
64+
{ID: "subnet-2"},
65+
{ID: "subnet-3"},
66+
},
67+
},
68+
},
69+
},
70+
},
71+
capitest.VariableTestDef{
72+
Name: "specified both VPC ID and subnet IDs",
73+
Vals: v1alpha1.ClusterConfigSpec{
74+
AWS: &v1alpha1.AWSSpec{
75+
Network: &v1alpha1.AWSNetwork{
76+
VPC: &v1alpha1.VPC{
77+
ID: "vpc-1234",
78+
},
79+
Subnets: v1alpha1.Subnets{
80+
{ID: "subnet-1"},
81+
{ID: "subnet-2"},
82+
{ID: "subnet-3"},
83+
},
84+
},
85+
},
86+
},
87+
},
4588
)
4689
}

pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
2323
capav1 "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2424
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers"
25-
awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig"
2625
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig"
2726
)
2827

2928
const (
29+
// VariableName is the external patch variable name.
30+
VariableName = "iamInstanceProfile"
31+
3032
// ControlPlaneHandlerNamePatch is the name of the inject handler.
3133
ControlPlaneHandlerNamePatch = "AWSIAMInstanceProfileControlPlanePatch"
3234
)
@@ -46,7 +48,7 @@ func NewControlPlaneMetaPatch() *awsIAMInstanceProfileControlPlanePatchHandler {
4648
return newAWSIAMInstanceProfileControlPlanePatchHandler(
4749
clusterconfig.MetaVariableName,
4850
clusterconfig.MetaControlPlaneConfigName,
49-
awsclusterconfig.AWSVariableName,
51+
v1alpha1.AWSVariableName,
5052
VariableName,
5153
)
5254
}

0 commit comments

Comments
 (0)