Skip to content

Commit 3956fa9

Browse files
Merge pull request #6 from davidepasquero/codex/forzare-eliminazione-pod-in-stato-terminating
Fix stuck pod cleanup
2 parents cc02cb4 + abc67a7 commit 3956fa9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/util/pod.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
apierrors "k8s.io/apimachinery/pkg/api/errors"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
"k8s.io/apimachinery/pkg/labels"
11+
"k8s.io/apimachinery/pkg/types"
1112
"k8s.io/client-go/kubernetes"
1213
)
1314

@@ -44,6 +45,14 @@ func CleanupTerminatingPods(ctx context.Context, client kubernetes.Interface, na
4445
}
4546

4647
logrus.Infof("(CleanupTerminatingPods) force deleting stuck pod %s/%s", pod.Namespace, pod.Name)
48+
49+
if len(pod.Finalizers) > 0 {
50+
patch := []byte(`{"metadata":{"finalizers":null}}`)
51+
if _, err := client.CoreV1().Pods(pod.Namespace).Patch(ctx, pod.Name, types.MergePatchType, patch, metav1.PatchOptions{}); err != nil && !apierrors.IsNotFound(err) {
52+
logrus.Errorf("(CleanupTerminatingPods) patch pod %s/%s error: %v", pod.Namespace, pod.Name, err)
53+
}
54+
}
55+
4756
grace := int64(0)
4857
if err := client.CoreV1().Pods(pod.Namespace).Delete(ctx, pod.Name, metav1.DeleteOptions{GracePeriodSeconds: &grace}); err != nil && !apierrors.IsNotFound(err) {
4958
logrus.Errorf("(CleanupTerminatingPods) delete pod %s/%s error: %v", pod.Namespace, pod.Name, err)

0 commit comments

Comments
 (0)