Skip to content

Commit e0ebdf3

Browse files
committed
[horus] Add pod Cleanup Terminating
1 parent 1b3ba34 commit e0ebdf3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

app/horus/core/horuser/pod_remove.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package horuser
1717

1818
import (
19+
"context"
1920
"encoding/json"
21+
corev1 "k8s.io/api/core/v1"
2022
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2123
"k8s.io/apimachinery/pkg/types"
2224
"k8s.io/klog/v2"
@@ -46,3 +48,21 @@ func (h *Horuser) Finalizer(clusterName, podName, podNamespace string) error {
4648
_, err := kubeClient.CoreV1().Pods(podNamespace).Patch(ctx, podName, types.JSONPatchType, data, v1.PatchOptions{})
4749
return err
4850
}
51+
52+
func (h *Horuser) Terminating(clusterName string, oldPod *corev1.Pod) bool {
53+
kubeClient := h.kubeClientMap[clusterName]
54+
if kubeClient == nil {
55+
return false
56+
}
57+
newPod, _ := kubeClient.CoreV1().Pods(oldPod.Namespace).Get(context.Background(), oldPod.Name, v1.GetOptions{})
58+
if newPod == nil {
59+
return false
60+
}
61+
if newPod.UID != oldPod.UID {
62+
return false
63+
}
64+
if newPod.DeletionTimestamp.IsZero() {
65+
return false
66+
}
67+
return true
68+
}

0 commit comments

Comments
 (0)