Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shunki-fujita committed Oct 8, 2024
1 parent 4042238 commit 3d59407
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controllers/pod_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down

0 comments on commit 3d59407

Please sign in to comment.