Skip to content

Support cleanup Pods whose owner is not Job #98

@fpt-harley-haitx5

Description

@fpt-harley-haitx5

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions