Skip to content

Commit

Permalink
[horus] Add pod Cleanup Terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
mfordjody committed Sep 25, 2024
1 parent 1b3ba34 commit e0ebdf3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/horus/core/horuser/pod_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package horuser

import (
"context"
"encoding/json"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -46,3 +48,21 @@ func (h *Horuser) Finalizer(clusterName, podName, podNamespace string) error {
_, err := kubeClient.CoreV1().Pods(podNamespace).Patch(ctx, podName, types.JSONPatchType, data, v1.PatchOptions{})
return err
}

func (h *Horuser) Terminating(clusterName string, oldPod *corev1.Pod) bool {
kubeClient := h.kubeClientMap[clusterName]
if kubeClient == nil {
return false
}
newPod, _ := kubeClient.CoreV1().Pods(oldPod.Namespace).Get(context.Background(), oldPod.Name, v1.GetOptions{})
if newPod == nil {
return false
}
if newPod.UID != oldPod.UID {
return false
}
if newPod.DeletionTimestamp.IsZero() {
return false
}
return true
}

0 comments on commit e0ebdf3

Please sign in to comment.