Skip to content

Commit f6d1158

Browse files
committed
feat: add VPC ID and Subnet IDs patch
1 parent f09ef9e commit f6d1158

File tree

18 files changed

+557
-28
lines changed

18 files changed

+557
-28
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: 79 additions & 0 deletions
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
@@ -52,5 +52,48 @@ func TestVariableValidation(t *testing.T) {
5252
},
5353
},
5454
},
55+
capitest.VariableTestDef{
56+
Name: "specified VPC ID",
57+
Vals: v1alpha1.ClusterConfigSpec{
58+
AWS: &v1alpha1.AWSSpec{
59+
Network: &v1alpha1.AWSNetwork{
60+
VPC: &v1alpha1.VPC{
61+
ID: "vpc-1234",
62+
},
63+
},
64+
},
65+
},
66+
},
67+
capitest.VariableTestDef{
68+
Name: "specified subnet IDs",
69+
Vals: v1alpha1.ClusterConfigSpec{
70+
AWS: &v1alpha1.AWSSpec{
71+
Network: &v1alpha1.AWSNetwork{
72+
Subnets: v1alpha1.Subnets{
73+
{ID: "subnet-1"},
74+
{ID: "subnet-2"},
75+
{ID: "subnet-3"},
76+
},
77+
},
78+
},
79+
},
80+
},
81+
capitest.VariableTestDef{
82+
Name: "specified both VPC ID and subnet IDs",
83+
Vals: v1alpha1.ClusterConfigSpec{
84+
AWS: &v1alpha1.AWSSpec{
85+
Network: &v1alpha1.AWSNetwork{
86+
VPC: &v1alpha1.VPC{
87+
ID: "vpc-1234",
88+
},
89+
Subnets: v1alpha1.Subnets{
90+
{ID: "subnet-1"},
91+
{ID: "subnet-2"},
92+
{ID: "subnet-3"},
93+
},
94+
},
95+
},
96+
},
97+
},
5598
)
5699
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
2222
capav1 "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2323
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers"
24-
awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig"
2524
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig"
2625
)
2726

@@ -48,7 +47,7 @@ func NewControlPlaneMetaPatch() *awsIAMInstanceProfileControlPlanePatchHandler {
4847
return newAWSIAMInstanceProfileControlPlanePatchHandler(
4948
clusterconfig.MetaVariableName,
5049
clusterconfig.MetaControlPlaneConfigName,
51-
awsclusterconfig.AWSVariableName,
50+
v1alpha1.AWSVariableName,
5251
VariableName,
5352
)
5453
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
2222
capav1 "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2323
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers"
24-
awsworkerconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/workerconfig"
2524
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/workerconfig"
2625
)
2726

@@ -44,7 +43,7 @@ var (
4443
func NewWorkerMetaPatch() *awsIAMInstanceProfileWorkerPatchHandler {
4544
return newAWSIAMInstanceProfileWorkerPatchHandler(
4645
workerconfig.MetaVariableName,
47-
awsworkerconfig.AWSVariableName,
46+
v1alpha1.AWSVariableName,
4847
VariableName,
4948
)
5049
}

0 commit comments

Comments
 (0)