From d16dfac0f8e93d3592305fb48ce05ee02fff7298 Mon Sep 17 00:00:00 2001 From: Juho Saarinen Date: Wed, 21 Oct 2020 15:32:26 +0300 Subject: [PATCH] Restart if pod ends up succeeded (#136) Fixes #132 --- controllers/runner_controller.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index f49ad49d..4c10b050 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -167,7 +167,11 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { r.Recorder.Event(&runner, corev1.EventTypeNormal, "PodCreated", fmt.Sprintf("Created pod '%s'", newPod.Name)) log.Info("Created runner pod", "repository", runner.Spec.Repository) } else { - if runner.Status.Phase != string(pod.Status.Phase) { + // If pod has ended up succeeded we need to restart it + // Happens e.g. when dind is in runner and run completes + restart := pod.Status.Phase == corev1.PodSucceeded + + if !restart && runner.Status.Phase != string(pod.Status.Phase) { updated := runner.DeepCopy() updated.Status.Phase = string(pod.Status.Phase) updated.Status.Reason = pod.Status.Reason @@ -185,8 +189,6 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return ctrl.Result{}, err } - restart := false - if pod.Status.Phase == corev1.PodRunning { for _, status := range pod.Status.ContainerStatuses { if status.Name != containerName {