Skip to content

Commit

Permalink
feat(hatchery/swarm): get register error from docker (#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored and yesnault committed Dec 3, 2018
1 parent 8db52b8 commit 558f97f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion engine/hatchery/swarm/swarm_util_kill.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package swarm

import (
"fmt"
"io/ioutil"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -37,11 +39,36 @@ func (h *HatcherySwarm) killAndRemove(dockerClient *dockerClient, ID string) err
log.Error("hatchery> swarm> killAndRemove> unable to get model from registering container %s", container.Name)
} else {
if err := hatchery.CheckWorkerModelRegister(h, modelID); err != nil {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2)
defer cancel()
logsOpts := types.ContainerLogsOptions{
Details: true,
ShowStderr: true,
ShowStdout: true,
Timestamps: true,
Since: "10s",
}
var spawnErr = sdk.SpawnErrorForm{
Error: err.Error(),
}

logsReader, errL := dockerClient.ContainerLogs(ctx, container.ID, logsOpts)
if errL != nil {
log.Error("hatchery> swarm> killAndRemove> cannot get logs from docker for containers service %s %v : %v", container.ID, container.Name, errL)
spawnErr.Logs = []byte(fmt.Sprintf("unable to get container logs: %v", errL))

} else if logsReader != nil {
defer logsReader.Close()
logs, errR := ioutil.ReadAll(logsReader)
if errR != nil {
log.Error("hatchery> swarm> killAndRemove> cannot read logs for containers service %s %v : %v", container.ID, container.Name, errR)
} else if logs != nil {
spawnErr.Logs = logs
}
}

if err := h.CDSClient().WorkerModelSpawnError(modelID, spawnErr); err != nil {
log.Error("CheckWorkerModelRegister> error on call client.WorkerModelSpawnError on worker model %d for register: %s", modelID, err)
log.Error("hatchery> swarm> killAndRemove> error on call client.WorkerModelSpawnError on worker model %d for register: %s", modelID, err)
}
}
}
Expand Down

0 comments on commit 558f97f

Please sign in to comment.