From 77350a0223f20376b2118252fcee4b935aa87668 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Fri, 4 Oct 2024 13:20:14 +0200 Subject: [PATCH] tmp --- controllers/nova_controller.go | 44 ++++++++++++++++++++++++++++++++-- go.mod | 2 ++ go.sum | 4 ++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/controllers/nova_controller.go b/controllers/nova_controller.go index 97c046f58..6bf151084 100644 --- a/controllers/nova_controller.go +++ b/controllers/nova_controller.go @@ -829,12 +829,52 @@ func (r *NovaReconciler) ensureCellDeleted( return err } - err = DeleteDatabaseAndAccountFinalizers(ctx, h, dbName, accountName, instance.ObjectMeta.Namespace) + err = mariadbv1.DeleteDatabaseAndAccountFinalizers( + ctx, h, dbName, accountName, instance.Namespace) + if err != nil { + return err + } + account := &mariadbv1.MariaDBAccount{ + ObjectMeta: metav1.ObjectMeta{ + Name: accountName, + Namespace: instance.Namespace, + }, + } + // 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 = r.Client.Delete(ctx, account) if err != nil { return err } - Log.Info("Cell isn't defined in the nova, so deleted cell", "cell", cell) + Log.Info("Deleted MariaDBAccount", "account", account) + + // NOTE(gibi): This is also controversial as we don't know if the account + // secret was created by us by falling back to create the MariaDBAccount. + // Still MariaDBAccount cleanup does not delete the secret so we have to. + err = secret.DeleteSecretsWithName(ctx, h, account.Spec.Secret, instance.Namespace) + if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + + database := &mariadbv1.MariaDBDatabase{ + ObjectMeta: metav1.ObjectMeta{ + Name: dbName, + Namespace: instance.Namespace, + }, + } + err = r.Client.Delete(ctx, database) + if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + Log.Info("Deleted MariaDBDatabase", "database", database) + + Log.Info("Cell isn't defined in the Nova CR any more, so deleted cell", "cell", cell) return nil } diff --git a/go.mod b/go.mod index 5c76f5155..abd93e1ab 100644 --- a/go.mod +++ b/go.mod @@ -88,3 +88,5 @@ replace github.com/openstack-k8s-operators/nova-operator/api => ./api // mschuppert: map to latest commit from release-4.16 tag // must consistent within modules and service operators replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging + +replace github.com/openstack-k8s-operators/mariadb-operator/api => github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240917193141-8598d28fb998 diff --git a/go.sum b/go.sum index 5fee81ccb..1131a3033 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,6 @@ github.com/openstack-k8s-operators/lib-common/modules/openstack v0.4.1-0.2024092 github.com/openstack-k8s-operators/lib-common/modules/openstack v0.4.1-0.20240925091112-d0fa8e528283/go.mod h1:t4Bbcsmzn1Z/0TlAN6Tsr3NXsB7M7EX5bCszfPSXZq4= github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240925091112-d0fa8e528283 h1:tOltAleFLxk3d7Ia8ktGGxCtVIrqqUTUfx/tcfE/zq4= github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240925091112-d0fa8e528283/go.mod h1:LV0jo5etIsGyINpmB37i4oWR8zU6ApIuh7fsqGGA41o= -github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240926100023-0398f9bb0ba5 h1:bNvL9IdLLefFB2C/bGL0QNZvn0lL4gwxgsQFaHg59AM= -github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240926100023-0398f9bb0ba5/go.mod h1:13K91HQShjM0y1zVTupCybaTpWJYzOhMPd+rJUpxIg8= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -114,6 +112,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240917193141-8598d28fb998 h1:n9puB4ZYAEpX4e8GT9TRiKh6biACndHew4dM5xszUiA= +github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240917193141-8598d28fb998/go.mod h1:nu9jPHDKVIrsU2GnrCXH/iW+qf0c3wKwJcHs7zJhK6s= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=