20182: Add option to limit the number of supervisor containers
[arvados.git] / lib / dispatchcloud / scheduler / run_queue.go
index 1e5ac2e0466b97730d5eccc9620134d021a66c20..65ca904be0bce50e94cb41824ae43b872a364654 100644 (file)
@@ -15,6 +15,10 @@ import (
 
 var quietAfter503 = time.Minute
 
+func isSupervisor(ctr arvados.Container) bool {
+       return (len(ctr.Command) > 0 && ctr.Command[0] == "arvados-cwl-runner") || ctr.SchedulingParameters.Supervisor
+}
+
 func (sch *Scheduler) runQueue() {
        unsorted, _ := sch.queue.Entries()
        sorted := make([]container.QueueEnt, 0, len(unsorted))
@@ -84,6 +88,8 @@ func (sch *Scheduler) runQueue() {
        // reaches the dynamic maxConcurrency limit.
        trying := len(running)
 
+       supervisors := 0
+
 tryrun:
        for i, ctr := range sorted {
                ctr, it := ctr.Container, ctr.InstanceType
@@ -91,6 +97,12 @@ tryrun:
                        "ContainerUUID": ctr.UUID,
                        "InstanceType":  it.Name,
                })
+               if isSupervisor(ctr) {
+                       supervisors += 1
+                       if sch.maxSupervisors > 0 && supervisors > sch.maxSupervisors {
+                               continue
+                       }
+               }
                if _, running := running[ctr.UUID]; running || ctr.Priority < 1 {
                        continue
                }