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

fix(HMS-2757): Do not cascade on pubkey delete #725

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

avitova
Copy link
Member

@avitova avitova commented Oct 17, 2023

So I think this should do. I forgot to set pubkey_id nullable and could not find rollback, so I have two migrations.
Tested scenario: create key, create a reservation with the key, delete the key, GetReservationById.
In this sequence of steps, this all works as expected; we do not have any pubkey id, and GetReservationById returns a response with no pubkey_id. All occurrences of PubkeyId for both responses and pubkey models should be covered by checking for nil pointers, and we should keep in mind, that we do allow empty pointers here.

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Perfect work, there are few nitpicks but overall it is perfect.

internal/migrations/sql/021_remove_delete_cascade.sql Outdated Show resolved Hide resolved
@@ -38,4 +38,7 @@ var (

// ErrReservationRateExceeded is returned when SQL constraint does not allow to insert more reservations
ErrReservationRateExceeded = usrerr.New(429, "rate limit exceeded", "too many reservations, wait and retry")

// ErrPubkeyNotFound is returned when a nil pointer to a pubkey is used for reservation detail
ErrPubkeyNotFound = usrerr.New(404, "pubkey not found", "no pubkey found")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe to stress out the fact that this was caused very likely by deletion (the usecase we see quite often):

Suggested change
ErrPubkeyNotFound = usrerr.New(404, "pubkey not found", "no pubkey found")
ErrPubkeyNotFound = usrerr.New(404, "pubkey not found", "no pubkey found (already deleted?)")

But I have to admit it looks weird, 404 is a 404 period. So feel free to let this wild idea go :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I have modified the message a bit to put the information out there.

Copy link
Member Author

Choose a reason for hiding this comment

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

One more idea, we might want to incorporate a message telling users what can they do to fix this, right?

Copy link
Member

Choose a reason for hiding this comment

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

I thought it cannot be fixed, but sure that is the intention yes.

cmd/spec/example_reservation.go Outdated Show resolved Hide resolved
@avitova
Copy link
Member Author

avitova commented Oct 18, 2023

Thank you for the comments. All of them are addressed, as they were valid. 🎉

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

There are two more anonymous functions but other than that all good.

@@ -58,7 +58,7 @@ func newGCPReservation() *models.GCPReservation {
AccountID: 1,
Status: "Created",
},
PubkeyID: 1,
PubkeyID: func(i int64) *int64 { return &i }(1),
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps here too?

@@ -23,6 +23,7 @@ var (
ErrBothTypeAndTemplateMissing = errors.New("instance type or launch template not set")
ErrUnsupportedRegion = errors.New("unknown region/location/zone")
ErrInvalidNamePattern = errors.New("name pattern is not RFC-1035 compatible")
ErrPubkeyNotFound = errors.New("no pubkey found, it may have been already deleted")
Copy link
Member

Choose a reason for hiding this comment

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

For plain Go errors I would keep it simple:

Suggested change
ErrPubkeyNotFound = errors.New("no pubkey found, it may have been already deleted")
ErrPubkeyNotFound = errors.New("no pubkey found")

Only in "user message" (above) it makes sense I think.

@avitova avitova force-pushed the NoCascade branch 3 times, most recently from 1ac1996 to 153aed0 Compare October 18, 2023 12:31
Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Please check the linter and this can be merged, thank you.

@avitova
Copy link
Member Author

avitova commented Oct 19, 2023

/retest

@lzap
Copy link
Member

lzap commented Oct 19, 2023

That should be resolved now.

/retest

@ezr-ondrej
Copy link
Member

/retest

I suspect the gcp is hitting public IP quota and we are then not having public IP present: https://ci.int.devshift.net/job/RHEnVision-provisioning-backend-pr-check/1975/

@lzap
Copy link
Member

lzap commented Oct 19, 2023

Maybe if we expose private IPs to the UI, we can not rely on public IP at all. Would that help @akhil-jha ?

@ezr-ondrej
Copy link
Member

Ah, I guess I've caused conflict here :( Sorry! :(

internal/payloads/reservation_payload.go Outdated Show resolved Hide resolved
@@ -121,7 +121,7 @@ type GCPReservationResponse struct {
ID int64 `json:"reservation_id" yaml:"reservation_id"`

// Pubkey ID.
PubkeyID int64 `json:"pubkey_id" yaml:"pubkey_id"`
PubkeyID *int64 `json:"pubkey_id,omitempty" yaml:"pubkey_id"`
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@avitova
Copy link
Member Author

avitova commented Oct 20, 2023

Updated the yaml omitempty fields and rebased.

@ezr-ondrej
Copy link
Member

Thank you @avitova ! 🧡

@ezr-ondrej ezr-ondrej merged commit f9724b4 into RHEnVision:main Oct 20, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants