Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set defaults for AWS CP and Worker instanceType #504

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions api/v1alpha1/aws_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ package v1alpha1

import (
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
)

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

type AWSNodeSpec struct {
Expand All @@ -24,6 +32,18 @@ type AWSNodeSpec struct {
AdditionalSecurityGroups AdditionalSecurityGroup `json:"additionalSecurityGroups,omitempty"`
}

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

func NewAWSWorkerNodeSpec() *AWSNodeSpec {
return &AWSNodeSpec{
InstanceType: ptr.To(AWSWorkerInstanceType),
}
}

type AdditionalSecurityGroup []SecurityGroup

type SecurityGroup struct {
Expand All @@ -49,17 +69,18 @@ func (AdditionalSecurityGroup) VariableSchema() clusterv1.VariableSchema {
}
}

func (AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
func (a AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
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"},
},
}
}
Expand All @@ -77,11 +98,12 @@ func (IAMInstanceProfile) VariableSchema() clusterv1.VariableSchema {

type InstanceType string

func (InstanceType) VariableSchema() clusterv1.VariableSchema {
func (i InstanceType) 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(i),
},
}
}
Expand Down
16 changes: 11 additions & 5 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ type ClusterConfigSpec struct {

func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
clusterConfigProps := GenericClusterConfig{}.VariableSchema()

switch {
case s.AWS != nil:
maps.Copy(
clusterConfigProps.OpenAPIV3Schema.Properties,
map[string]clusterv1.JSONSchemaProps{
AWSVariableName: AWSSpec{}.VariableSchema().OpenAPIV3Schema,
"controlPlane": NodeConfigSpec{
AWS: &AWSNodeSpec{},
}.VariableSchema().OpenAPIV3Schema,
AWSVariableName: s.AWS.VariableSchema().OpenAPIV3Schema,
"controlPlane": s.ControlPlane.VariableSchema().OpenAPIV3Schema,
},
)
case s.Docker != nil:
Expand Down Expand Up @@ -94,6 +91,15 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
return clusterConfigProps
}

func NewAWSClusterConfigSpec() *ClusterConfigSpec {
return &ClusterConfigSpec{
AWS: &AWSSpec{},
ControlPlane: &NodeConfigSpec{
AWS: NewAWSControlPlaneNodeSpec(),
},
}
}

// GenericClusterConfig defines the generic cluster configdesired.
type GenericClusterConfig struct {
// +optional
Expand Down
8 changes: 7 additions & 1 deletion api/v1alpha1/node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
maps.Copy(
nodeConfigProps.OpenAPIV3Schema.Properties,
map[string]clusterv1.JSONSchemaProps{
AWSVariableName: AWSNodeSpec{}.VariableSchema().OpenAPIV3Schema,
AWSVariableName: s.AWS.VariableSchema().OpenAPIV3Schema,
},
)
case s.Docker != nil:
Expand All @@ -63,6 +63,12 @@ func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
return nodeConfigProps
}

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

type GenericNodeConfig struct{}

func (GenericNodeConfig) VariableSchema() clusterv1.VariableSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ spec:
template:
spec:
iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io
instanceType: m5.xlarge
instanceType: PLACEHOLDER
sshKeyName: ""
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
Expand All @@ -119,7 +119,7 @@ spec:
template:
spec:
iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io
instanceType: m5.2xlarge
instanceType: PLACEHOLDER
sshKeyName: ""
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ patches:
patch: |-
- op: "add"
path: "/spec/template/spec/instanceType"
value: "m5.2xlarge"
value: "PLACEHOLDER"
- target:
kind: AWSMachineTemplate
name: quick-start-control-plane
patch: |-
- op: "add"
path: "/spec/template/spec/instanceType"
value: "m5.xlarge"
value: "PLACEHOLDER"
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.ClusterConfigSpec{AWS: &v1alpha1.AWSSpec{}}.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.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/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.NodeConfigSpec{AWS: &v1alpha1.AWSNodeSpec{}}.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.NodeConfigSpec{AWS: &v1alpha1.AWSNodeSpec{}}.VariableSchema()),
ptr.To(v1alpha1.NewAWSWorkerConfigSpec().VariableSchema()),
false,
NewVariable,
capitest.VariableTestDef{
Expand Down
Loading