diff --git a/api/v1alpha1/githubactionrunner_types.go b/api/v1alpha1/githubactionrunner_types.go index 8d30386c..fb48ac48 100644 --- a/api/v1alpha1/githubactionrunner_types.go +++ b/api/v1alpha1/githubactionrunner_types.go @@ -54,7 +54,7 @@ const ( // LeastRecent first. LeastRecent SortOrder = "LeastRecent" // MostRecent first. - MostRecent SortOrder = "MostRecent" + MostRecent SortOrder = "MostRecent" ) // SortOrder defines order to sort by when sorting on creation timestamp. diff --git a/controllers/githubactionrunner_controller.go b/controllers/githubactionrunner_controller.go index 368af963..e4318336 100644 --- a/controllers/githubactionrunner_controller.go +++ b/controllers/githubactionrunner_controller.go @@ -135,13 +135,16 @@ func (r *GithubActionRunnerReconciler) handleScaling(ctx context.Context, instan } else if shouldScaleDown(podRunnerPairs, instance) { logger.Info("Scaling down", "runners at github", podRunnerPairs.numRunners(), "maxrunners in CR", instance.Spec.MaxRunners) - pod := podRunnerPairs.getIdlePods(instance.Spec.DeletionOrder)[0] - err := r.DeleteResourceIfExists(ctx, &pod) - if err == nil { - r.GetRecorder().Event(instance, corev1.EventTypeNormal, "Scaling", fmt.Sprintf("Deleted pod %s/%s", pod.Namespace, pod.Name)) - instance.Status.CurrentSize-- - if err := r.GetClient().Status().Update(ctx, instance); err != nil { - return r.manageOutcome(ctx, instance, err) + idlePods := podRunnerPairs.getIdlePods(instance.Spec.DeletionOrder) + if len(idlePods) > 0 { + pod := idlePods[0] + err := r.DeleteResourceIfExists(ctx, &pod) + if err == nil { + r.GetRecorder().Event(instance, corev1.EventTypeNormal, "Scaling", fmt.Sprintf("Deleted pod %s/%s", pod.Namespace, pod.Name)) + instance.Status.CurrentSize-- + if err := r.GetClient().Status().Update(ctx, instance); err != nil { + return r.manageOutcome(ctx, instance, err) + } } }