Skip to content

Docker-machine: Ensure runner stays under limit when IdleCount is 0

Stan Hu requested to merge sh-fix-idle-count-zero into main

What does this MR do?

When IdleCount is 0, machines are always created on-demand before each job (if there is no available machine in Idle state). However, when IdleCount were set to 0 and limit were set to a positive value, the Runner would ignore the limit and attempt to allocate a machine each time.

This change fixes that problem by updating idleLimitStrategy with a new function, canCreateOnDemand, to complement canCreateIdle. The latter returns true if there is capacity to create idle machines for pre-scaling, while the former returns true if there is capacity for on-demand jobs.

We need to make this distinction to ensure that setting idleCount to 0 does not create an infinite number of idle machines in pre-scaling.

When a build attempts to Acquire a machine, we now call canCreateOnDemand to check whether there is capacity to create a machine. We need to do this check before the runner proceeds to the Prepare stage where Use would attempt to allocate a machine. If we performed the check there, the job would fail if limit were reached.

Relates to #36817 (closed)

Edited by Stan Hu

Merge request reports

Loading