make sure pod is completed (succeeded/failed) before pod getting completed time
@@ -191,7 +191,8 @@ func (k *KubernetesAPI) deleteFilteredCheckerPods(ctx context.Context, client *k
for n, v := range reapCheckerPods {
// Delete pods older than maxCheckPodAge and is in status Succeeded
- if v.Status.Phase == v1.PodSucceeded && time.Now().Sub(getPodCompletedTime(v)) > cfg.MaxCheckPodAge {
+ if v.Status.Phase == v1.PodSucceeded {
+ if time.Now().Sub(getPodCompletedTime(v)) > cfg.MaxCheckPodAge {
log.Infoln("checkReaper: Found completed pod older than:", cfg.MaxCheckPodAge, "in status `Succeeded`. Deleting pod:", n)
err = k.deletePod(ctx, v)
@@ -201,9 +202,11 @@ func (k *KubernetesAPI) deleteFilteredCheckerPods(ctx context.Context, client *k
}
delete(reapCheckerPods, n)
}
+ }
// Delete failed pods (status Failed) older than maxCheckPodAge
- if v.Status.Phase == v1.PodFailed && time.Now().Sub(getPodCompletedTime(v)) > cfg.MaxCheckPodAge{
+ if v.Status.Phase == v1.PodFailed {
+ if time.Now().Sub(getPodCompletedTime(v)) > cfg.MaxCheckPodAge {
log.Infoln("checkReaper: Found completed pod older than:", cfg.MaxCheckPodAge, "in status `Failed`. Deleting pod:", n)
err = k.deletePod(ctx, v)
@@ -213,6 +216,7 @@ func (k *KubernetesAPI) deleteFilteredCheckerPods(ctx context.Context, client *k
}
delete(reapCheckerPods, n)
}
+ }
// Delete if there are more than MaxCompletedPodCount checker pods with the same name in status Succeeded that were created more recently
// Delete if the checker pod is Failed and there are more than MaxErrorPodCount checker pods of the same type which were created more recently
