8000 fix(hatchery:swarm): clean service remove useless condition · ovh/cds@b87954a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b87954a

Browse files
committed
fix(hatchery:swarm): clean service remove useless condition
1 parent b5de1c1 commit b87954a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

engine/hatchery/swarm/swarm.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ func (h *HatcherySwarm) listAwolWorkers(dockerClientName string, containers []ty
626626
//Checking workers
627627
oldContainers := []types.Container{}
628628
for _, c := range workers {
629-
if !strings.Contains(c.Status, "Exited") && time.Now().Add(-1*time.Minute).Unix() < c.Created {
629+
if !strings.Contains(c.Status, "Exited") && time.Now().Add(-3*time.Minute).Unix() < c.Created {
630630
log.Debug("hatchery> swarm> listAwolWorkers> container %s(status=%s) is too young", c.Names[0], c.Status)
631631
continue
632632
}
@@ -681,12 +681,25 @@ func (h *HatcherySwarm) killAwolWorker(ctx context.Context) error {
681681
}
682682
}
683683

684+
// creating a map of containers names
685+
mContainers := map[string]struct{}{}
686+
for i := range containers {
687+
name := strings.TrimPrefix(containers[i].Names[0], "/") // docker returns name prefixed by a /
688+
mContainers[name] = struct{}{}
689+
}
690+
684691
// Checking services
685692
for _, c := range containers {
686-
if c.Labels["service_worker"] == "" || c.Names[0] != c.Labels["service_worker"] {
693+
// checks if the container is a service based on its labels
694+
if c.Labels["service_worker"] == "" {
687695
continue
688696
}
689-
if !strings.Contains(c.Status, "Exited") && time.Now().Add(-1*time.Minute).Unix() < c.Created {
697+
// if the worker associated to this service is still alive do not kill the service
698+
if _, workerStillAlive := mContainers[c.Labels["service_worker"]]; workerStillAlive {
699+
continue
700+
}
701+
702+
if !strings.Contains(c.Status, "Exited") && time.Now().Add(-3*time.Minute).Unix() < c.Created {
690703
log.Debug("hatchery> swarm> killAwolWorker> container %s(status=%s) is too young - service associated to worker %s", c.Names[0], c.Status, c.Labels["service_worker"])
691704
continue
692705
}

engine/hatchery/swarm/swarm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestHatcherySwarm_ListAwolWorker(t *testing.T) {
8585
h.Config.Name = "swarmy"
8686

8787
now := time.Now()
88-
d1h := now.Add(-2 * time.Minute)
88+
d1h := now.Add(-5 * time.Minute)
8989
containers := []types.Container{
9090
{
9191
ID: "swarmy-model1-w1",

0 commit comments

Comments
 (0)
0