Skip to content

Commit eef83de

Browse files
committed
Update autoscaling from zero enhancement proposal with support for platform-aware autoscale from zero
This commit updates the contract between the cluster-autoscaler Cluster API provider and the infrastructure provider's controllers that reconcile the Infrastructure Machine Template to support platform-aware autoscale from 0 in clusters consisting of nodes heterogeneous in CPU architecture and OS. With this commit, the infrastructure providers implementing controllers to reconcile the status of their Infrastructure Machine Templates for supporting autoscale from 0 will be able to fill the status.nodeInfo stanza with additional information about the nodes. The status.nodeInfo stanza has type corev1.NodeSystemInfo to reflect the same content, the rendered nodes' objects would store in their status field. The cluster-autoscaler can use that information to build the node template labels `kubernetes.io/arch` and `kubernetes.io/os` if that information is present. Suppose the pending pods that trigger the cluster autoscaler have a node selector or a requiredDuringSchedulingIgnoredDuringExecution node affinity concerning the architecture or operating system of the node where they can execute. In that case, the autoscaler will be able to filter the nodes groups options according to the architecture or operating system requested by the pod. The users could already provide this information to the cluster autoscaler through the labels capacity annotation. However, there is no similar capability to support future labels/taints through information set by the reconcilers of the status of Infrastructure Machine Templates. Signed-off-by: aleskandro <aleskandro@redhat.com>
1 parent 393485e commit eef83de

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

docs/book/src/developer/providers/contracts/infra-machine.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ If implementing the pause behavior, providers SHOULD surface the paused status o
494494

495495
### InfraMachineTemplate: support cluster autoscaling from zero
496496

497-
As described in the enhancement [Opt-in Autoscaling from Zero][Opt-in Autoscaling from Zero], providers may implement a capacity field in machine templates to inform the cluster autoscaler about the resources available on that machine type.
497+
As described in the enhancement [Opt-in Autoscaling from Zero][Opt-in Autoscaling from Zero], providers may implement the `capacity` and `nodeInfo` fields in machine templates to inform the cluster autoscaler about the resources available on that machine type, the architecture, and the operating system it runs.
498498

499499
Building on the `FooMachineTemplate` example from above, this shows the addition of a status and capacity field:
500500

@@ -517,19 +517,50 @@ type FooMachineTemplateStatus struct {
517517
// https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md
518518
// +optional
519519
Capacity corev1.ResourceList `json:"capacity,omitempty"`
520+
// +optional
521+
NodeInfo *NodeInfo `json:"nodeInfo,omitempty"`
520522
}
523+
524+
// Architecture represents the CPU architecture of the node. Its underlying type is a string.
525+
// Its underlying type is a string and its value can be any of amd64, arm64, s390x, ppc64le.
526+
// +kubebuilder:validation:Enum=amd64;arm64;s390x;ppc64le
527+
// +enum
528+
type Architecture string
529+
530+
// NodeInfo contains information about the node's architecture and operating system.
531+
type NodeInfo struct {
532+
// architecture is the CPU architecture of the node.
533+
// Its underlying type is a string and its value can be any of amd64, arm64, s390x, ppc64le.
534+
// +optional
535+
Architecture Architecture `json:"architecture,omitempty"`
536+
// operatingSystem is a string representing the operating system of the node.
537+
// This may be a string like 'linux' or 'windows'.
538+
// +optional
539+
OperatingSystem string `json:"operatingSystem,omitempty"`
540+
}
541+
521542
```
522543

523-
When rendered to a manifest, the machine template status capacity field representing an instance with 500 megabytes of RAM, 1 CPU core, and 1 NVidia GPU would look like this:
544+
When rendered to a manifest, the machine template status capacity field representing an amd64 linux instance with 500 megabytes of RAM, 1 CPU core, and 1 NVidia GPU should look like this:
524545

525546
```
526547
status:
527548
capacity:
528549
memory: 500mb
529550
cpu: "1"
530551
nvidia.com/gpu: "1"
552+
nodeInfo:
553+
architecture: amd64
554+
operatingSystem: linux
531555
```
532556

557+
If the information in the `nodeInfo` field is not available, the result of the autoscaling from zero operation will depend
558+
on the cluster autoscaler implementation. For example, the Cluster API implementation of the Kubernetes Cluster Autoscaler
559+
will assume the host is running either the architecture set in the `CAPI_SCALE_ZERO_DEFAULT_ARCH` environment variable of
560+
the cluster autoscaler pod environment, or the amd64 architecture and Linux operating system as default values.
561+
562+
See [autoscaling](../../../tasks/automated-machine-management/autoscaling.md).
563+
533564
## Typical InfraMachine reconciliation workflow
534565

535566
A machine infrastructure provider must respond to changes to its InfraMachine resources. This process is

docs/proposals/20210310-opt-in-autoscaling-from-zero.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ node group. But, during a scale from zero situation (ie when a node group has ze
107107
autoscaler needs to acquire this information from the infrastructure provider.
108108

109109
An optional status field is proposed on the Infrastructure Machine Template which will be populated
110-
by infrastructure providers to contain the CPU, memory, and GPU capacities for machines described by that
111-
template. The cluster autoscaler will then utilize this information by reading the appropriate
110+
by infrastructure providers to contain the CPU, CPU architecture, memory, and GPU capacities for machines
111+
described by that template. The cluster autoscaler will then utilize this information by reading the appropriate
112112
infrastructure reference from the resource it is scaling (MachineSet or MachineDeployment).
113113

114114
A user may override the field in the associated infrastructure template by applying annotations to the
@@ -160,6 +160,10 @@ the template. Internally, this field will be represented by a Go `map` type uti
160160
for the keys and `k8s.io/apimachinery/pkg/api/resource.Quantity` as the values (similar to how resource
161161
limits and requests are handled for pods).
162162

163+
Additionally, the status field should contain information about the node, such as the architecture and
164+
operating system. This information is not required for the autoscaler to function, but it can be useful in
165+
scenarios where the autoscaler needs to make decisions for clusters with heterogeneous node groups in architecture, OS, or both.
166+
163167
It is worth mentioning that the Infrastructure Machine Templates are not usually reconciled by themselves.
164168
Each infrastructure provider will be responsible for determining the best implementation for adding the
165169
status field based on the information available on their platform.
@@ -175,6 +179,9 @@ const (
175179
// DockerMachineTemplateStatus defines the observed state of a DockerMachineTemplate
176180
type DockerMachineTemplateStatus struct {
177181
Capacity corev1.ResourceList `json:"capacity,omitempty"`
182+
183+
// +optional
184+
NodeInfo *NodeInfo `json:"nodeInfo,omitempty"`
178185
}
179186
180187
// DockerMachineTemplate is the Schema for the dockermachinetemplates API.
@@ -188,6 +195,38 @@ type DockerMachineTemplate struct {
188195
```
189196
_Note: the `ResourceList` and `ResourceName` referenced are from k8s.io/api/core/v1`_
190197

198+
`NodeInfo` is a struct that contains the architecture and operating system information of the node, to implement
199+
in the providers integration code.
200+
Its definition should look like the following:
201+
202+
```go
203+
// Architecture represents the CPU architecture of the node. Its underlying type is a string.
204+
// Its underlying type is a string and its value can be any of amd64, arm64, s390x, ppc64le.
205+
// +kubebuilder:validation:Enum=amd64;arm64;s390x;ppc64le
206+
// +enum
207+
type Architecture string
208+
209+
// Architecture constants defined for clarity.
210+
const (
211+
ArchitectureAmd64 Architecture = "amd64"
212+
ArchitectureArm64 Architecture = "arm64"
213+
ArchitectureS390x Architecture = "s390x"
214+
ArchitecturePpc64le Architecture = "ppc64le"
215+
)
216+
217+
// NodeInfo contains information about the node's architecture and operating system.
218+
type NodeInfo struct {
219+
// architecture is the CPU architecture of the node.
220+
// Its underlying type is a string and its value can be any of amd64, arm64, s390x, ppc64le.
221+
// +optional
222+
Architecture Architecture `json:"architecture,omitempty"`
223+
// operatingSystem is a string representing the operating system of the node.
224+
// This may be a string like 'linux' or 'windows'.
225+
// +optional
226+
OperatingSystem string `json:"operatingSystem,omitempty"`
227+
}
228+
```
229+
191230
When used as a manifest, it would look like this:
192231

193232
```
@@ -204,8 +243,13 @@ status:
204243
memory: 500mb
205244
cpu: "1"
206245
nvidia.com/gpu: "1"
246+
nodeInfo:
247+
architecture: arm64
248+
operatingSystem: linux
207249
```
208250

251+
The information stored in the `status.nodeInfo` field will be used by the cluster autoscaler's scheduler simulator to determine the simulated node's labels `kubernetes.io/arch` and `kubernetes.io/os`. This logic will be implemented in the cluster autoscaler's ClusterAPI cloud provider code.
252+
209253
#### MachineSet and MachineDeployment Annotations
210254

211255
In cases where a user needs to provide specific resource information for a
@@ -246,6 +290,11 @@ metadata:
246290
capacity.cluster-autoscaler.kubernetes.io/taints: "key1=value1:NoSchedule,key2=value2:NoExecute"
247291
```
248292

293+
If the `capacity.cluster-autoscaler.kubernetes.io/labels` annotation specifies a label that would otherwise be
294+
generated from the fields in the `status` field of the Machine Template, the autoscaler will prioritize and use
295+
the label defined in the annotation. This means any label set by the annotation will override the corresponding
296+
value provided by the infrastructure provider in the Machine Template status.
297+
249298
### Security Model
250299

251300
This feature will require the service account associated with the cluster autoscaler to have
@@ -318,6 +367,7 @@ office hours meeting:
318367

319368
## Implementation History
320369

370+
- [X] 05/08/2025: Updated proposal to enable architecture- and OS- aware auto-scale from 0
321371
- [X] 09/12/2024: Added section on Implementation Status
322372
- [X] 01/31/2023: Updated proposal to include annotation changes
323373
- [X] 06/10/2021: Proposed idea in an issue or [community meeting]

0 commit comments

Comments
 (0)