Skip to content

Commit

Permalink
Delete MariaDBAccount and Database
Browse files Browse the repository at this point in the history
Both CR is created by the nova controller for the given cell, so when
that cell is deleted the CRs also needs to be deleted.
  • Loading branch information
gibizer committed Sep 27, 2024
1 parent 8625719 commit 92ac210
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
39 changes: 35 additions & 4 deletions controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,15 +684,46 @@ func DeleteDatabaseAndAccountFinalizers(
return err
}

account, err := mariadbv1.GetAccount(ctx, h, accountName, namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
}
if err == nil {
// NOTE(gibi): this might be controversial as we cannot be sure if
// Nova got a pre-created account from outside or created its own.
// Today it is always the nova controller who creates the Account but
// it might change in the future.
// Still as we need to delete the MariaDBDatabase we need to get rid
// of the Account. Also that Account in that DB will be pointless
// if the DB is gone.
err := h.GetClient().Delete(ctx, account)
if err != nil {
return err
}
util.LogForObject(h, "Deleted MariaDBAccount", account)
}

mariaDBDatabase, err := GetDatabase(ctx, h, name, namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
} else if err == nil && controllerutil.RemoveFinalizer(mariaDBDatabase, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, mariaDBDatabase)
if err != nil && !k8s_errors.IsNotFound(err) {
} else if err == nil {
if controllerutil.RemoveFinalizer(mariaDBDatabase, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, mariaDBDatabase)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
}
util.LogForObject(
h,
fmt.Sprintf(
"Removed finalizer %s from MariaDBDatabase %s", h.GetFinalizer(), mariaDBDatabase.Spec.Name),
mariaDBDatabase)
}

err := h.GetClient().Delete(ctx, mariaDBDatabase)
if err != nil {
return err
}
util.LogForObject(h, fmt.Sprintf("Removed finalizer %s from MariaDBDatabase %s", h.GetFinalizer(), mariaDBDatabase.Spec.Name), mariaDBDatabase)
util.LogForObject(h, "Deleted MariaDBDatabase", mariaDBDatabase)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion test/functional/nova_reconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func CreateNovaWith3CellsAndEnsureReady(novaNames NovaNames) {

cell1Account, cell1Secret := mariadb.CreateMariaDBAccountAndSecret(
cell1.MariaDBAccountName, mariadbv1.MariaDBAccountSpec{})
DeferCleanup(k8sClient.Delete, ctx, cell1Account)
// DeferCleanup(k8sClient.Delete, ctx, cell1Account)
DeferCleanup(k8sClient.Delete, ctx, cell1Secret)

cell2Account, cell2Secret := mariadb.CreateMariaDBAccountAndSecret(
Expand Down

0 comments on commit 92ac210

Please sign in to comment.