Skip to content

Commit 64e6e72

Browse files
authored
fix: set defaults for AWS CP and Worker instanceType (#504)
Moved d2iq-labs#51 Addressed the pending review comments **What problem does this PR solve?:** - sets defaults for aws nodes CP: m5.xlarge and Workers: m5.2xlarge - sets PLACEHOLDER value as defaults in AWSMachineTemplates because instanceType field is required by CAPA. - sets instance type as required field in the schema since CAREN will be using the default if not provided by the user. update existing unit tests to use default schema **NOTE** Once this PR is finalized, I will create follow up PR to set instance profile and some other changes in the API types that would ensure that it creates variable schema from the object instead of creating new one. **Which issue(s) this PR fixes:** Fixes # #485 **How Has This Been Tested?:** Tried to test locally using make e2e-test E2E_LABEL='provider:AWS && cni:Cilium' but local environment timed outs during initializations. Looking into fixing local environment (colima +docker +kind on mac) Tested manually be creating AWS cluster. aws-quick-start cluster class has following ``` instanceType: default: m5.xlarge description: The AWS instance type to use for the cluster Machines type: string required: - instanceType ``` and workers ``` instanceType: default: m5.2xlarge description: The AWS instance type to use for the cluster Machines type: string required: - instanceType ``` Created AWS cluster without adding instanceType variable, CAREN patched AWSMachineTemplate with default instanceType. ** Special notes for your reviewer:** The approach taken in this PR will be used as guide to set default for other variables.
1 parent 094f26a commit 64e6e72

File tree

15 files changed

+57
-23
lines changed

15 files changed

+57
-23
lines changed

api/v1alpha1/aws_node_types.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ package v1alpha1
55

66
import (
77
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
8+
"k8s.io/utils/ptr"
89
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
10+
11+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
12+
)
13+
14+
const (
15+
AWSControlPlaneInstanceType InstanceType = "m5.xlarge"
16+
AWSWorkerInstanceType InstanceType = "m5.2xlarge"
917
)
1018

1119
type AWSNodeSpec struct {
@@ -24,6 +32,18 @@ type AWSNodeSpec struct {
2432
AdditionalSecurityGroups AdditionalSecurityGroup `json:"additionalSecurityGroups,omitempty"`
2533
}
2634

35+
func NewAWSControlPlaneNodeSpec() *AWSNodeSpec {
36+
return &AWSNodeSpec{
37+
InstanceType: ptr.To(AWSControlPlaneInstanceType),
38+
}
39+
}
40+
41+
func NewAWSWorkerNodeSpec() *AWSNodeSpec {
42+
return &AWSNodeSpec{
43+
InstanceType: ptr.To(AWSWorkerInstanceType),
44+
}
45+
}
46+
2747
type AdditionalSecurityGroup []SecurityGroup
2848

2949
type SecurityGroup struct {
@@ -49,17 +69,18 @@ func (AdditionalSecurityGroup) VariableSchema() clusterv1.VariableSchema {
4969
}
5070
}
5171

52-
func (AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
72+
func (a AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
5373
return clusterv1.VariableSchema{
5474
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
5575
Description: "AWS Node configuration",
5676
Type: "object",
5777
Properties: map[string]clusterv1.JSONSchemaProps{
5878
"iamInstanceProfile": IAMInstanceProfile("").VariableSchema().OpenAPIV3Schema,
59-
"instanceType": InstanceType("").VariableSchema().OpenAPIV3Schema,
79+
"instanceType": a.InstanceType.VariableSchema().OpenAPIV3Schema,
6080
"ami": AMISpec{}.VariableSchema().OpenAPIV3Schema,
6181
"additionalSecurityGroups": AdditionalSecurityGroup{}.VariableSchema().OpenAPIV3Schema,
6282
},
83+
Required: []string{"instanceType"},
6384
},
6485
}
6586
}
@@ -77,11 +98,12 @@ func (IAMInstanceProfile) VariableSchema() clusterv1.VariableSchema {
7798

7899
type InstanceType string
79100

80-
func (InstanceType) VariableSchema() clusterv1.VariableSchema {
101+
func (i InstanceType) VariableSchema() clusterv1.VariableSchema {
81102
return clusterv1.VariableSchema{
82103
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
83104
Type: "string",
84105
Description: "The AWS instance type to use for the cluster Machines",
106+
Default: variables.MustMarshal(i),
85107
},
86108
}
87109
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,13 @@ type ClusterConfigSpec struct {
5757

5858
func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
5959
clusterConfigProps := GenericClusterConfig{}.VariableSchema()
60-
6160
switch {
6261
case s.AWS != nil:
6362
maps.Copy(
6463
clusterConfigProps.OpenAPIV3Schema.Properties,
6564
map[string]clusterv1.JSONSchemaProps{
66-
AWSVariableName: AWSSpec{}.VariableSchema().OpenAPIV3Schema,
67-
"controlPlane": NodeConfigSpec{
68-
AWS: &AWSNodeSpec{},
69-
}.VariableSchema().OpenAPIV3Schema,
65+
AWSVariableName: s.AWS.VariableSchema().OpenAPIV3Schema,
66+
"controlPlane": s.ControlPlane.VariableSchema().OpenAPIV3Schema,
7067
},
7168
)
7269
case s.Docker != nil:
@@ -94,6 +91,15 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
9491
return clusterConfigProps
9592
}
9693

94+
func NewAWSClusterConfigSpec() *ClusterConfigSpec {
95+
return &ClusterConfigSpec{
96+
AWS: &AWSSpec{},
97+
ControlPlane: &NodeConfigSpec{
98+
AWS: NewAWSControlPlaneNodeSpec(),
99+
},
100+
}
101+
}
102+
97103
// GenericClusterConfig defines the generic cluster configdesired.
98104
type GenericClusterConfig struct {
99105
// +optional

api/v1alpha1/node_types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
4141
maps.Copy(
4242
nodeConfigProps.OpenAPIV3Schema.Properties,
4343
map[string]clusterv1.JSONSchemaProps{
44-
AWSVariableName: AWSNodeSpec{}.VariableSchema().OpenAPIV3Schema,
44+
AWSVariableName: s.AWS.VariableSchema().OpenAPIV3Schema,
4545
},
4646
)
4747
case s.Docker != nil:
@@ -63,6 +63,12 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
6363
return nodeConfigProps
6464
}
6565

66+
func NewAWSWorkerConfigSpec() *NodeConfigSpec {
67+
return &NodeConfigSpec{
68+
AWS: NewAWSWorkerNodeSpec(),
69+
}
70+
}
71+
6672
type GenericNodeConfig struct{}
6773

6874
func (GenericNodeConfig) VariableSchema() clusterv1.VariableSchema {

charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/aws-cluster-class.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ spec:
106106
template:
107107
spec:
108108
iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io
109-
instanceType: m5.xlarge
109+
instanceType: PLACEHOLDER
110110
sshKeyName: ""
111111
---
112112
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
@@ -119,7 +119,7 @@ spec:
119119
template:
120120
spec:
121121
iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io
122-
instanceType: m5.2xlarge
122+
instanceType: PLACEHOLDER
123123
sshKeyName: ""
124124
---
125125
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1

hack/examples/overlays/clusterclasses/aws/kustomization.yaml.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ patches:
5151
patch: |-
5252
- op: "add"
5353
path: "/spec/template/spec/instanceType"
54-
value: "m5.2xlarge"
54+
value: "PLACEHOLDER"
5555
- target:
5656
kind: AWSMachineTemplate
5757
name: quick-start-control-plane
5858
patch: |-
5959
- op: "add"
6060
path: "/spec/template/spec/instanceType"
61-
value: "m5.xlarge"
61+
value: "PLACEHOLDER"

pkg/handlers/aws/clusterconfig/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (h *awsClusterConfigVariableHandler) DiscoverVariables(
4343
resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{
4444
Name: clusterconfig.MetaVariableName,
4545
Required: true,
46-
Schema: v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema(),
46+
Schema: v1alpha1.NewAWSClusterConfigSpec().VariableSchema(),
4747
})
4848
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
4949
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
1818
capitest.ValidateDiscoverVariables(
1919
t,
2020
clusterconfig.MetaVariableName,
21-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
21+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2222
true,
2323
awsclusterconfig.NewVariable,
2424
capitest.VariableTestDef{

pkg/handlers/aws/mutation/controlplaneloadbalancer/variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestVariableValidation(t *testing.T) {
1919
capitest.ValidateDiscoverVariables(
2020
t,
2121
clusterconfig.MetaVariableName,
22-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
22+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2323
true,
2424
awsclusterconfig.NewVariable,
2525
capitest.VariableTestDef{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
1818
capitest.ValidateDiscoverVariables(
1919
t,
2020
clusterconfig.MetaVariableName,
21-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
21+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2222
true,
2323
awsclusterconfig.NewVariable,
2424
capitest.VariableTestDef{

pkg/handlers/aws/mutation/instancetype/variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
1818
capitest.ValidateDiscoverVariables(
1919
t,
2020
clusterconfig.MetaVariableName,
21-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
21+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2222
true,
2323
awsclusterconfig.NewVariable,
2424
capitest.VariableTestDef{

pkg/handlers/aws/mutation/network/variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
1818
capitest.ValidateDiscoverVariables(
1919
t,
2020
clusterconfig.MetaVariableName,
21-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
21+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2222
true,
2323
awsclusterconfig.NewVariable,
2424
capitest.VariableTestDef{

pkg/handlers/aws/mutation/region/variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
1818
capitest.ValidateDiscoverVariables(
1919
t,
2020
clusterconfig.MetaVariableName,
21-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
21+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2222
true,
2323
awsclusterconfig.NewVariable,
2424
capitest.VariableTestDef{

pkg/handlers/aws/mutation/securitygroups/variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
1818
capitest.ValidateDiscoverVariables(
1919
t,
2020
clusterconfig.MetaVariableName,
21-
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
21+
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
2222
true,
2323
awsclusterconfig.NewVariable,
2424
capitest.VariableTestDef{

pkg/handlers/aws/workerconfig/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (h *awsWorkerConfigVariableHandler) DiscoverVariables(
4343
resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{
4444
Name: workerconfig.MetaVariableName,
4545
Required: false,
46-
Schema: v1alpha1.NodeConfigSpec{AWS: &v1alpha1.AWSNodeSpec{}}.VariableSchema(),
46+
Schema: v1alpha1.NewAWSWorkerConfigSpec().VariableSchema(),
4747
})
4848
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
4949
}

pkg/handlers/aws/workerconfig/variables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestVariableValidation(t *testing.T) {
1717
capitest.ValidateDiscoverVariables(
1818
t,
1919
workerconfig.MetaVariableName,
20-
ptr.To(v1alpha1.NodeConfigSpec{AWS: &v1alpha1.AWSNodeSpec{}}.VariableSchema()),
20+
ptr.To(v1alpha1.NewAWSWorkerConfigSpec().VariableSchema()),
2121
false,
2222
NewVariable,
2323
capitest.VariableTestDef{

0 commit comments

Comments
 (0)