From 561a6fa8c7919f6633db68600df1a40432da007c 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, 6 insertions(+), 10 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 99ce9a962..976e07c60 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/openstack-k8s-operators/lib-common/modules/common v0.4.1-0.20240926101719-8fc1c3da53f7 github.com/openstack-k8s-operators/lib-common/modules/openstack v0.4.1-0.20240926101719-8fc1c3da53f7 github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240926101719-8fc1c3da53f7 - github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240927143624-61d230f582d6 + github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20241008102252-6f4b7a67029f github.com/openstack-k8s-operators/nova-operator/api v0.0.0-20221209164002-f9e6b9363961 go.uber.org/zap v1.27.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 19f130262..12a413494 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ 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.20240926101719-8fc1c3da53f7/go.mod h1:oCopeVBDHbCoPFXOMNAPae/XvPQ3H9Sdaag16HlLZC0= github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240926101719-8fc1c3da53f7 h1:dNf8GQ+6Dv2twGwYlyTfiYttpSESfcQ89p0py2XAbdo= github.com/openstack-k8s-operators/lib-common/modules/test v0.4.1-0.20240926101719-8fc1c3da53f7/go.mod h1:LV0jo5etIsGyINpmB37i4oWR8zU6ApIuh7fsqGGA41o= -github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240927143624-61d230f582d6 h1:t0TJCqVvIR+2ab77er24bjUTS8uR2xJuuXt3cBlom90= -github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20240927143624-61d230f582d6/go.mod h1:13K91HQShjM0y1zVTupCybaTpWJYzOhMPd+rJUpxIg8= +github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20241008102252-6f4b7a67029f h1:Tkg3SwrWfLhlc00MQYYLli5TdUQCxC5KFDq5BToSVaw= +github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20241008102252-6f4b7a67029f/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=