From 79a31328a55bec31f6bf77a641734976b6e24551 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sun, 20 Feb 2022 04:42:19 +0000 Subject: [PATCH] Stop recreating ephemeral runner pod Ref https://github.com/actions-runner-controller/actions-runner-controller/issues/911#issuecomment-1046161384 --- controllers/runner_controller.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index d007e9fa..efbb74bc 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -176,6 +176,27 @@ func (r *RunnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // Happens e.g. when dind is in runner and run completes stopped := runnerPodOrContainerIsStopped(&pod) + ephemeral := runner.Spec.Ephemeral == nil || *runner.Spec.Ephemeral + + if stopped && ephemeral { + log.V(1).Info("Ephemeral runner has been stopped successfully. Marking this runner for deletion.") + + // This is the key to make ephemeral runners to work reliably with webhook-based autoscale. + // See https://github.com/actions-runner-controller/actions-runner-controller/issues/911#issuecomment-1046161384 for more context. + // + // In the next reconcilation loop, this triggers a runner unregistration. + // (Note that the unregistration can fail safely because an ephemeral runner usually unregisters itself from GitHub but we do it just for confirmation) + // + // See the code path above that is executed when `runner.ObjectMeta.DeletionTimestamp.IsZero()` isn't true, + // which handles the unregistrationa the removal of the completed pod, and so on. + if err := r.Delete(ctx, &runner); err != nil { + log.V(1).Error(err, "Retrying to mark this runner for deletion in 10 seconds.") + return ctrl.Result{RequeueAfter: 10 * time.Second}, nil + } + + return ctrl.Result{Requeue: true}, nil + } + restart := stopped if registrationOnly && stopped {