-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add support to MHC created CR #111
Conversation
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>
Skipping CI for Draft Pull Request. |
[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 |
/test? |
@clobrano: The following commands are available to trigger required jobs:
Use In response to this:
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. |
/test 4.15-openshift-e2e |
There was a problem hiding this 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>
c151227
to
ecf2c95
Compare
/test 4.14-openshift-e2e |
// turns it means that the Machine must exist in the cluster, otherwise an error is returned. | ||
mustExist := machineName == "" | ||
|
||
if machineName == "" && len(remediation.GetOwnerReferences()) > 0 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 isUnhandledMachine
in 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 😄
There was a problem hiding this comment.
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 :)
Converting the PR to draft to prevent all tests to run |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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>
/test 4.14-openshift-e2e |
/lgtm |
/retest |
/unhold |
No description provided.