Skip to content

Commit

Permalink
avoid panic if no idle pods (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen authored Jan 15, 2021
1 parent 5296578 commit 6c4dd70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/githubactionrunner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 10 additions & 7 deletions controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 6c4dd70

Please sign in to comment.