avoiding scale under 1, scale up services at 0

This commit is contained in:
Manuel Bovo 2017-07-18 12:26:45 +02:00 committed by Gianluca Arbezzano
parent 29cfd3d109
commit 861fc14781
No known key found for this signature in database
GPG Key ID: 9505D2809E1D6180

View File

@ -96,7 +96,7 @@ func (p SwarmProvider) Scale(serviceId string, target int, direction bool) error
// This function validate if a request is acceptable or not. // This function validate if a request is acceptable or not.
func (p *SwarmProvider) isAcceptable(tasks []swarm.Task, target int, direction bool) error { func (p *SwarmProvider) isAcceptable(tasks []swarm.Task, target int, direction bool) error {
if p.calculateActiveTasks(tasks) < target && direction == false { if p.calculateActiveTasks(tasks) < target || p.calculateActiveTasks(tasks) < 2 && direction == false {
return errors.New(fmt.Sprintf("I can not scale down because it has only %d running.", target)) return errors.New(fmt.Sprintf("I can not scale down because it has only %d running.", target))
} }
return nil return nil