Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
fix: set defaults for AWS CP and Worker instanceType
Browse files Browse the repository at this point in the history
  • Loading branch information
supershal committed Apr 10, 2024
1 parent 3f673f9 commit 481a55a
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 38 deletions.
26 changes: 5 additions & 21 deletions api/v1alpha1/aws_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
AWSControlPlaneInstanceType InstanceType = "m5.xlarge"
AWSWorkerInstanceType InstanceType = "m5.xlarge"
AWSWorkerInstanceType InstanceType = "m5.2xlarge"
)

type AWSNodeSpec struct {
Expand Down Expand Up @@ -57,32 +57,28 @@ func (AdditionalSecurityGroup) VariableSchema() clusterv1.VariableSchema {
}

func (a AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
instanceType := InstanceType("")
if a.InstanceType != nil {
instanceType = *a.InstanceType
}

return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "AWS Node configuration",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"iamInstanceProfile": IAMInstanceProfile("").VariableSchema().OpenAPIV3Schema,
"instanceType": instanceType.VariableSchema().OpenAPIV3Schema,
"instanceType": a.InstanceType.VariableSchema().OpenAPIV3Schema,
"ami": AMISpec{}.VariableSchema().OpenAPIV3Schema,
"additionalSecurityGroups": AdditionalSecurityGroup{}.VariableSchema().OpenAPIV3Schema,
},
Required: []string{"instanceType"},
},
}
}

func AWSControlPlaneNodeSpec() *AWSNodeSpec {
func NewAWSControlPlaneNodeSpec() *AWSNodeSpec {
return &AWSNodeSpec{
InstanceType: ptr.To(AWSControlPlaneInstanceType),
}
}

func AWSWorkerNodeSpec() *AWSNodeSpec {
func NewAWSWorkerNodeSpec() *AWSNodeSpec {
return &AWSNodeSpec{
InstanceType: ptr.To(AWSWorkerInstanceType),
}
Expand Down Expand Up @@ -111,18 +107,6 @@ func (i InstanceType) VariableSchema() clusterv1.VariableSchema {
}
}

type ControlPlaneInstanceType string

func (ControlPlaneInstanceType) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Description: "The AWS instance type to use for the cluster Machines",
Default: variables.MustMarshal("m5.xlarge"),
},
}
}

type AMISpec struct {
// ID is an explicit AMI to use.
// +optional
Expand Down
7 changes: 2 additions & 5 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ type ClusterConfigSpec struct {

func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
clusterConfigProps := GenericClusterConfig{}.VariableSchema()
if s.ControlPlane == nil {
s.ControlPlane = &NodeConfigSpec{}
}
switch {
case s.AWS != nil:
maps.Copy(
Expand Down Expand Up @@ -94,11 +91,11 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
return clusterConfigProps
}

func DefaultAWSClusterConfigSpec() *ClusterConfigSpec {
func NewAWSClusterConfigSpec() *ClusterConfigSpec {
return &ClusterConfigSpec{
AWS: &AWSSpec{},
ControlPlane: &NodeConfigSpec{
AWS: AWSControlPlaneNodeSpec(),
AWS: NewAWSControlPlaneNodeSpec(),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
return nodeConfigProps
}

func DefaultAWSWorkerConfigSpec() *NodeConfigSpec {
func NewAWSWorkerConfigSpec() *NodeConfigSpec {
return &NodeConfigSpec{
AWS: AWSWorkerNodeSpec(),
AWS: NewAWSWorkerNodeSpec(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/clusterconfig/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (h *awsClusterConfigVariableHandler) DiscoverVariables(
resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{
Name: clusterconfig.MetaVariableName,
Required: true,
Schema: v1alpha1.DefaultAWSClusterConfigSpec().VariableSchema(),
Schema: v1alpha1.NewAWSClusterConfigSpec().VariableSchema(),
})
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
}
2 changes: 1 addition & 1 deletion pkg/handlers/aws/mutation/ami/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/mutation/instancetype/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.DefaultAWSClusterConfigSpec().VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/mutation/network/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/mutation/region/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/mutation/securitygroups/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
clusterconfig.MetaVariableName,
ptr.To(v1alpha1.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()),
true,
awsclusterconfig.NewVariable,
capitest.VariableTestDef{
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/aws/workerconfig/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (h *awsWorkerConfigVariableHandler) DiscoverVariables(
resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{
Name: workerconfig.MetaVariableName,
Required: false,
Schema: v1alpha1.DefaultAWSWorkerConfigSpec().VariableSchema(),
Schema: v1alpha1.NewAWSWorkerConfigSpec().VariableSchema(),
})
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
}
2 changes: 1 addition & 1 deletion pkg/handlers/aws/workerconfig/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestVariableValidation(t *testing.T) {
capitest.ValidateDiscoverVariables(
t,
workerconfig.MetaVariableName,
ptr.To(v1alpha1.DefaultAWSWorkerConfigSpec().VariableSchema()),
ptr.To(v1alpha1.NewAWSWorkerConfigSpec().VariableSchema()),
false,
NewVariable,
capitest.VariableTestDef{
Expand Down

0 comments on commit 481a55a

Please sign in to comment.