From 6fba208d9858fb632a3c8daec903eda0711a714f Mon Sep 17 00:00:00 2001 From: Michael Hausenblas Date: Sat, 22 Feb 2020 17:29:13 +0000 Subject: [PATCH] fixes GC Signed-off-by: Michael Hausenblas --- gc.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/gc.go b/gc.go index 7d7edeb..1d04785 100644 --- a/gc.go +++ b/gc.go @@ -7,38 +7,22 @@ import ( var ( // how often we check for orphans: - gcPause = 10 * time.Second - // how long a pod of a terminating dproc can run - // before we consider it an orphan (in seconds): - maxOrphanRuntimeSec = 600.0 + gcPause = 30 * time.Second ) func gcDProcs() { for { - poNstart, err := kubectl(false, "get", "po", - "--selector=dproctype="+string(DProcTerminating), "-o=custom-columns=:metadata.name,:status.startTime", "--field-selector=status.phase=Running", - "--no-headers") + orphandeploys, err := kubectl(false, "get", "deploy", + "--selector=dproctype="+string(DProcTerminating), "-o=custom-columns=:metadata.name", "--no-headers") if err != nil { debug(err.Error()) } - debug(poNstart) - if poNstart != "" { - for _, pns := range strings.Split(poNstart, "\n") { - poname, start := strings.Split(pns, " ")[0], strings.Split(pns, " ")[1] - debug("GC: looking at candidate pod " + poname + " with start timestamp " + start + "\n") - layout := "2006-01-02T15:04:05Z" - st, err := time.Parse(layout, start) + debug(orphandeploys) + if orphandeploys != "" { + for _, d := range strings.Split(orphandeploys, "\n") { + _, err := kubectl(false, "delete", "deploy", d) if err != nil { - debug("GC: couldn't parse start time of pod " + poname) - } - now := time.Now() - diff := now.Sub(st) - if diff.Seconds() > maxOrphanRuntimeSec { - debug("GC: found orphaned pod " + poname + " with a start time of " + st.String()) - _, err = kubectl(false, "delete", "pod", poname) - if err != nil { - warn("GC: couldn't remove orphaned pod " + poname) - } + warn("GC: couldn't reap orphaned deployment " + d) } } }