Skip to content

🐛 fix: set machine spec failuredomain string if not defined #3576

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jcpowermac
Copy link

@jcpowermac jcpowermac commented Aug 14, 2025

What this PR does / why we need it:

This commit sets the machine.Spec.FailureDomain string
from the vsphereMachine.Spec.FailureDomain if
defined and the machine failure domain is empty.

This resolves an issue where virtual machines are not placed
within vm-host groups in a timely
manner causing misplacement in the topology.

Fixes #3575

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 14, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @jcpowermac!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-vsphere 🎉. 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-sigs/cluster-api-provider-vsphere 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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 14, 2025
@k8s-ci-robot
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 14, 2025
@jcpowermac jcpowermac changed the title fix: use vsphereMachine instead of machine for fd 🐛 fix: use vsphereMachine instead of machine for fd Aug 14, 2025
@rvanderp3
Copy link
Contributor

/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 Aug 14, 2025
@rvanderp3
Copy link
Contributor

/lgtm

/assign @sbueringer

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

LGTM label has been added.

Git tree hash: 29283286600b1e3b812f33127e495556fc7d4a05

@@ -234,10 +234,10 @@ func (r vmReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.R
}

var vsphereFailureDomain *infrav1.VSphereFailureDomain
if failureDomain := machine.Spec.FailureDomain; failureDomain != "" {
if failureDomain := vsphereMachine.Spec.FailureDomain; failureDomain != nil && *failureDomain != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Am I right that its always the way that:

Whatever is set on vSphereMachine's .spec.failureDomain gets propagated up (by CAPI's machine controller) to the Machine's .spec.failureDomain field.

Its just that the timing is bad (CAPI does this too late?!)

Otherwise: should we use a fallback to machine.Spec.FailureDomain, if its not set on vsphereMachine?

Copy link
Member

Choose a reason for hiding this comment

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

Reading the CAPI contract: https://main.cluster-api.sigs.k8s.io/developer/providers/contracts/infra-machine#inframachine-failure-domain

It should be the other way around (which means code as-is should be correct?!).

Copy link
Author

Choose a reason for hiding this comment

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

used rr to troubleshoot, the machine object doesn't receive the failuredomain name before the guest is powered on - then the race is on...will the node ccm init prior to being added to the vm-host group and potentially vmotion'ed to the correct location in the vCenter cluster.

if ok, err := vms.reconcileVMGroupInfo(ctx, virtualMachineCtx); err != nil || !ok {
return vm, err
}
if err := vms.reconcileClusterModuleMembership(ctx, virtualMachineCtx); err != nil {
return vm, err
}
if ok, err := vms.reconcilePowerState(ctx, virtualMachineCtx); err != nil || !ok {
return vm, err
}
if err := vms.reconcileHostInfo(ctx, virtualMachineCtx); err != nil {

if virtualMachineCtx.VSphereFailureDomain == nil || virtualMachineCtx.VSphereFailureDomain.Spec.Topology.Hosts == nil {

Copy link
Member

Choose a reason for hiding this comment

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

I agree that potentially is the behavior when setting failuredomain only on the InfraMachine object (VSphereMachineTemplate?!).

According to kubernetes-sigs/cluster-api#11232 the correct usage is setting FailureDomain on the Machine object instead. Which means it would also be there in the referenced code.

Setting it on the VSphereMachine / VSphereMachineTemplate is the old deprecated behavior.

Copy link
Author

Choose a reason for hiding this comment

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

I understand that its deprecated behavior, what is the solution then? The machine failuredomain name is slow to become available in the reconcile loop, which causes this race.

Copy link
Member

@chrischdi chrischdi Aug 15, 2025

Choose a reason for hiding this comment

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

The solution if I'm right is: Set the failuredomain on the Machine (or MachineSet or MachineDeployment) object instead of the InfraMachine / VSphereMachine.

It should be fine to still set it on the InfraMachine / VSphereMachine. The important piece is to set it on the Machine instead of relying on CAPI copy this information to the InfraMachine / VSphereMachine.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 15, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@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 ask for approval from sbueringer. 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

@jcpowermac jcpowermac changed the title 🐛 fix: use vsphereMachine instead of machine for fd 🐛 fix: set machine spec failuredomain string if not defined Aug 15, 2025
This commit sets the `machine.Spec.FailureDomain` string
from the `vsphereMachine.Spec.FailureDomain` if
defined and the machine failure domain is empty.

This resolves an issue where virtual machines are not placed
within vm-host groups in a timely
manner causing misplacement in the topology.
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a VM to a vm-host group is racy
5 participants