Skip to content

✨ Update logic for HostClaims#3152

Open
pierrecregut wants to merge 1 commit intometal3-io:mainfrom
pierrecregut:feature/hostclaim-update
Open

✨ Update logic for HostClaims#3152
pierrecregut wants to merge 1 commit intometal3-io:mainfrom
pierrecregut:feature/hostclaim-update

Conversation

@pierrecregut
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Update ensures the synchronization between HostClaim and BareMetalHost.

  • Copy HostClaim secrets to BareMetalHost namespace
  • Ensure propagation of reboot annotations
  • Synchronize hostclaim status (mirrors BareMetalHost conditions)

Checklist:

  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • E2E tests have been added, if necessary.
  • Integration tests have been added, if necessary.

@metal3-io-bot
Copy link
Copy Markdown
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 rozzii for approval. For more information see the Code Review Process.

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

Details 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

@metal3-io-bot metal3-io-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 10, 2026
Comment thread pkg/hostclaim/hostclaim_manager.go Outdated
return nil
}

// Update updates a machine and is invoked by the Machine Controller.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Outdated docstrings

Comment thread pkg/hostclaim/hostclaim_manager.go Outdated

// Update updates a machine and is invoked by the Machine Controller.
func (m *HostManager) Update(ctx context.Context) error {
m.Log.Info("Updating machine")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please find and replace all cases of "machine" here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And this should be V(1) too unless we detect that actual changes are needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

return hideConflictError(err)
}

// transient rebootAnnotation was successfully transmitted. We can delete it on HostClaim.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a bit unfortunate: this way it's hard to track when reboot is actually executed. But I don't see a good way out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes and if the HostClaim patch fails we may even reboot twice in rare cases.

m.SetConditionHostToFalse(
metal3api.AssociatedCondition, metal3api.MissingBareMetalHostReason,
"BareMetalHost associated to the claim not found")
return errors.New("BareMetalHost not found")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I"m curious what the expected remediation is. Is a user supposed to delete and re-create the claim? Or is the controller supposed to provide another BMH?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the consumerRef case status.BaremetalHost is reset to nil, so the association logic is performed again (because in the controller introduced later the defer patch will be done as in m3m controller). This was not done here and I have added it.

Comment thread pkg/hostclaim/hostclaim_manager.go Outdated
}
err := m.client.Get(ctx, key, &bmh)
if k8serrors.IsNotFound(err) {
m.Log.Info("Annotated host not found", "bmh", bmhRef.Name, "bmhNamespace", bmhRef.Namespace)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/annotated/linked/ ?

if !consumerRefMatches(bmh.Spec.ConsumerRef, hostClaim) {
m.Log.Info("The consumer ref does not point to the hostClaim", "consumerRef", bmh.Spec.ConsumerRef)
hostClaim.Status.BareMetalHost = nil
return nil, ErrNoBMH
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar question here: what's the expected action in this case? Especially since we only provide a generic error message (which is understandable)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see above.

sourceRef *corev1.SecretReference,
namespace string,
hostName string,
) (*corev1.SecretReference, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This call should exit early if the target namespace is the same as the source namespace (a non-multi-tenant case).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

conditions.SetMirrorCondition(bmh, m.HostClaim, metal3api.ProvisionedCondition)
m.SetConditionHostToTrue(metal3api.AssociatedCondition, metal3api.BareMetalHostAssociatedReason)

if !equality.Semantic.DeepEqual(m.HostClaim.Status, hostOld) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And this is where logging something would actually be useful

bmh.Annotations = map[string]string{}
}

if syncReboot(m.HostClaim.Annotations, bmh.Annotations) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also sync the detachment annotation (also maybe without the "force" flag being introduced in #2955 - i.e. sanitize the value). Detaching is commonly used in my world (e.g. by ACM) to prevent Ironic from further touching the deployed instance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dtantsur I have not modified this part yet. I want to be sure that we want to give control of the Detach annotation to the customer.... An analogy of hostclaim is taking a taxi rather than renting/owning a car: you do not have the keys. With detach, you ask the taxi driver to throw away the keys.... but you still do not have them. As it is done, I do not see a way of sharing the right to detach by both the customer and the infra owner (no consumerOverride).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could have a knob to enable/disable it per HDP. But it's quite important for users to be able isolate their instance from Ironic's power management. It also allows reducing the load on Ironic.

I guess we'd need to re-attach on HostClaim deletion.

Comment thread pkg/hostclaim/hostclaim_manager.go Outdated
}

if err != nil {
m.SetConditionHostToFalse(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe don't update the condition on conflict?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Update ensures the synchronization between HostClaim and BareMetalHost.
* Copy HostClaim secrets to BareMetalHost namespace
* Ensure propagation of reboot annotations
* Synchronize hostclaim status (mirrors BareMetalHost conditions)

Co-authored-by: Pierre Crégut <pierre.cregut@orange.com>
Co-authored-by: Laurent Roussarie <laurent.roussarie@orange.com>
Signed-off-by: Pierre Crégut <pierre.cregut@orange.com>
@pierrecregut pierrecregut force-pushed the feature/hostclaim-update branch from af309eb to 8a95ab0 Compare April 10, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants