Skip to content

Commit 4851192

Browse files
committed
Merge pull request #2280 from mboersma/scale-does-start
fix(deisctl): "deisctl scale router=N" also starts units
2 parents a8965ab + 40ead56 commit 4851192

3 files changed

Lines changed: 37 additions & 24 deletions

File tree

deisctl/backend/fleet/create.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package fleet
22

33
import (
44
"fmt"
5+
"strings"
56
"sync"
7+
"time"
68

79
"github.com/coreos/fleet/job"
810
"github.com/coreos/fleet/schema"
911
"github.com/coreos/fleet/unit"
1012
)
1113

1214
// Create schedules a new unit for the given component
13-
func (c *FleetClient) Create(targets []string, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
15+
func (c *FleetClient) Create(
16+
targets []string, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
1417

1518
units := make([]*schema.Unit, len(targets))
1619

@@ -53,6 +56,21 @@ func doCreate(c *FleetClient, unit *schema.Unit, wg *sync.WaitGroup, outchan cha
5356
return
5457
}
5558

59+
// loop until the unit actually exists in unit states
60+
outerLoop:
61+
for {
62+
time.Sleep(250 * time.Millisecond)
63+
unitStates, err := cAPI.UnitStates()
64+
if err != nil {
65+
errchan <- err
66+
}
67+
for _, us := range unitStates {
68+
if strings.HasPrefix(us.Name, unit.Name) {
69+
break outerLoop
70+
}
71+
}
72+
}
73+
5674
outchan <- out
5775
}
5876

deisctl/backend/fleet/destroy.go

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,23 @@ func doDestroy(c *FleetClient, target string, wg *sync.WaitGroup, outchan chan s
3232
}
3333
destroyed := fmt.Sprintf("\033[0;33m%v:\033[0m destroyed \r", name)
3434

35-
// bail early if unit doesn't exist
36-
_, err = c.Units(name)
37-
if err != nil {
38-
if strings.Contains(err.Error(), "could not find unit") {
39-
outchan <- destroyed
40-
}
41-
return
42-
}
35+
// tell fleet to destroy the unit
36+
c.Fleet.DestroyUnit(name)
4337

44-
// otherwise destroy it
45-
if err = c.Fleet.DestroyUnit(name); err != nil {
46-
// ignore already destroyed units
47-
if !strings.Contains(err.Error(), "could not find unit") {
48-
errchan <- err
49-
return
50-
}
51-
}
52-
53-
// loop until actually destroyed
38+
// loop until the unit is actually gone from unit states
39+
outerLoop:
5440
for {
55-
_, err = c.Units(name)
41+
time.Sleep(250 * time.Millisecond)
42+
unitStates, err := cAPI.UnitStates()
5643
if err != nil {
57-
if strings.Contains(err.Error(), "could not find unit") {
58-
outchan <- destroyed
59-
return
44+
errchan <- err
45+
}
46+
for _, us := range unitStates {
47+
if strings.HasPrefix(us.Name, name) {
48+
continue outerLoop
6049
}
6150
}
62-
time.Sleep(250 * time.Millisecond)
51+
outchan <- destroyed
52+
return
6353
}
6454
}

deisctl/backend/fleet/scale.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func scaleUp(c *FleetClient, component string, numExistingContainers, numTimesTo
4242
target := component + "@" + strconv.Itoa(numExistingContainers+i+1)
4343
c.Create([]string{target}, wg, outchan, errchan)
4444
}
45+
wg.Wait()
46+
for i := 0; i < numTimesToScale; i++ {
47+
target := component + "@" + strconv.Itoa(numExistingContainers+i+1)
48+
c.Start([]string{target}, wg, outchan, errchan)
49+
}
4550
}
4651

4752
func scaleDown(c *FleetClient, component string, numExistingContainers, numTimesToScale int,

0 commit comments

Comments
 (0)