Hi. I have an issue that Pods are not chosen to be deleted if it has owner that's not a Job. In my case I use Tekton pipelines, which will create multiple pods to run the pipelines, and each pod has an owner with kind "TaskRun", not "Job".
I've taken a look at the logic to determine whether a pod is chosen to be deleted:
|
func shouldDeletePod(pod *corev1.Pod, orphaned, pending, evicted, successful, failed time.Duration) bool { |
|
// evicted pods, those with or without owner references, but in Evicted state |
|
// - uses c.deleteEvictedAfter, this one is tricky, because there is no timestamp of eviction. |
|
// So, basically it will be removed as soon as discovered |
|
if pod.Status.Phase == corev1.PodFailed && pod.Status.Reason == "Evicted" && evicted > 0 { |
|
return true |
|
} |
|
owners := getPodOwnerKinds(pod) |
|
podFinishTime := podFinishTime(pod) |
|
if !podFinishTime.IsZero() { |
|
age := time.Since(podFinishTime) |
|
// orphaned pod: those that do not have any owner references |
|
// - uses c.deleteOrphanedAfter |
|
if len(owners) == 0 { |
|
if orphaned > 0 && age >= orphaned { |
|
return true |
|
} |
|
} |
|
// owned by job, have exactly one ownerReference present and its kind is Job |
|
// - uses the c.deleteSuccessfulAfter, c.deleteFailedAfter, c.deletePendingAfter |
|
if isOwnedByJob(owners) { |
|
switch pod.Status.Phase { |
|
case corev1.PodSucceeded: |
|
if successful > 0 && age >= successful { |
|
return true |
|
} |
|
case corev1.PodFailed: |
|
if failed > 0 && age >= failed { |
|
return true |
|
} |
|
default: |
|
return false |
|
} |
|
return false |
|
} |
|
} |
|
if pod.Status.Phase == corev1.PodPending && pending > 0 { |
|
t := podLastTransitionTime(pod) |
|
if t.IsZero() { |
|
return false |
|
} |
|
if time.Now().Sub(t) >= pending { |
|
return true |
|
} |
|
} |
|
return false |
|
} |
. It seems pods can only be deleted in these 2 cases:
- Pod has 0 owner
- Pod has 1 owner, whose kind must be Job
Is it okay to have additional flag to allow deletion of pods that have owner different than Job ? Thanks in advance.
Hi. I have an issue that Pods are not chosen to be deleted if it has owner that's not a Job. In my case I use Tekton pipelines, which will create multiple pods to run the pipelines, and each pod has an owner with kind "TaskRun", not "Job".
I've taken a look at the logic to determine whether a pod is chosen to be deleted:
kube-cleanup-operator/pkg/controller/pod.go
Lines 27 to 73 in 538f00d
Is it okay to have additional flag to allow deletion of pods that have owner different than Job ? Thanks in advance.