func (r *Resources) inspectFinalizerPodDrainDBServer(ctx context.Context, log zerolog.Logger, p *v1.Pod, memberStatus api.MemberStatus, updateMember func(api.MemberStatus) error) error {
	if err := r.prepareDBServerPodTermination(ctx, log, p, memberStatus, func(update api.MemberStatus) error {
		if err := updateMember(update); err != nil {
			return errors.WithStack(err)
		}
		memberStatus = update
		return nil
	}); err != nil {
		return errors.WithStack(err)
	}
	if memberStatus.Conditions.IsTrue(api.ConditionTypeCleanedOut) || memberStatus.Phase == api.MemberPhaseDrain {
		err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error {
			return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.DeleteOptions{})
		})
		if err != nil && !k8sutil.IsNotFound(err) {
			log.Warn().Err(err).Msg("Failed to delete PVC for member")
			return errors.WithStack(err)
		}
		log.Debug().Str("pvc-name", memberStatus.PersistentVolumeClaimName).Msg("Removed PVC of member")
	}
	return nil
}
inspectFinalizerPodDrainDBServer checks the finalizer condition for drain-dbserver.
It returns nil if the finalizer can be removed.
package resources
import (
	"context"
	"time"
	"github.com/arangodb/kube-arangodb/pkg/util/errors"
	"github.com/rs/zerolog"
	v1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
	"github.com/arangodb/kube-arangodb/pkg/util"
	"github.com/arangodb/kube-arangodb/pkg/util/constants"
	"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)
const (
	podFinalizerRemovedInterval = util.Interval(time.Second / 2)   
	recheckPodFinalizerInterval = util.Interval(time.Second * 10)  
)
func (r *Resources) runPodFinalizers(ctx context.Context, p *v1.Pod, memberStatus api.MemberStatus, updateMember func(api.MemberStatus) error) (util.Interval, error) {
	log := r.log.With().Str("pod-name", p.GetName()).Logger()
	var removalList []string
	isServerContainerDead := !k8sutil.IsPodServerContainerRunning(p)
	for _, f := range p.ObjectMeta.GetFinalizers() {
		switch f {
		case constants.FinalizerPodAgencyServing:
			log.Debug().Msg("Inspecting agency-serving finalizer")
			if isServerContainerDead {
				log.Debug().Msg("Server Container is dead, removing finalizer")
				removalList = append(removalList, f)
				break
			}
			if err := r.inspectFinalizerPodAgencyServing(ctx, log, p, memberStatus, updateMember); err == nil {
				removalList = append(removalList, f)
			} else {
				log.Debug().Err(err).Str("finalizer", f).Msg("Cannot remove finalizer yet")
			}
		case constants.FinalizerPodDrainDBServer:
			log.Debug().Msg("Inspecting drain dbserver finalizer")
			if isServerContainerDead {
				log.Debug().Msg("Server Container is dead, removing finalizer")
				removalList = append(removalList, f)
				break
			}
			if err := r.inspectFinalizerPodDrainDBServer(ctx, log, p, memberStatus, updateMember); err == nil {
				removalList = append(removalList, f)
			} else {
				log.Debug().Err(err).Str("finalizer", f).Msg("Cannot remove Pod finalizer yet")
			}
		case constants.FinalizerDelayPodTermination:
			if isServerContainerDead {
				log.Debug().Msg("Server Container is dead, removing finalizer")
				removalList = append(removalList, f)
				break
			}
			s, _ := r.context.GetStatus()
			_, group, ok := s.Members.ElementByID(memberStatus.ID)
			if !ok {
				continue
			}
			log.Error().Str("finalizer", f).Msg("Delay finalizer")
			groupSpec := r.context.GetSpec().GetServerGroupSpec(group)
			d := time.Duration(util.IntOrDefault(groupSpec.ShutdownDelay, 0)) * time.Second
			if t := p.ObjectMeta.DeletionTimestamp; t != nil {
				e := p.ObjectMeta.DeletionTimestamp.Time.Sub(time.Now().Add(d))
				log.Error().Str("finalizer", f).Dur("left", e).Msg("Delay finalizer status")
				if e < 0 {
					removalList = append(removalList, f)
				}
			} else {
				continue
			}
		}
	}
	if len(removalList) > 0 {
		if err := k8sutil.RemovePodFinalizers(ctx, r.context.GetCachedStatus(), log, r.context.PodsModInterface(), p, removalList, false); err != nil {
			log.Debug().Err(err).Msg("Failed to update pod (to remove finalizers)")
			return 0, errors.WithStack(err)
		}
		log.Debug().Strs("finalizers", removalList).Msg("Removed finalizer(s) from Pod")
		return podFinalizerRemovedInterval, nil
	}
	return recheckPodFinalizerInterval, nil
}
func (r *Resources) inspectFinalizerPodAgencyServing(ctx context.Context, log zerolog.Logger, p *v1.Pod, memberStatus api.MemberStatus, updateMember func(api.MemberStatus) error) error {
	if err := r.prepareAgencyPodTermination(ctx, log, p, memberStatus, func(update api.MemberStatus) error {
		if err := updateMember(update); err != nil {
			return errors.WithStack(err)
		}
		memberStatus = update
		return nil
	}); err != nil {
		return errors.WithStack(err)
	}
	if memberStatus.Conditions.IsTrue(api.ConditionTypeAgentRecoveryNeeded) {
		err := k8sutil.RunWithTimeout(ctx, func(ctxChild context.Context) error {
			return r.context.PersistentVolumeClaimsModInterface().Delete(ctxChild, memberStatus.PersistentVolumeClaimName, metav1.DeleteOptions{})
		})
		if err != nil && !k8sutil.IsNotFound(err) {
			log.Warn().Err(err).Msg("Failed to delete PVC for member")
			return errors.WithStack(err)
		}
		log.Debug().Str("pvc-name", memberStatus.PersistentVolumeClaimName).Msg("Removed PVC of member so agency can be completely replaced")
	}
	return nil
}