Skip to content
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

Add support to MHC created CR #111

Merged

Conversation

clobrano
Copy link
Contributor

No description provided.

Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
Copy link
Contributor

openshift-ci bot commented Dec 16, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

openshift-ci bot commented Dec 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clobrano

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

@clobrano clobrano changed the title Add support to MHC created CR [WIP] Add support to MHC created CR Dec 16, 2023
@clobrano
Copy link
Contributor Author

/test?

Copy link
Contributor

openshift-ci bot commented Dec 17, 2023

@clobrano: The following commands are available to trigger required jobs:

  • /test 4.12-ci-bundle-machine-deletion-remediation-bundle
  • /test 4.12-images
  • /test 4.12-openshift-e2e
  • /test 4.12-unit
  • /test 4.13-ci-bundle-machine-deletion-remediation-bundle
  • /test 4.13-images
  • /test 4.13-openshift-e2e
  • /test 4.13-unit
  • /test 4.14-ci-bundle-machine-deletion-remediation-bundle
  • /test 4.14-images
  • /test 4.14-openshift-e2e
  • /test 4.14-unit
  • /test 4.15-ci-bundle-machine-deletion-remediation-bundle
  • /test 4.15-images
  • /test 4.15-openshift-e2e
  • /test 4.15-unit

Use /test all to run all jobs.

In response to this:

/test?

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/test-infra repository.

@clobrano
Copy link
Contributor Author

/test 4.15-openshift-e2e

Copy link
Member

@razo7 razo7 left a comment

Choose a reason for hiding this comment

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

Still a WIP but I saw some stuff that can be addressed now.

In case the MDR CR is created by MHC
- get the remediation target Machine from CR's ownerReference of Kind
  "Machine"
- Ignore if the target Machine has no Nodes

Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
@clobrano
Copy link
Contributor Author

/test 4.14-openshift-e2e

@clobrano clobrano marked this pull request as ready for review December 20, 2023 08:53
@clobrano clobrano changed the title [WIP] Add support to MHC created CR Add support to MHC created CR Dec 20, 2023
// turns it means that the Machine must exist in the cluster, otherwise an error is returned.
mustExist := machineName == ""

if machineName == "" && len(remediation.GetOwnerReferences()) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

machineName == "" can be replaced with mustExist

Copy link
Member

Choose a reason for hiding this comment

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

technically yes, semantically not so much IMHO...

Copy link
Member

Choose a reason for hiding this comment

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

I think this pattern is confusing.

someBool :=  someEvaluation
if someEvaluation {
// Do something
}

When I read this sort of code I immediately wonder why wasn't boolean used in the if clause since the exact same evaluation was done one line before.
I suggest either add a comment on mustExist that explains that, or use a different name than mustExist that will explain it.

Copy link
Member

Choose a reason for hiding this comment

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

or use a different name

+1
maybe something like isUnhandledMachine, which explains the situation, and implies indirectly that the machine has to exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a specific comment to mustExist in the change below, together with a rework of the logic. @mshitrit what do you think?

16570a4 l

Copy link
Member

@mshitrit mshitrit Dec 25, 2023

Choose a reason for hiding this comment

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

I think it's better with the comment rather than without, but it still doesn't explain why we are not using the boolean in the if clause.
Let me suggest the following refactoring:

//this method will contain all the logic of getting the machineName (annotation/ownerRef or remediation)
machineName, machineNs, err := getMachineData(remediation, MachineNameNsAnnotation)
...
if err := r.Get(ctx, key, machine); err != nil {
..
  if  isMachineNameExistInAnnotation(remediation, MachineNameNsAnnotation){
  ...

I think it'll make the code much clearer, one downside is that we might need to get the data from the annotation twice- but IMO it is worth the trade-off.

In any case feel free to use different method name, or disregard completely - I don't think this is major enough to block on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your point. Maybe we can get the same result renaming mustExist as you suggested in isUnhandledMachine (as suggested by Marc)?

I propose this because I think that isMachineNameExistInAnnotation would still need an explanation as well as mustExist does. Changing the name I could write something like (kind of pseudo code)

name, ns := getDataFromAnnotation()

isUnhandledMachine := name == ""

if isUnhandledMachine {
  // get the Machine from the cluster
}

wdyt?

Copy link
Member

@mshitrit mshitrit Dec 31, 2023

Choose a reason for hiding this comment

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

In general I think it's a good idea to use isUnhandledMachine in the if clause instead of evaluating name == "" again, which I find confusing.
I also think that isUnhandledMachine is a better name.

I do think this is still a bit confusing because isUnhandledMachine value may not reflect the actual logic.
IIUC We only decide that the machine is unhandled after we also check ownerRef & remediation.
So to put it in other words isUnhandledMachine value may equal true when logically it is actually need to be false.

Another option is just to rename isMachineNameExistInAnnotation method to isUnhandledMachinein my original suggestion.

In any case I do think your suggestion is better than the current status and in any case I consider this a NIT so do feel free to implement it as you decide best 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's merge this now then, I'll follow up with a specific PR :)

@clobrano
Copy link
Contributor Author

Converting the PR to draft to prevent all tests to run

Copy link
Member

@slintes slintes left a comment

Choose a reason for hiding this comment

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

I don't think it makes a difference in the code, but just as a reminder: CR created by NHC can also have Machine owners (needed for Metal3 remediation)

@@ -625,3 +667,18 @@ func (r *MachineDeletionRemediationReconciler) getMachineOwnerSpecReplicas(ctx c
}
return int(replicas), nil
}

func (r *MachineDeletionRemediationReconciler) getMachineKindAndNamespace(ctx context.Context) (kind, namespace string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

seems to be unused

@@ -576,6 +588,36 @@ func (r *MachineDeletionRemediationReconciler) getMachineOwnerNodes(ctx context.
return machineOwnerNodes, nil
}

func (r *MachineDeletionRemediationReconciler) getMachineNameNsFromCR(ctx context.Context, remediation *v1alpha1.MachineDeletionRemediation) (machineName, machineNs string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe rename to ...FromName, for similar to ...FromOwnerReference?

Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
For coherence with getMachineNameNsFromOwnerReference, rename
getMachineNameNsFromCR into getMachineNameNsFromRemediationName.

Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
Signed-off-by: Carlo Lobrano <c.lobrano@gmail.com>
@clobrano
Copy link
Contributor Author

/test 4.14-openshift-e2e

@mshitrit
Copy link
Member

/lgtm
/hold
I left a suggestion for some refactoring but not blocking on it.

@clobrano
Copy link
Contributor Author

clobrano commented Jan 2, 2024

/retest

@clobrano
Copy link
Contributor Author

clobrano commented Jan 2, 2024

/unhold
I will address the rest of the remarks in a following PR

@openshift-merge-bot openshift-merge-bot bot merged commit 1bac83e into medik8s:main Jan 2, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants