Skip to content

Commit d34afb1

Browse files
committed
refactor: Separate defaults for worker and CP AWS nodes
1 parent 5b10be5 commit d34afb1

21 files changed

+259
-309
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require (
1616
k8s.io/api v0.29.3
1717
k8s.io/apiextensions-apiserver v0.29.3
1818
k8s.io/apimachinery v0.29.3
19-
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
2019
sigs.k8s.io/cluster-api v1.6.3
2120
sigs.k8s.io/controller-runtime v0.17.3
2221
)
@@ -72,6 +71,7 @@ require (
7271
k8s.io/component-base v0.29.3 // indirect
7372
k8s.io/klog/v2 v2.120.1 // indirect
7473
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
74+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
7575
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
7676
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
7777
sigs.k8s.io/yaml v1.4.0 // indirect

api/v1alpha1/aws_node_types.go

Lines changed: 34 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,42 @@
33

44
package v1alpha1
55

6-
import (
7-
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
8-
"k8s.io/utils/ptr"
9-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
6+
const (
7+
AWSControlPlaneInstanceType = "m5.xlarge"
8+
AWSWorkerInstanceType = "m5.2xlarge"
109

11-
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
10+
AWSControlPlaneInstanceProfile = "control-plane.cluster-api-provider-aws.sigs.k8s.io"
11+
AWSWorkerInstanceProfile = "nodes.cluster-api-provider-aws.sigs.k8s.io"
1212
)
1313

14-
const (
15-
AWSControlPlaneInstanceType InstanceType = "m5.xlarge"
16-
AWSWorkerInstanceType InstanceType = "m5.2xlarge"
14+
type AWSControlPlaneNodeSpec struct {
15+
// The IAM instance profile to use for the cluster Machines.
16+
// +kubebuilder:default=control-plane.cluster-api-provider-aws.sigs.k8s.io
17+
// +optional
18+
IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"`
1719

18-
AWSControlPlaneInstanceProfile IAMInstanceProfile = "control-plane.cluster-api-provider-aws.sigs.k8s.io"
19-
AWSWorkerInstanceProfile IAMInstanceProfile = "nodes.cluster-api-provider-aws.sigs.k8s.io"
20-
)
20+
// +kubebuilder:default=m5.xlarge
21+
// +optional
22+
InstanceType string `json:"instanceType,omitempty"`
23+
24+
AWSGenericNodeSpec `json:",inline"`
25+
}
2126

22-
type AWSNodeSpec struct {
27+
type AWSWorkerNodeSpec struct {
28+
// The IAM instance profile to use for the cluster Machines.
29+
// +kubebuilder:default=nodes.cluster-api-provider-aws.sigs.k8s.io
2330
// +optional
24-
IAMInstanceProfile *IAMInstanceProfile `json:"iamInstanceProfile,omitempty"`
31+
IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"`
2532

33+
// The AWS instance type to use for the cluster Machines.
34+
// +kubebuilder:default=m5.2xlarge
2635
// +optional
27-
InstanceType *InstanceType `json:"instanceType,omitempty"`
36+
InstanceType string `json:"instanceType,omitempty"`
2837

38+
AWSGenericNodeSpec `json:",inline"`
39+
}
40+
41+
type AWSGenericNodeSpec struct {
2942
// AMI or AMI Lookup arguments for machine image of a AWS machine.
3043
// If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence
3144
//+optional
@@ -35,87 +48,16 @@ type AWSNodeSpec struct {
3548
AdditionalSecurityGroups AdditionalSecurityGroup `json:"additionalSecurityGroups,omitempty"`
3649
}
3750

38-
func NewAWSControlPlaneNodeSpec() *AWSNodeSpec {
39-
return &AWSNodeSpec{
40-
InstanceType: ptr.To(AWSControlPlaneInstanceType),
41-
IAMInstanceProfile: ptr.To(AWSControlPlaneInstanceProfile),
42-
}
43-
}
44-
45-
func NewAWSWorkerNodeSpec() *AWSNodeSpec {
46-
return &AWSNodeSpec{
47-
InstanceType: ptr.To(AWSWorkerInstanceType),
48-
IAMInstanceProfile: ptr.To(AWSWorkerInstanceProfile),
49-
}
50-
}
51-
5251
type AdditionalSecurityGroup []SecurityGroup
5352

5453
type SecurityGroup struct {
5554
// ID is the id of the security group
5655
// +optional
57-
ID *string `json:"id,omitempty"`
58-
}
59-
60-
func (AdditionalSecurityGroup) VariableSchema() clusterv1.VariableSchema {
61-
return clusterv1.VariableSchema{
62-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
63-
Type: "array",
64-
Items: &clusterv1.JSONSchemaProps{
65-
Type: "object",
66-
Properties: map[string]clusterv1.JSONSchemaProps{
67-
"id": {
68-
Type: "string",
69-
Description: "Security group ID to add for the cluster Machines",
70-
},
71-
},
72-
},
73-
},
74-
}
75-
}
76-
77-
func (a AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
78-
return clusterv1.VariableSchema{
79-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
80-
Description: "AWS Node configuration",
81-
Type: "object",
82-
Properties: map[string]clusterv1.JSONSchemaProps{
83-
"iamInstanceProfile": a.IAMInstanceProfile.VariableSchema().OpenAPIV3Schema,
84-
"instanceType": a.InstanceType.VariableSchema().OpenAPIV3Schema,
85-
"ami": AMISpec{}.VariableSchema().OpenAPIV3Schema,
86-
"additionalSecurityGroups": AdditionalSecurityGroup{}.VariableSchema().OpenAPIV3Schema,
87-
},
88-
Required: []string{"instanceType"},
89-
},
90-
}
91-
}
92-
93-
type IAMInstanceProfile string
94-
95-
func (i IAMInstanceProfile) VariableSchema() clusterv1.VariableSchema {
96-
return clusterv1.VariableSchema{
97-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
98-
Type: "string",
99-
Description: "The IAM instance profile to use for the cluster Machines",
100-
Default: variables.MustMarshal(i),
101-
},
102-
}
103-
}
104-
105-
type InstanceType string
106-
107-
func (i InstanceType) VariableSchema() clusterv1.VariableSchema {
108-
return clusterv1.VariableSchema{
109-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
110-
Type: "string",
111-
Description: "The AWS instance type to use for the cluster Machines",
112-
Default: variables.MustMarshal(i),
113-
},
114-
}
56+
ID string `json:"id,omitempty"`
11557
}
11658

