Skip to content

Commit c0657c7

Browse files
feat: implement auto-population of AWSMachineTemplate capacity and nodeInfo
Add AWSMachineTemplateReconciler to automatically populate capacity and node info fields by querying AWS EC2 API. This completes the autoscaling from zero implementation by ensuring the required metadata is available without manual configuration. Changes include: - Add NodeInfo struct with Architecture and OperatingSystem fields to AWSMachineTemplate status - Implement controller that queries EC2 API for instance type specifications - Auto-populate CPU, memory, pods, and ephemeral storage capacity - Auto-detect architecture (amd64/arm64) and OS (linux/windows) from AMI - Add conversion logic for backward compatibility with v1beta1 - Enable status subresource on AWSMachineTemplate CRD - Add comprehensive unit tests (351 lines) covering various scenarios - Add RBAC permissions for controller operations The controller automatically populates these fields when an AWSMachineTemplate is created or updated, eliminating the need for manual configuration and enabling Cluster Autoscaler to make informed scaling decisions from zero nodes. Related: https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md Squashed from 5 commits: - 9a92a43 Implement autoscaling from zero by auto-populating AWSMachineTemplate capacity - 86fe072 add AWSMachineTemplate NodeInfo - ddaf62c Fix review comments - 4ea52c8 Fix review comments 2 - b398ffc Fix review comments 3
1 parent 26bbb03 commit c0657c7

11 files changed

+898
-5
lines changed

api/v1beta1/awsmachine_conversion.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
136136
}
137137
}
138138

139+
// Restore Status fields that don't exist in v1beta1.
140+
dst.Status.NodeInfo = restored.Status.NodeInfo
141+
139142
return nil
140143
}
141144

api/v1beta1/conversion.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@ func Convert_v1beta2_AWSMachineStatus_To_v1beta1_AWSMachineStatus(in *v1beta2.AW
108108
// Note: DedicatedHostID is not present in v1beta1, so it will be dropped during conversion
109109
return autoConvert_v1beta2_AWSMachineStatus_To_v1beta1_AWSMachineStatus(in, out, s)
110110
}
111+
112+
func Convert_v1beta2_AWSMachineTemplateStatus_To_v1beta1_AWSMachineTemplateStatus(in *v1beta2.AWSMachineTemplateStatus, out *AWSMachineTemplateStatus, s conversion.Scope) error {
113+
// NodeInfo field is ignored (dropped) as it doesn't exist in v1beta1
114+
return autoConvert_v1beta2_AWSMachineTemplateStatus_To_v1beta1_AWSMachineTemplateStatus(in, out, s)
115+
}

api/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awsmachinetemplate_types.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,55 @@ import (
2323
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2424
)
2525

26+
// Architecture represents the CPU architecture of the node.
27+
// Its underlying type is a string and its value can be any of amd64, arm64.
28+
type Architecture string
29+
30+
// Architecture constants.
31+
const (
32+
ArchitectureAmd64 Architecture = "amd64"
33+
ArchitectureArm64 Architecture = "arm64"
34+
)
35+
36+
// OperatingSystem represents the operating system of the node.
37+
// Its underlying type is a string and its value can be any of linux, windows.
38+
type OperatingSystem string
39+
40+
// Operating system constants.
41+
const (
42+
// OperatingSystemLinux represents the Linux operating system.
43+
OperatingSystemLinux OperatingSystem = "linux"
44+
// OperatingSystemWindows represents the Windows operating system.
45+
OperatingSystemWindows OperatingSystem = "windows"
46+
)
47+
48+
// NodeInfo contains information about the node's architecture and operating system.
49+
type NodeInfo struct {
50+
// Architecture is the CPU architecture of the node.
51+
// Its underlying type is a string and its value can be any of amd64, arm64.
52+
// +kubebuilder:validation:Enum=amd64;arm64
53+
// +optional
54+
Architecture Architecture `json:"architecture,omitempty"`
55+
// OperatingSystem is the operating system of the node.
56+
// Its underlying type is a string and its value can be any of linux, windows.
57+
// +kubebuilder:validation:Enum=linux;windows
58+
// +optional
59+
OperatingSystem OperatingSystem `json:"operatingSystem,omitempty"`
60+
}
61+
2662
// AWSMachineTemplateStatus defines a status for an AWSMachineTemplate.
2763
type AWSMachineTemplateStatus struct {
2864
// Capacity defines the resource capacity for this machine.
2965
// This value is used for autoscaling from zero operations as defined in:
3066
// https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md
3167
// +optional
3268
Capacity corev1.ResourceList `json:"capacity,omitempty"`
69+
70+
// NodeInfo contains information about the node's architecture and operating system.
71+
// This value is used for autoscaling from zero operations as defined in:
72+
// https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md
73+
// +optional
74+
NodeInfo *NodeInfo `json:"nodeInfo,omitempty"`
3375
}
3476

3577
// AWSMachineTemplateSpec defines the desired state of AWSMachineTemplate.
@@ -40,6 +82,7 @@ type AWSMachineTemplateSpec struct {
4082
// +kubebuilder:object:root=true
4183
// +kubebuilder:resource:path=awsmachinetemplates,scope=Namespaced,categories=cluster-api,shortName=awsmt
4284
// +kubebuilder:storageversion
85+
// +kubebuilder:subresource:status
4386
// +k8s:defaulter-gen=true
4487

4588
// AWSMachineTemplate is the schema for the Amazon EC2 Machine Templates API.

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,32 @@ spec:
11561156
This value is used for autoscaling from zero operations as defined in:
11571157
https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md
11581158
type: object
1159+
nodeInfo:
1160+
description: |-
1161+
NodeInfo contains information about the node's architecture and operating system.
1162+
This value is used for autoscaling from zero operations as defined in:
1163+
https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md
1164+
properties:
1165+
architecture:
1166+
description: |-
1167+
Architecture is the CPU architecture of the node.
1168+
Its underlying type is a string and its value can be any of amd64, arm64.
1169+
enum:
1170+
- amd64
1171+
- arm64
1172+
type: string
1173+
operatingSystem:
1174+
description: |-
1175+
OperatingSystem is the operating system of the node.
1176+
Its underlying type is a string and its value can be any of linux, windows.
1177+
enum:
1178+
- linux
1179+
- windows
1180+
type: string
1181+
type: object
11591182
type: object
11601183
type: object
11611184
served: true
11621185
storage: true
1186+
subresources:
1187+
status: {}

config/rbac/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ rules:
175175
resources:
176176
- awsclusters/status
177177
- awsfargateprofiles/status
178+
- awsmachinetemplates/status
178179
- rosaclusters/status
179180
- rosanetworks/status
180181
- rosaroleconfigs/status

0 commit comments

Comments
 (0)