Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cleanup Pods whose owner is not Job #98

Open
fpt-harley-haitx5 opened this issue Aug 26, 2024 · 1 comment
Open

Support cleanup Pods whose owner is not Job #98

fpt-harley-haitx5 opened this issue Aug 26, 2024 · 1 comment

Comments

@fpt-harley-haitx5
Copy link

fpt-harley-haitx5 commented Aug 26, 2024

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.

Repository owner deleted a comment Aug 26, 2024
@lwolf
Copy link
Owner

lwolf commented Aug 31, 2024

Hi. Sorry for the late reply.

Historically the idea was to only cleanup pods owned by jobs and abandoned ones.
But with so many custom operators these days I think it's reasonable to be able to specify additional owners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants