Skip to content

Commit 6ac92ab

Browse files
author
Lukas Hybner
committed
Better scale up and down runners
We use ephemeral runners which shutdown after pipeline ends and after this new runners starts. So I change behaviour to scale up new runners when idle runners change to busy. This is change meaning minRunners property to mininum idle Runners. This change respect maxRunners property.
1 parent 81e3004 commit 6ac92ab

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

controllers/githubactionrunner_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func (r *GithubActionRunnerReconciler) handleScaling(ctx context.Context, instan
132132

133133
if shouldScaleUp(podRunnerPairs, instance) {
134134
instance.Status.CurrentSize = podRunnerPairs.numPods()
135-
scale := funk.MaxInt([]int{instance.Spec.MinRunners - podRunnerPairs.numRunners(), 1})
135+
scale := funk.MaxInt([]int{instance.Spec.MinRunners - podRunnerPairs.numRunners(), instance.Spec.MinRunners - podRunnerPairs.numIdle(), 1})
136+
scale = funk.MinInt([]int{scale, instance.Spec.MaxRunners - podRunnerPairs.numRunners()})
136137
logger.Info("Scaling up", "numInstances", scale)
137138

138139
if err := r.scaleUp(ctx, scale, instance); err != nil {
@@ -178,11 +179,11 @@ func (r *GithubActionRunnerReconciler) scaleDown(ctx context.Context, podRunnerP
178179
}
179180

180181
func shouldScaleUp(podRunnerPairs podRunnerPairList, instance *garov1alpha1.GithubActionRunner) bool {
181-
return podRunnerPairs.numRunners() < instance.Spec.MinRunners || (podRunnerPairs.allBusy() && podRunnerPairs.numRunners() < instance.Spec.MaxRunners)
182+
return podRunnerPairs.numIdle() < instance.Spec.MinRunners && podRunnerPairs.numRunners() < instance.Spec.MaxRunners
182183
}
183184

184185
func shouldScaleDown(podRunnerPairs podRunnerPairList, instance *garov1alpha1.GithubActionRunner) bool {
185-
return podRunnerPairs.numRunners() > instance.Spec.MaxRunners || (podRunnerPairs.numIdle() > 1 && (podRunnerPairs.numRunners() > instance.Spec.MinRunners))
186+
return podRunnerPairs.numRunners() > instance.Spec.MaxRunners || podRunnerPairs.numIdle() > instance.Spec.MinRunners
186187
}
187188

188189
func (r *GithubActionRunnerReconciler) manageOutcome(ctx context.Context, instance *garov1alpha1.GithubActionRunner, issue error) (reconcile.Result, error) {

0 commit comments

Comments
 (0)