Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

✨ Set ownerreference on BareMetalHost #263

Merged
merged 1 commit into from
Feb 25, 2020

Conversation

maelk
Copy link
Member

@maelk maelk commented Feb 21, 2020

What this PR does / why we need it:
This PR adds an Ownerreference on the baremetalhost, set by CAPBM when selecting the baremetalhost. Clusterctl builds a tree of resources using the ownerreferences. the ownerreference is not directly used right now because we still have BMO installed out of the scope of clusterctl, but whenever that will not be the case anymore (i.e. we include BMO deployment in infrastructure-components.yaml) then this ownerreference is a must to ensure that the BMH gets moved along during the pivoting.

@metal3-io-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maelk

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

@metal3-io-bot metal3-io-bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 21, 2020
@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

/test-v1a3-integration

2 similar comments
@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

/test-v1a3-integration

@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

/test-v1a3-integration

@dhellmann
Copy link
Member

Could we get a little more detail about why the existing consumerRef field is insufficient for this?

I've noticed some other patches merging rather quickly this morning. I would like to have time to review this one, so I'm applying a temporary hold.

/hold

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 2020
@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

Sure, this is because clusterctl builds a tree of resources using the ownerreferences. It is not directly used right now because we still have BMO installed out of the scope of clusterctl, but whenever that will not be the case anymore (i.e. we include BMO deployment in infrastructure-components.yaml) then this ownerreference is a must to ensure that the BMH gets moved along during the pivoting. It is duplicating the idea behind consumerRef, but clusterctl does not understand BMH CRs, so it uses a more universal way to build the dependency tree.

Copy link
Member

@dhellmann dhellmann left a comment

Choose a reason for hiding this comment

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

Thanks for updating the description, that makes the change make sense. I have a few code-related questions/comments inline.

@@ -346,6 +346,7 @@ func (m *MachineManager) Delete(ctx context.Context) error {
}

if host != nil && host.Spec.ConsumerRef != nil {
host.OwnerReferences = m.DeleteOwnerRef(host.OwnerReferences)
Copy link
Member

Choose a reason for hiding this comment

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

For the ConsumerRef, we check that it matches the current machine before making any changes. Should we do the same here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The DeleteOwnerRef will only remove the ownerRef pointing to this baremetalmachine only. It will leave the others intact

return refList
}
index, err := m.FindOwnerRef(refList)
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

This logic seems inverted from what I'm used to seeing in go. If this line was if err != nil then the block could return immediately, which would place the shortcut return path closer to the test and keep the more common active path in the main block of the function.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point! I'll fix it

// FindOwnerRef checks if an ownerreference to this baremetal machine exists
// and returns the index
func (m *MachineManager) FindOwnerRef(refList []metav1.OwnerReference) (int, error) {
for i := 0; i < len(refList); i++ {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to use range() here?

Suggested change
for i := 0; i < len(refList); i++ {
for i, curOwnerRef := range(refList) {

Copy link
Member Author

Choose a reason for hiding this comment

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

no, indeed. I will fix it

@@ -1809,18 +1812,25 @@ var _ = Describe("BareMetalMachine manager", func() {
} else {
_, ok := errors.Cause(err).(HasRequeueAfterError)
Expect(ok).To(BeTrue())
return
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it's going to short circuit some of the test logic. Is that the intent? Why return early when a re-queue is expected? Perhaps this is another place where the logic could be flipped and the return kept inside the if/then block and the else block eliminated.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, I have tightened the condition for the return

@dhellmann
Copy link
Member

/hold cancel

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 2020
@mhrivnak
Copy link
Member

A main reason we did not add such an owner reference to BMH previously was that it does not make sense to cascade-delete a BMH. Is that accounted for somehow with this change?

@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

When deleting the Baremetalmachine, capbm will block the deletion with a finalizer until the BMH is back to "ready" state. The first operation of the deprovisioning is to remove the ownerReference. So when the Baremetalmachine is garbage collected, the BMH does not have an ownerreference to the baremetalmachine anymore and is not deleted. Is this sufficient in your opinion, or do you foresee corner-cases ?

@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

/test-v1a3-integration

@dhellmann
Copy link
Member

When deleting the Baremetalmachine, capbm will block the deletion with a finalizer until the BMH is back to "ready" state. The first operation of the deprovisioning is to remove the ownerReference. So when the Baremetalmachine is garbage collected, the BMH does not have an ownerreference to the baremetalmachine anymore and is not deleted. Is this sufficient in your opinion, or do you foresee corner-cases ?

So when a BMM is deleted, first the owner reference is removed and then deprovisioning starts? And after deprovisioning is done then the finalizer is removed from the BMM and it is deleted?

@maelk
Copy link
Member Author

maelk commented Feb 21, 2020

Yes, that's the workflow

@mhrivnak
Copy link
Member

When deleting the Baremetalmachine, capbm will block the deletion with a finalizer until the BMH is back to "ready" state. The first operation of the deprovisioning is to remove the ownerReference. So when the Baremetalmachine is garbage collected, the BMH does not have an ownerreference to the baremetalmachine anymore and is not deleted. Is this sufficient in your opinion, or do you foresee corner-cases ?

Sounds reasonable to me. Thanks for the explanation.

@kashifest
Copy link
Member

Looks good to me

@kashifest
Copy link
Member

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 25, 2020
@metal3-io-bot metal3-io-bot merged commit 50a9742 into metal3-io:master Feb 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. 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.

5 participants