From fb0afd1f59da62d1106159092c68dd675fde7b47 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 17 Sep 2024 15:18:29 -0400 Subject: [PATCH] use DeleteDatabaseAndAccountFinalizers This switches the use of GetDatabaseAndAccount + database.DeleteFinalizers() to use a new function in mariadb DeleteDatabaseAndAccountFinalizers, which looks up each individual component used for database access individually and removes finalizers from all of those that were found, regardless of other elements not existing. All controllers should be changed to use this method to ensure that early-created MariaDBAccount objects are removed from a control plane where MariaDBDatabase objects did not get created before the control plane were deleted, as well as similar scenarios. --- controllers/nova_controller.go | 10 +++------- go.mod | 2 ++ go.sum | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/controllers/nova_controller.go b/controllers/nova_controller.go index dd0844f79..e1dc70a1c 100644 --- a/controllers/nova_controller.go +++ b/controllers/nova_controller.go @@ -1269,15 +1269,11 @@ func (r *NovaReconciler) ensureDBDeletion( // iterate over novaDbs and remove finalizers for _, novaDb := range novaDbs { dbName, accountName := novaDb[0], novaDb[1] - db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, dbName, accountName, instance.ObjectMeta.Namespace) - if err != nil && !k8s_errors.IsNotFound(err) { + + err := mariadbv1.DeleteDatabaseAndAccountFinalizers(ctx, h, dbName, accountName, instance.ObjectMeta.Namespace) + if err != nil { return err } - if !k8s_errors.IsNotFound(err) { - if err := db.DeleteFinalizer(ctx, h); err != nil { - return err - } - } } Log.Info("Removed finalizer from MariaDBDatabase CRs", "MariaDBDatabase names", novaDbs) diff --git a/go.mod b/go.mod index 68eef9213..bf9e8d0b9 100644 --- a/go.mod +++ b/go.mod @@ -85,6 +85,8 @@ require ( replace github.com/openstack-k8s-operators/nova-operator/api => ./api +replace github.com/openstack-k8s-operators/mariadb-operator/api => github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240917193141-8598d28fb998 //allow-merging + // mschuppert: map to latest commit from release-4.13 tag // must consistent within modules and service operators replace github.com/openshift/api => github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 //allow-merging diff --git a/go.sum b/go.sum index a812d6a36..0987142fb 100644 --- a/go.sum +++ b/go.sum @@ -84,8 +84,6 @@ github.com/openstack-k8s-operators/lib-common/modules/openstack v0.4.1-0.2024073 github.com/openstack-k8s-operators/lib-common/modules/openstack v0.4.1-0.20240730142703-7fd3da600c9d/go.mod h1:TyZh5+Uwxb1vcyY44H5GJVulvlQxU05TTAPQ4tSmbzY= github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240730142703-7fd3da600c9d h1:P5tF3/shBcQf0HkPHWcr5Ri+jsRStMPbGOPQw4qRHRI= github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240730142703-7fd3da600c9d/go.mod h1:0h76CxD9g0z2Hk7fGFOZcjnzT1tQQ/yRNv3OXng+S/A= -github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240730222151-2d771bf1a024 h1:AjwCb8Vf/eiTeiDC8jAO4r6U8wklzrI9dejA60gVIMM= -github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240730222151-2d771bf1a024/go.mod h1:2tKZca1jZU3eGKLh7qBoPrN2gg8sIDg6sYioftjRdNQ= 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= @@ -109,6 +107,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU 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/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=