Skip to content

ClusterAPI: Report machine phases to improve cluster-autoscaler decisions #7989

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

Merged

Conversation

loick111
Copy link
Contributor

@loick111 loick111 commented Mar 27, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it

Following the changes done in #7950, this PR improves the node listing process in the cluster-autoscaler ClusterAPI provider by reporting the machine phase in the Instance status. This allows the cluster-autoscaler to make better scaling decisions without having to wait for a timeout. Specifically:

  • Machines in Deleting, Failed, or Pending states are now reported properly.
  • Failed machines are detected early, enabling faster recovery actions.
  • This change is particularly useful when using the priority expander, as it prevents unnecessary delays before scaling the next priority group.

Which issue(s) this PR fixes

Related to #6128
Related to #7928

Special notes for your reviewer

  • Improves observability of machine states for better debugging.
  • No breaking changes; existing behavior remains unchanged, except for improved handling of failed machines.

Does this PR introduce a user-facing change?

Report machine phases in ClusterAPI provider to allow faster autoscaler decisions and avoid timeout delays.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 27, 2025
Copy link

linux-foundation-easycla bot commented Mar 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: loick111 / name: Loïck MAHIEUX (005a42b)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 27, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @loick111!

It looks like this is your first PR to kubernetes/autoscaler 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/autoscaler has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@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. area/cluster-autoscaler labels Mar 27, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @loick111. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot k8s-ci-robot added the area/provider/cluster-api Issues or PRs related to Cluster API provider label Mar 27, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 27, 2025
// This helps cluster-autoscaler make better scaling decisions.
switch {
case isFailedMachineProviderID(providerIDNormalized):
klog.V(4).Infof("Machine failed in %s (%s)", ng.Id(), providerID)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we say Machine failed in node group %s (%s)...

for all 3 log instances here

case isFailedMachineProviderID(providerIDNormalized):
klog.V(4).Infof("Machine failed in %s (%s)", ng.Id(), providerID)
instance.Status = &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there really no other possible instance state than "InstanceCreating" when the machine is failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we can have machine failed for multiple reasons.
cf. https://cluster-api.sigs.k8s.io/developer/core/controllers/machine

I handled the reporting of Status only when machine are Failed during Provisioning & Deleting phases as I think cluster-autoscaler doesn't have anything to do when Running machine goes into Failed state, it will be more under machine-controller responsibility. (by keeping the same behavior than before, not reporting any Status to core cluster-autoscaler)

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a fair evolution from the current behaviors, thx!

Add improved error handling for machines phase in the ClusterAPI node group
implementation. When a machine is in Deleting/Failed/Pending phase, mark the cloudprovider.Instance
with a status for cluster-autoscaler recovery actions.

The changes:
- Enhance Nodes listing to allow reporting the machine phase in Instance status
- Add error status reporting for failed machines

This change helps identify and manage failed machines more effectively,
allowing the autoscaler to make better scaling decisions.
@loick111 loick111 force-pushed the feature/clusterapi-instances-status branch from 7e3c844 to 005a42b Compare March 28, 2025 14:11
@loick111 loick111 requested a review from jackfrancis March 28, 2025 14:32
@elmiko
Copy link
Contributor

elmiko commented Mar 28, 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 Mar 28, 2025
Copy link
Contributor

@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.

this is looking good to me, thanks @loick111 !

@elmiko
Copy link
Contributor

elmiko commented Apr 1, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 1, 2025
@jackfrancis
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jackfrancis, loick111

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

The pull request process is described 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 1, 2025
@k8s-ci-robot k8s-ci-robot merged commit dc91330 into kubernetes:master Apr 1, 2025
7 checks passed
@loick111 loick111 deleted the feature/clusterapi-instances-status branch April 4, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler area/provider/cluster-api Issues or PRs related to Cluster API provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants