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

Add an ability to remove secrets and configmaps when database is gone #168

Merged
merged 3 commits into from
Jan 12, 2023

Conversation

allanger
Copy link
Collaborator

After database resource is removed, there are still some "leftovers". If ownership is set to database resource explicitly, those "leftovers" will be removed with a database.

But since we've faced some unexpected removing of needed secrets in a past, the "cleanup" should be optional.

Close #163

@allanger allanger self-assigned this Dec 15, 2022
if err != nil {
return r.manageError(ctx, dbcr, err, true)
} else if dbSecret != nil && dbcr.Spec.Cleanup {
logrus.Infof("Setting up OwnerReference %v", ownership)
dbSecret.SetOwnerReferences(ownership)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not define the ownership at creation in the related function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've tried to add it to SecretBuilder and ConfigmapBuilder, but they are called from places where there is no context that is required for creating an owner reference. I could add it to the main reconcile function, pass it through a big chain of functions, add conditions everywhere, or just put it here. It may be not the best way of doing this, but otherwise, a lot of code should be restructured, and I'm not sure if it should be done within this PR.

For example, fn SecretBuilder() is called from every function that modifies templateSecrets and connectionString that are called from the main templateSecrets creator function that is moved to database_helper.go. So it was not really obvious where to put the ownership stuff.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would mostly supply the ownership as argument to the function like createInstanceAccessSecret, and apply there the SetOwnerReferences function.

and for the ownership variable definition at 191, think you could only make there the if condition if the ownership is an empty struct or filled with the reference to the db-operator.

But my assumption is also, that an empty ownership struct, should not really do anything at SetOwnerReferences. But maybe I'm wrong.

Another question for me, issue is only about secrets and cm. But we also create the proxy deployment and cronjob. Should we also include this here, or a separate issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, I didn't think about that. I'll try.

I think other resources should be removed too, but I just forgot about them. So I'll do that

@allanger allanger force-pushed the 163-remove-resources-created-by-db branch from d110d7c to 3ec4945 Compare January 11, 2023 14:34
@allanger allanger merged commit 077cf9d into master Jan 12, 2023
@allanger allanger deleted the 163-remove-resources-created-by-db branch January 12, 2023 08:29
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.

ConfigMap and Secret are not deleted when Database is deleted
2 participants