From 3d59407605f409f661cfc950a914a47bd81c95bd Mon Sep 17 00:00:00 2001 From: shunki-fujita Date: Tue, 8 Oct 2024 03:47:34 +0000 Subject: [PATCH] wip --- controllers/pod_watcher.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/controllers/pod_watcher.go b/controllers/pod_watcher.go index c23401368..fc6adc6ce 100644 --- a/controllers/pod_watcher.go +++ b/controllers/pod_watcher.go @@ -14,6 +14,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" crlog "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -56,6 +57,13 @@ func (r *PodWatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu sts := &appsv1.StatefulSet{} if err := r.Get(ctx, client.ObjectKey{Namespace: pod.Namespace, Name: ref.Name}, sts); err != nil { + if controllerutil.ContainsFinalizer(pod, constants.MySQLClusterPodFinalizer) { + log.Info("removing finalizer", "name", pod.Name) + controllerutil.RemoveFinalizer(pod, constants.MySQLClusterPodFinalizer) + if err := r.Update(ctx, pod); err != nil { + return ctrl.Result{}, err + } + } return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -74,6 +82,13 @@ func (r *PodWatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if pod.DeletionTimestamp != nil { log.Info("detected mysql pod deletion", "name", pod.Name) + if controllerutil.ContainsFinalizer(pod, constants.MySQLClusterPodFinalizer) { + log.Info("removing finalizer", "name", pod.Name) + controllerutil.RemoveFinalizer(pod, constants.MySQLClusterPodFinalizer) + if err := r.Update(ctx, pod); err != nil { + return ctrl.Result{}, err + } + } } else { log.Info("detected demote annotation", "name", pod.Name) }