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

Block removing a valid lease in case not owned #11

Merged

Conversation

mshitrit
Copy link
Member

@mshitrit mshitrit commented Aug 30, 2023

ECOPROJECT-1589
Block lease removal in case it is still valid and owned by a different holder

@openshift-ci openshift-ci bot requested review from razo7 and slintes August 30, 2023 14:40
@mshitrit
Copy link
Member Author

/hold

@clobrano
Copy link
Contributor

/lgtm
Giving a chance to get more feedbacks, feel free to unhold
/hold

Signed-off-by: Michael Shitrit <[email protected]>
@@ -227,6 +227,12 @@ func (l *manager) invalidateLease(ctx context.Context, obj client.Object) error
}
return err
}
if l.holderIdentity != *lease.Spec.HolderIdentity {
isLeaseExpired := time.Now().After(lease.Spec.RenewTime.Time.Add(time.Duration(*lease.Spec.LeaseDurationSeconds) * time.Second))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should invalidate not owned leases, even when they expired.

(and nil checks are missing, and we should reuse isValidLease, but that doesn't matter when we remove this...)

Copy link
Member Author

@mshitrit mshitrit Aug 30, 2023

Choose a reason for hiding this comment

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

I don't think we should invalidate not owned leases, even when they expired.

why not ? IIRC RequestLease would work for this use case (i.e we can request a lease owned by a different holder if it is expired)

Copy link
Member

Choose a reason for hiding this comment

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

  • what's the use case for invalidating not owned leases? 🤷🏼‍♂️
  • why adding more code than needed for fixing this bug after code freeze?

Copy link
Member Author

@mshitrit mshitrit Aug 30, 2023

Choose a reason for hiding this comment

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

what's the use case for invalidating not owned leases? 🤷🏼‍♂️

I don't have a particular use case in mind, however I do think it makes sense to align the behavior to that of RequestLease, I think it's quite confusing that we will not allow deleting an expired lease directly (through Invalidate API) but it is fine to do it if we use RequestLease API.

why adding more code than needed for fixing this bug after code freeze?

I do agree that we should minimize code inserted this late before the release, however in this case it's a single "if" statement so IMO the value outweigh the risk.
I think that a better approach to follow this principal would be ATM having a fix only at NHC instead of both repos.

Copy link
Member

Choose a reason for hiding this comment

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

align the behavior to that of RequestLease

There we have clear usecase.

I think it's quite confusing that we will not allow deleting an expired lease

I think it's more confusing to delete leases you don't own. When I create a lease and it's deleted by someone else, at least I would be surprised.

however in this case it's a single "if" statement

which had two missing nil checks in its 1st iteration...

a better approach to follow this principal would be ATM having a fix only at NHC

which would need more code, and would leave the issue here for the next one...

Copy link
Member Author

Choose a reason for hiding this comment

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

ATM looks like we don't agree on whether InvalidateLease should only work on owned leases or not.
In order to get on with the release I've made the change so only owned leases will be Invalidated and we can have further discussion later on.

err = manager.RequestLease(context.Background(), node, leaseDuration)
switch actionOnLease {
case requestLease:
{
Copy link
Member

Choose a reason for hiding this comment

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

unneeded {} in both case blocks

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I don't follow, both requestLease and invalidateLease has { }.
Am I missing something ?

Copy link
Member

Choose a reason for hiding this comment

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

you just don't need them, they are redundant.

Signed-off-by: Michael Shitrit <[email protected]>
Signed-off-by: Michael Shitrit <[email protected]>
Signed-off-by: Michael Shitrit <[email protected]>
@openshift-ci openshift-ci bot added the lgtm label Aug 31, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 31, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clobrano, mshitrit, slintes

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:
  • OWNERS [clobrano,mshitrit,slintes]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mshitrit
Copy link
Member Author

/unhold

@openshift-merge-robot openshift-merge-robot merged commit 30fb25d into medik8s:main Aug 31, 2023
4 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