Skip to content

Commit 349bf97

Browse files
authored
feat: add VPC ID and Subnet IDs patch (#220)
Fixes #201 Fixes #200 Depends on #219 Tested manually (at-least that the values are set in `AWSCluster`) ``` apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster metadata: name: <NAME> spec: topology: variables: - name: clusterConfig value: aws: network: vpc: id: vpc-1234567890 subnets: - id: subnet-1 - id: subnet-2 - id: subnet-3 ``` This is what the `AWSCluster` looked like: ``` spec: network: subnets: - id: subnet-1 isPublic: false - id: subnet-2 isPublic: false - id: subnet-3 isPublic: false vpc: availabilityZoneSelection: Ordered availabilityZoneUsageLimit: 3 id: vpc-1234567890 region: us-west-2 ```
1 parent f1ba6bb commit 349bf97

File tree

25 files changed

+550
-46
lines changed

25 files changed

+550
-46
lines changed

api/v1alpha1/aws_clusterconfig_types.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type AWSSpec struct {
1111
// AWS region to create cluster in.
1212
// +optional
1313
Region *Region `json:"region,omitempty"`
14+
// +optional
15+
Network *AWSNetwork `json:"network,omitempty"`
1416
}
1517

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

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ package v1alpha1
66
const (
77
// CNIVariableName is the external patch variable name.
88
CNIVariableName = "cni"
9+
// AWSVariableName is the AWS config patch variable name.
10+
AWSVariableName = "aws"
911
)

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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
spec:
58+
network:
59+
subnets:
60+
- id: subnet-1
61+
- id: subnet-2
62+
- id: subnet-3
63+
vpc:
64+
id: vpc-1234567890
65+
```

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/mutation/ami/inject_control_plane.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
package ami
55

66
import (
7-
_ "embed"
8-
7+
"github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1"
98
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches/selectors"
109
capav1 "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
11-
awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig"
1210
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig"
1311
)
1412

@@ -17,7 +15,7 @@ func NewControlPlanePatch() *awsAMISpecPatchHandler {
1715
clusterconfig.MetaVariableName,
1816
[]string{
1917
clusterconfig.MetaControlPlaneConfigName,
20-
awsclusterconfig.AWSVariableName,
18+
v1alpha1.AWSVariableName,
2119
VariableName,
2220
},
2321
selectors.InfrastructureControlPlaneMachines(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
package ami
44

55
import (
6+
"github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1"
67
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches/selectors"
78
capav1 "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
8-
awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig"
99
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/workerconfig"
1010
)
1111

1212
func NewWorkerPatch() *awsAMISpecPatchHandler {
1313
return newAWSAMISpecPatchHandler(
1414
workerconfig.MetaVariableName,
1515
[]string{
16-
awsclusterconfig.AWSVariableName,
16+
v1alpha1.AWSVariableName,
1717
VariableName,
1818
},
1919
selectors.InfrastructureWorkerMachineTemplates(

pkg/handlers/aws/mutation/cni/calico/inject.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package calico
55

66
import (
77
"context"
8-
_ "embed"
98
"slices"
109

1110
"github.com/go-logr/logr"

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package iaminstanceprofile
55

66
import (
77
"context"
8-
_ "embed"
98

109
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1110
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -18,7 +17,6 @@ import (
1817
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches/selectors"
1918
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
2019
capav1 "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
21-
awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig"
2220
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig"
2321
)
2422

@@ -36,7 +34,7 @@ func NewControlPlanePatch() *awsIAMInstanceProfileControlPlanePatchHandler {
3634
return newAWSIAMInstanceProfileControlPlanePatchHandler(
3735
clusterconfig.MetaVariableName,
3836
clusterconfig.MetaControlPlaneConfigName,
39-
awsclusterconfig.AWSVariableName,
37+
v1alpha1.AWSVariableName,
4038
VariableName,
4139
)
4240
}

0 commit comments

Comments
 (0)