From a8ea0544c6aab935443667eaaea8ab31e587a874 Mon Sep 17 00:00:00 2001 From: "David J. M. Karlsen" Date: Sat, 12 Jun 2021 16:56:09 +0200 Subject: [PATCH 1/2] Unregister evicted pods --- controllers/githubactionrunner_controller.go | 2 +- controllers/podrunner_types.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/githubactionrunner_controller.go b/controllers/githubactionrunner_controller.go index 3594f6c1..7e5a170f 100644 --- a/controllers/githubactionrunner_controller.go +++ b/controllers/githubactionrunner_controller.go @@ -359,7 +359,7 @@ func (r *GithubActionRunnerReconciler) unregisterRunner(ctx context.Context, cr // handleFinalization will remove runner from github based on presence of finalizer func (r *GithubActionRunnerReconciler) handleFinalization(ctx context.Context, cr *garov1alpha1.GithubActionRunner, list podRunnerPairList) error { - for _, item := range list.getPodsBeingDeleted() { + for _, item := range list.getPodsBeingDeletedOrEvicted() { // TODO - cause of failure should be checked more closely, if it does not exist we can ignore it. If it is a comms error we should stick around if err := r.unregisterRunner(ctx, cr, item); err != nil { return err diff --git a/controllers/podrunner_types.go b/controllers/podrunner_types.go index a4e2067f..3a014438 100644 --- a/controllers/podrunner_types.go +++ b/controllers/podrunner_types.go @@ -93,8 +93,8 @@ func (r podRunnerPairList) getIdles(sortOrder v1alpha1.SortOrder, minTTL time.Du return idles } -func (r podRunnerPairList) getPodsBeingDeleted() []podRunnerPair { +func (r podRunnerPairList) getPodsBeingDeletedOrEvicted() []podRunnerPair { return funk.Filter(r.pairs, func(pair podRunnerPair) bool { - return util.IsBeingDeleted(&pair.pod) + return util.IsBeingDeleted(&pair.pod) || IsEvicted(&pair.pod) }).([]podRunnerPair) } From d55f2eff2345da1fa7592d7e8c57c906f0dacfd5 Mon Sep 17 00:00:00 2001 From: "David J. M. Karlsen" Date: Sat, 12 Jun 2021 16:57:53 +0200 Subject: [PATCH 2/2] add missing file --- controllers/podrunner_types.go | 2 +- controllers/podutil.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 controllers/podutil.go diff --git a/controllers/podrunner_types.go b/controllers/podrunner_types.go index 3a014438..3796b548 100644 --- a/controllers/podrunner_types.go +++ b/controllers/podrunner_types.go @@ -95,6 +95,6 @@ func (r podRunnerPairList) getIdles(sortOrder v1alpha1.SortOrder, minTTL time.Du func (r podRunnerPairList) getPodsBeingDeletedOrEvicted() []podRunnerPair { return funk.Filter(r.pairs, func(pair podRunnerPair) bool { - return util.IsBeingDeleted(&pair.pod) || IsEvicted(&pair.pod) + return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod) }).([]podRunnerPair) } diff --git a/controllers/podutil.go b/controllers/podutil.go new file mode 100644 index 00000000..3dffc375 --- /dev/null +++ b/controllers/podutil.go @@ -0,0 +1,10 @@ +package controllers + +import ( + v1 "k8s.io/api/core/v1" + "strings" +) + +func isEvicted(pod *v1.Pod) bool { + return strings.Contains(pod.Status.Reason, "Evicted") +}