From e730d4f7013d11e8cf931801667b496504ebfabe Mon Sep 17 00:00:00 2001 From: Inel Pandzic Date: Mon, 19 Aug 2024 10:42:31 +0200 Subject: [PATCH] Refactor --- api/v1alpha1/perconaservermysql_types.go | 10 ---------- pkg/controller/ps/controller.go | 5 +++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/api/v1alpha1/perconaservermysql_types.go b/api/v1alpha1/perconaservermysql_types.go index f0d3823c7..033ee4bfe 100644 --- a/api/v1alpha1/perconaservermysql_types.go +++ b/api/v1alpha1/perconaservermysql_types.go @@ -840,16 +840,6 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi return nil } -func (cr *PerconaServerMySQL) FinalizerApplied(finalizer string) bool { - for _, f := range cr.GetFinalizers() { - if f == finalizer { - return true - } - } - - return false -} - const ( BinVolumeName = "bin" BinVolumePath = "/opt/percona" diff --git a/pkg/controller/ps/controller.go b/pkg/controller/ps/controller.go index 27857561a..0d12e3a3b 100644 --- a/pkg/controller/ps/controller.go +++ b/pkg/controller/ps/controller.go @@ -42,6 +42,7 @@ import ( k8sretry "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" logf "sigs.k8s.io/controller-runtime/pkg/log" apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1" @@ -190,7 +191,7 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPods(ctx context.Context, cr * // If `delete-mysql-pvc` finalizer is also applied we need to remove all the secrets, // but we need to do it here since there are needed to apply this finalizer. - if cr.FinalizerApplied(naming.FinalizerDeleteMySQLPvc) { + if controllerutil.ContainsFinalizer(cr, naming.FinalizerDeleteMySQLPvc) { secretNames := []string{ cr.Spec.SecretsName, "internal-" + cr.Name, @@ -403,7 +404,7 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPvc(ctx context.Context, cr *a // If `delete-mysql-in-order` finalizer is applied, we will let that handler // remove all the secrets, since they are needed to remove pods in order. - if cr.FinalizerApplied(naming.FinalizerDeletePodsInOrder) { + if controllerutil.ContainsFinalizer(cr, naming.FinalizerDeleteMySQLPvc) { return nil }