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

feat: support for central trait preserved #1564

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

parametalol
Copy link
Contributor

@parametalol parametalol commented Jan 15, 2024

Make use of #1549: do not deprovision centrals which have "preserved" trait.

  • E2E tests for the traits.

@parametalol
Copy link
Contributor Author

parametalol commented Jan 15, 2024

Current dependencies on/for this PR:

@parametalol parametalol mentioned this pull request Jan 15, 2024
9 tasks
@parametalol parametalol force-pushed the michael/central-trait-preserved branch from c4633a8 to 419d224 Compare January 15, 2024 13:37
@parametalol parametalol force-pushed the michael/central-trait-preserved branch from 419d224 to 651078b Compare January 15, 2024 14:16
@parametalol parametalol force-pushed the michael/central-trait-preserved branch from 651078b to a2fe03c Compare January 16, 2024 13:58
@parametalol parametalol changed the title michael/central-trait-preserved feat: support for central trait preserved Jan 16, 2024
@kovayur kovayur force-pushed the michael/central-trait-preserved branch from a2fe03c to f4b76ca Compare January 17, 2024 10:09
@parametalol parametalol changed the base branch from michael/central-labels to michael/central-traits January 18, 2024 09:24
@parametalol parametalol force-pushed the michael/central-trait-preserved branch from f4b76ca to 1aa70bc Compare January 18, 2024 09:25
@parametalol
Copy link
Contributor Author

I think we need an e2e test here as well that actually executes the query.

I added e2e tests for generic traits and this preserved trait specifically.

@@ -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)
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Contributor

@stehessel stehessel Feb 13, 2024

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)
{
Copy link
Contributor

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")
Copy link
Contributor

@stehessel stehessel Feb 13, 2024

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

@stehessel stehessel Feb 13, 2024

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?

  1. 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?
  2. (Accidental) deletion by admins? Admins control traits, but admin API ignores traits.
  3. 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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@parametalol parametalol mentioned this pull request Feb 15, 2024
9 tasks
@@ -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).
Copy link
Collaborator

@ludydoo ludydoo Mar 25, 2024

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)

Copy link
Contributor Author

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

@openshift-merge-robot
Copy link
Collaborator

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.

Copy link
Contributor

openshift-ci bot commented May 28, 2024

@0x656b694d: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e 4420c77 link true /test e2e
ci/prow/images 4420c77 link true /test images

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.

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.

6 participants