11759
type AMISpec struct {
118-
// ID is an explicit AMI to use.
60+
// AMI ID is the reference to the AMI from which to create the machine instance.
11961
// +optional
12062
ID string `json:"id,omitempty"`
12163

@@ -124,58 +66,18 @@ type AMISpec struct {
12466
Lookup *AMILookup `json:"lookup,omitempty"`
12567
}
12668

127-
func (AMISpec) VariableSchema() clusterv1.VariableSchema {
128-
return clusterv1.VariableSchema{
129-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
130-
Type: "object",
131-
Default: &v1.JSON{},
132-
Description: "AMI or AMI Lookup arguments for machine image of a AWS machine." +
133-
"If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence",
134-
Properties: map[string]clusterv1.JSONSchemaProps{
135-
"id": {
136-
Type: "string",
137-
Description: "AMI ID is the reference to the AMI from which to create the machine instance.",
138-
},
139-
"lookup": AMILookup{}.VariableSchema().OpenAPIV3Schema,
140-
},
141-
},
142-
}
143-
}
144-
14569
type AMILookup struct {
146-
// Format is the AMI naming format
70+
// AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the
71+
// base OS and kubernetes version.
72+
// +kubebuilder:example=`capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*`
14773
// +optional
14874
Format string `json:"format,omitempty"`
14975

150-
// Org is the AWS Organization ID to use for image lookup
76+
// The AWS Organization ID to use for image lookup.
15177
// +optional
15278
Org string `json:"org,omitempty"`
15379

154-
// BaseOS is the name of the base os for image lookup
80+
// The name of the base os for image lookup
15581
// +optional
15682
BaseOS string `json:"baseOS,omitempty"`
15783
}
158-
159-
func (AMILookup) VariableSchema() clusterv1.VariableSchema {
160-
return clusterv1.VariableSchema{
161-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
162-
Type: "object",
163-
Default: &v1.JSON{},
164-
Properties: map[string]clusterv1.JSONSchemaProps{
165-
"format": {
166-
Type: "string",
167-
Description: "AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the" +
168-
"base OS and kubernetes version. example: capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*",
169-
},
170-
"org": {
171-
Type: "string",
172-
Description: "The AWS Organization ID to use for image lookup",
173-
},
174-
"baseOS": {
175-
Type: "string",
176-
Description: "The name of the base os for image lookup",
177-
},
178-
},
179-
},
180-
}
181-
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type AWSClusterConfigSpec struct {
8484
GenericClusterConfigSpec `json:",inline"`
8585

8686
// +optional
87-
ControlPlane *AWSNodeConfigSpec `json:"controlPlane,omitempty"`
87+
ControlPlane *AWSControlPlaneNodeConfigSpec `json:"controlPlane,omitempty"`
8888

8989
// Extra Subject Alternative Names for the API Server signing cert.
9090
// +kubebuilder:validation:UniqueItems=true

api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ spec:
247247
type: object
248248
controlPlane:
249249
description: |-
250-
AWSNodeConfigSpec defines the desired state of AWSNodeConfig.
250+
AWSControlPlaneConfigSpec defines the desired state of AWSNodeConfig.
251251
Place any configuration that can be applied to individual Nodes here.
252252
Otherwise, it should go into the ClusterConfigSpec.
253253
properties:
@@ -267,27 +267,34 @@ spec:
267267
If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence
268268
properties:
269269
id:
270-
description: ID is an explicit AMI to use.
270+
description: AMI ID is the reference to the AMI from which
271+
to create the machine instance.
271272
type: string
272273
lookup:
273274
description: Lookup is the lookup arguments for the AMI.
274275
properties:
275276
baseOS:
276-
description: BaseOS is the name of the base os for
277-
image lookup
277+
description: The name of the base os for image lookup
278278
type: string
279279
format:
280-
description: Format is the AMI naming format
280+
description: |-
281+
AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the
282+
base OS and kubernetes version.
283+
example: capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*
281284
type: string
282285
org:
283-
description: Org is the AWS Organization ID to use
284-
for image lookup
286+
description: The AWS Organization ID to use for image
287+
lookup.
285288
type: string
286289
type: object
287290
type: object
288291
iamInstanceProfile:
292+
default: control-plane.cluster-api-provider-aws.sigs.k8s.io
293+
description: The IAM instance profile to use for the cluster
294+
Machines.
289295
type: string
290296
instanceType:
297+
default: m5.xlarge
291298
type: string
292299
type: object
293300
type: object

api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml renamed to api/v1alpha1/crds/caren.nutanix.com_awsworkernodeconfigs.yaml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ kind: CustomResourceDefinition
66
metadata:
77
annotations:
88
controller-gen.kubebuilder.io/version: (devel)
9-
name: awsnodeconfigs.caren.nutanix.com
9+
name: awsworkernodeconfigs.caren.nutanix.com
1010
spec:
1111
group: caren.nutanix.com
1212
names:
13-
kind: AWSNodeConfig
14-
listKind: AWSNodeConfigList
15-
plural: awsnodeconfigs
16-
singular: awsnodeconfig
13+
kind: AWSWorkerNodeConfig
14+
listKind: AWSWorkerNodeConfigList
15+
plural: awsworkernodeconfigs
16+
singular: awsworkernodeconfig
1717
scope: Namespaced
1818
versions:
1919
- name: v1alpha1
2020
schema:
2121
openAPIV3Schema:
22-
description: AWSNodeConfig is the Schema for the awsnodeconfigs API.
22+
description: AWSWorkerNodeConfig is the Schema for the awsnodeconfigs API.
2323
properties:
2424
apiVersion:
2525
description: |-
@@ -40,7 +40,7 @@ spec:
4040
type: object
4141
spec:
4242
description: |-
43-
AWSNodeConfigSpec defines the desired state of AWSNodeConfig.
43+
AWSWorkerNodeConfigSpec defines the desired state of AWSNodeConfig.
4444
Place any configuration that can be applied to individual Nodes here.
4545
Otherwise, it should go into the ClusterConfigSpec.
4646
properties:
@@ -60,27 +60,34 @@ spec:
6060
If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence
6161
properties:
6262
id:
63-
description: ID is an explicit AMI to use.
63+
description: AMI ID is the reference to the AMI from which
64+
to create the machine instance.
6465
type: string
6566
lookup:
6667
description: Lookup is the lookup arguments for the AMI.
6768
properties:
6869
baseOS:
69-
description: BaseOS is the name of the base os for image
70-
lookup
70+
description: The name of the base os for image lookup
7171
type: string
7272
format:
73-
description: Format is the AMI naming format
73+
description: |-
74+
AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the
75+
base OS and kubernetes version.
76+
example: capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*
7477
type: string
7578
org:
76-
description: Org is the AWS Organization ID to use for
77-
image lookup
79+
description: The AWS Organization ID to use for image
80+
lookup.
7881
type: string
7982
type: object
8083
type: object
8184
iamInstanceProfile:
85+
default: nodes.cluster-api-provider-aws.sigs.k8s.io
86+
description: The IAM instance profile to use for the cluster Machines.
8287
type: string
8388
instanceType:
89+
default: m5.2xlarge
90+
description: The AWS instance type to use for the cluster Machines.
8491
type: string
8592
type: object
8693
type: object

api/v1alpha1/docker_clusterconfig_types.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,4 @@
33

44
package v1alpha1
55

6-
import (
7-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8-
)
9-
106
type DockerSpec struct{}
11-
12-
func (DockerSpec) VariableSchema() clusterv1.VariableSchema {
13-
return clusterv1.VariableSchema{
14-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
15-
Description: "Docker cluster configuration",
16-
Type: "object",
17-
Properties: map[string]clusterv1.JSONSchemaProps{},
18-
},
19-
}
20-
}

0 commit comments

Comments
 (0)