-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: support for central trait preserved
#1564
base: main
Are you sure you want to change the base?
Conversation
Current dependencies on/for this PR: |
c4633a8
to
419d224
Compare
fe1a163
to
6b46642
Compare
419d224
to
651078b
Compare
651078b
to
a2fe03c
Compare
preserved
069c6f1
to
3ee143c
Compare
a2fe03c
to
f4b76ca
Compare
3ee143c
to
e6da879
Compare
e6da879
to
6474c30
Compare
f4b76ca
to
1aa70bc
Compare
I added e2e tests for generic traits and this |
@@ -60,6 +62,10 @@ type CNameRecordStatus struct { | |||
Status *string | |||
} | |||
|
|||
var errPreservedCentral = func(id string) *errors.ServiceError { | |||
return errors.BadRequest("central %q has %s trait", id, constants.CentralTraitPreserved) |
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.
Should be 409 I think. The error message (probably in the caller given there are two) should also include the remediation hint, I guess it will be removing the trait or using force.
@@ -492,6 +498,10 @@ func (k *dinosaurService) RegisterDinosaurDeprovisionJob(ctx context.Context, id | |||
} | |||
metrics.IncreaseCentralTotalOperationsCountMetric(dinosaurConstants.CentralOperationDeprovision) | |||
|
|||
if arrays.Contains(dinosaurRequest.Traits, constants.CentralTraitPreserved) { |
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.
Why do we need a check here in addition to the one during deletion?
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.
This is for the case when the function is called by the HTTP handler: the check allows for returning the error immediately, instead of marking the instance for deletion and fail to delete it later.
@@ -60,6 +63,11 @@ type CNameRecordStatus struct { | |||
Status *string | |||
} | |||
|
|||
var errPreservedCentral = func(id string) *errors.ServiceError { | |||
return errors.NewErrorFromHTTPStatusCode(http.StatusConflict, | |||
"central %q has %s trait, remove the trait to enable deletion", id, constants.CentralTraitPreserved) |
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.
Could you please update the openapi spec to include 409 for delete?
}) | ||
svcErr := k.Delete(preserved, false) | ||
assert.Equal(t, http.StatusConflict, svcErr.HTTPCode) | ||
{ |
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.
This block feels like it should be extracted into a separate function.
Expect(err).ToNot(HaveOccurred(), "no error on checking for existing trait") | ||
|
||
_, err = adminAPI.GetCentralTrait(ctx, id, "test-trait-2") | ||
Expect(err).To(HaveOccurred(), "error on checking for non-existing trait") |
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.
We could assert 404 here.
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.
Made it in #1661.
@@ -575,6 +589,11 @@ func (k *dinosaurService) DeprovisionExpiredDinosaurs() *errors.ServiceError { | |||
// If the force flag is true, then any errors prior to the final deletion of the CentralRequest will be logged as warnings | |||
// but do not interrupt the deletion flow. | |||
func (k *dinosaurService) Delete(centralRequest *dbapi.CentralRequest, force bool) *errors.ServiceError { |
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.
Is the force
option exposed by the console UI? It feels like we are mixing up different concepts a bit. What deletion scenarios are we trying to prevent?
- User deletes their own instance. Do we want to stop anyone from doing this? They will be confused what's going on because the traits are managed via the admin API. Traits will be generally unknown to users, so why expose them to users?
- (Accidental) deletion by admins? Admins control traits, but admin API ignores traits.
- Unwanted/early expiry of instances. Wouldn't it make more sense to prevent expiry in the first place, rather than stop the deprovision of an already expired instance?
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.
No, force
is not exposed. In fact, force=true
if only an admin deletes the central via /centrals/db/{id}
endpoint. I was thinking that this would be the only way to delete a preserved instance, including users not being able to do so.
Your 3rd point makes sense. The trait should be called perpetual
then. We could actually have both traits, but I think perpetual
is more interesting.
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.
No, force is not exposed. In fact, force=true if only an admin deletes the central via /centrals/db/{id} endpoint. I was thinking that this would be the only way to delete a preserved instance, including users not being able to do so.
I think users could interpret this as being forced to pay in case they use on-demand billing. So I don't think this is a good idea. If we want to expose it to users, it would be better to also mark their instance as preserved
in the UI and let them be able to change the state / force delete 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.
IMHO both admin and user API calls to delete instances should be respected despite preserved
trait. If user wants to delete an instance, they should be able to do that without additional steps (they already have to type in instance name in the UI to confirm). If an admin wants to delete a user instance, they most likely have a good reason for it.
@@ -512,6 +524,7 @@ func (k *dinosaurService) DeprovisionDinosaurForUsers(users []string) *errors.Se | |||
Model(&dbapi.CentralRequest{}). | |||
Where("owner IN (?)", users). | |||
Where("status NOT IN (?)", dinosaurDeletionStatuses). | |||
Where("traits IS NULL OR ? != ALL (traits)", dinosaurConstants.CentralTraitPreserved). |
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.
By curiosity, what does ? != ALL (traits)
mean ? And why not use ("? NOT IN traits", CentralTraitPreserved)
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.
This is a specific syntax for column of type array: https://www.postgresql.org/docs/current/arrays.html#ARRAYS-SEARCHING
PR needs rebase. 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-sigs/prow repository. |
@0x656b694d: The following tests failed, say
Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
Make use of #1549: do not deprovision centrals which have "preserved" trait.