Skip to content

Conversation

@LiangquanLi930
Copy link
Contributor

@LiangquanLi930 LiangquanLi930 commented Oct 15, 2025

✨ Implement autoscaling from zero by auto-populating AWSMachineTemplate capacity

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR implements the Cluster API autoscaling from zero proposal for CAPA by adding a controller that automatically populates AWSMachineTemplate.Status.Capacity with instance type information.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • includes emoji in title
  • adds unit tests
  • adds or updates e2e tests

Release note:

Implement autoscaling from zero by auto-populating AWSMachineTemplate capacity

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 15, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign richardcase for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 15, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @LiangquanLi930. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@LiangquanLi930 LiangquanLi930 changed the title ✨ Implement autoscaling from zero by auto-populating AWSMachineTemplate capacity WIP ✨ Implement autoscaling from zero by auto-populating AWSMachineTemplate capacity Oct 15, 2025
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 15, 2025
@elmiko
Copy link

elmiko commented Oct 15, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 15, 2025
@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch 6 times, most recently from 50f8188 to f1ee365 Compare October 20, 2025 08:39
@LiangquanLi930
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e-blocking

@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch from f1ee365 to 3be8f4d Compare October 20, 2025 11:21
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 20, 2025
@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch 2 times, most recently from 01be987 to 915f55b Compare October 20, 2025 12:57
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 20, 2025
@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch from 915f55b to b3850d1 Compare October 20, 2025 14:42
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

func TestAWSMachineTemplateReconciler(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there also be a unit test which expects actual correct values instead of just checking "capacity" is set?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elmiko
Copy link

elmiko commented Oct 22, 2025

nodeInfo would be nice to have, architecture should be relatively easy to determine but i'm not sure about operating system.

that said, nodeInfo is an extension to the original opt-in scale from zero, if arch and o/s are not present the autoscaler will still be able to scale based on resources alone.

@LiangquanLi930
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e

Copy link

@elmiko elmiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general this is looking good to me, i tend to agree with Christian's questions.

@LiangquanLi930
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e

@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch from 679c53a to 3208d4c Compare October 23, 2025 09:51
@LiangquanLi930
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e

@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch 2 times, most recently from f02a539 to cee9b2e Compare October 23, 2025 18:44
@LiangquanLi930
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-test

@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch 11 times, most recently from d87e524 to ae396bf Compare October 28, 2025 06:56
@LiangquanLi930 LiangquanLi930 force-pushed the opt-in-autoscaling-from-zero branch from ae396bf to 15d3232 Compare October 28, 2025 09:11
@LiangquanLi930
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e

@k8s-ci-robot
Copy link
Contributor

@LiangquanLi930: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-aws-e2e ded149b link false /test pull-cluster-api-provider-aws-e2e

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

// Extract node info from AMI if available
nodeInfo := &infrav1.NodeInfo{}
amiID := template.Spec.Template.Spec.AMI.ID
if amiID != nil && *amiID != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elmiko @chrischdi Hi
I have a question: when an AWSMachineTemplate does not specify an AMI.ID, how should this be handled? Should we keep it as it is, or should we retrieve the AMI.ID in some way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in other words, do we have any other ways to obtain the architecture and OS?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, i am not familiar enough with the aws sdk to know if we could query in another way. @damdo and @nrb have some experience with CAPA, perhaps they might have a suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what we do when there's no AMI ID defined for a Machine: https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/pkg/cloud/services/ec2/instances.go#L144

I would say we could probably re-use https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/pkg/cloud/services/ec2/ami.go#L174, and if that doesn't get what we need, it's an error and the user needs to give us either the AMI ID or some of the other lookup data.

}

// Determine OS - check Platform field first (specifically for Windows identification)
var os string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could initialize this with linux and only change to windows if the image.Platform or the image.PlatformDetails say it's windows? A fairly minor change, but it would eliminate the check at L242.

// Extract node info from AMI if available
nodeInfo := &infrav1.NodeInfo{}
amiID := template.Spec.Template.Spec.AMI.ID
if amiID != nil && *amiID != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what we do when there's no AMI ID defined for a Machine: https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/pkg/cloud/services/ec2/instances.go#L144

I would say we could probably re-use https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/pkg/cloud/services/ec2/ami.go#L174, and if that doesn't get what we need, it's an error and the user needs to give us either the AMI ID or some of the other lookup data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-priority ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants