1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 18:27:25 +08:00

Fix issue where instance name rotation was faulty

Previously, if node2 was deleted in a node1, node2, node3 set, the next node creation would fail since it would always try to assign node3 as a name.
Now, the first available name is always assigned.

Signed-off-by: Antonis Kalipetis <akalipetis@gmail.com>
This commit is contained in:
Antonis Kalipetis 2016-11-22 10:42:19 +02:00
parent 861355d4e3
commit dd8f63363e
No known key found for this signature in database
GPG Key ID: 15691170DA0396BB

View File

@ -86,14 +86,28 @@ func CreateInstance(session *Session, dindImage string) (*Instance, error) {
t := true
h.Resources.OomKillDisable = &t
nodeName := fmt.Sprintf("node%d", len(session.Instances)+1)
var nodeName string
var containerName string
for i := 1; ; i++ {
nodeName = fmt.Sprintf("node%d", i)
containerName = fmt.Sprintf("%s_%s", session.Id[:8], nodeName)
exists := false
for _, instance := range session.Instances {
if instance.Name == containerName {
exists = true
break
}
}
if !exists {
break
}
}
conf := &container.Config{Hostname: nodeName, Image: dindImage, Tty: true, OpenStdin: true, AttachStdin: true, AttachStdout: true, AttachStderr: true}
networkConf := &network.NetworkingConfig{
map[string]*network.EndpointSettings{
session.Id: &network.EndpointSettings{Aliases: []string{nodeName}},
},
}
containerName := fmt.Sprintf("%s_%s", session.Id[:8], nodeName)
container, err := c.ContainerCreate(context.Background(), conf, h, networkConf, containerName)
if err != nil {