mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-16 20:07:25 +08:00
Enumerate nodes to improve cluster configuration
This commit is contained in:
parent
69f9edc695
commit
a7d76f2720
@ -1,12 +1,14 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
@ -77,16 +79,22 @@ func ResizeConnection(name string, cols, rows uint) error {
|
|||||||
return c.ContainerResize(context.Background(), name, types.ResizeOptions{Height: rows, Width: cols})
|
return c.ContainerResize(context.Background(), name, types.ResizeOptions{Height: rows, Width: cols})
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInstance(net string, dindImage string) (*Instance, error) {
|
func CreateInstance(session *Session, dindImage string) (*Instance, error) {
|
||||||
|
|
||||||
h := &container.HostConfig{NetworkMode: container.NetworkMode(net), Privileged: true}
|
h := &container.HostConfig{NetworkMode: container.NetworkMode(session.Id), Privileged: true}
|
||||||
h.Resources.PidsLimit = int64(500)
|
h.Resources.PidsLimit = int64(500)
|
||||||
h.Resources.Memory = 4092 * Megabyte
|
h.Resources.Memory = 4092 * Megabyte
|
||||||
t := true
|
t := true
|
||||||
h.Resources.OomKillDisable = &t
|
h.Resources.OomKillDisable = &t
|
||||||
|
|
||||||
conf := &container.Config{Image: dindImage, Tty: true, OpenStdin: true, AttachStdin: true, AttachStdout: true, AttachStderr: true}
|
nodeName := fmt.Sprintf("node%d", len(session.Instances)+1)
|
||||||
container, err := c.ContainerCreate(context.Background(), conf, h, nil, "")
|
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}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
container, err := c.ContainerCreate(context.Background(), conf, h, networkConf, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -102,7 +110,7 @@ func CreateInstance(net string, dindImage string) (*Instance, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Instance{Name: strings.Replace(cinfo.Name, "/", "", 1), Hostname: cinfo.Config.Hostname, IP: cinfo.NetworkSettings.Networks[net].IPAddress}, nil
|
return &Instance{Name: strings.Replace(cinfo.Name, "/", "", 1), Hostname: cinfo.Config.Hostname, IP: cinfo.NetworkSettings.Networks[session.Id].IPAddress}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteContainer(id string) error {
|
func DeleteContainer(id string) error {
|
||||||
|
@ -54,7 +54,7 @@ func getDindImageName() string {
|
|||||||
|
|
||||||
func NewInstance(session *Session) (*Instance, error) {
|
func NewInstance(session *Session) (*Instance, error) {
|
||||||
log.Printf("NewInstance - using image: [%s]\n", dindImage)
|
log.Printf("NewInstance - using image: [%s]\n", dindImage)
|
||||||
instance, err := CreateInstance(session.Id, dindImage)
|
instance, err := CreateInstance(session, dindImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user