Updating cluster

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Nishant Totla 2016-03-22 14:48:00 -07:00
parent 48cd1ebd69
commit 11df80601c
No known key found for this signature in database
GPG Key ID: 7EA5781C9B3D0C19
4 changed files with 34 additions and 26 deletions

View File

@ -647,7 +647,7 @@ func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if image := r.Form.Get("fromImage"); image != "" { //pull if image := r.Form.Get("fromImage"); image != "" { //pull
authConfig := dockerclient.AuthConfig{} authConfig := apitypes.AuthConfig{}
buf, err := base64.URLEncoding.DecodeString(r.Header.Get("X-Registry-Auth")) buf, err := base64.URLEncoding.DecodeString(r.Header.Get("X-Registry-Auth"))
if err == nil { if err == nil {
json.Unmarshal(buf, &authConfig) json.Unmarshal(buf, &authConfig)

View File

@ -57,7 +57,7 @@ type Cluster interface {
// `callback` can be called multiple time // `callback` can be called multiple time
// `where` is where it is being pulled // `where` is where it is being pulled
// `status` is the current status, like "", "in progress" or "downloaded // `status` is the current status, like "", "in progress" or "downloaded
Pull(name string, authConfig *dockerclient.AuthConfig, callback func(where, status string, err error)) Pull(name string, authConfig *types.AuthConfig, callback func(where, status string, err error))
// Import image // Import image
// `callback` can be called multiple time // `callback` can be called multiple time

View File

@ -15,6 +15,8 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
containertypes "github.com/docker/engine-api/types/container"
networktypes "github.com/docker/engine-api/types/network"
"github.com/docker/swarm/cluster" "github.com/docker/swarm/cluster"
"github.com/docker/swarm/cluster/mesos/task" "github.com/docker/swarm/cluster/mesos/task"
"github.com/docker/swarm/scheduler" "github.com/docker/swarm/scheduler"
@ -183,14 +185,14 @@ func (c *Cluster) UnregisterEventHandler(h cluster.EventHandler) {
func (c *Cluster) StartContainer(container *cluster.Container, hostConfig *dockerclient.HostConfig) error { func (c *Cluster) StartContainer(container *cluster.Container, hostConfig *dockerclient.HostConfig) error {
// if the container was started less than a second ago in detach mode, do not start it // if the container was started less than a second ago in detach mode, do not start it
if time.Now().Unix()-container.Created > 1 || container.Config.Labels[cluster.SwarmLabelNamespace+".mesos.detach"] != "true" { if time.Now().Unix()-container.Created > 1 || container.Config.Labels[cluster.SwarmLabelNamespace+".mesos.detach"] != "true" {
return container.Engine.StartContainer(container.Id, hostConfig) return container.Engine.StartContainer(container.ID, hostConfig)
} }
return nil return nil
} }
// CreateContainer for container creation in Mesos task // CreateContainer for container creation in Mesos task
func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (*cluster.Container, error) { func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string, authConfig *types.AuthConfig) (*cluster.Container, error) {
if config.Memory == 0 && config.CpuShares == 0 { if config.Memory == 0 && config.CPUShares == 0 {
return nil, errResourcesNeeded return nil, errResourcesNeeded
} }
@ -263,7 +265,7 @@ func (c *Cluster) CreateNetwork(request *types.NetworkCreate) (*types.NetworkCre
if len(parts) == 2 { if len(parts) == 2 {
// a node was specified, create the container only on this node // a node was specified, create the container only on this node
request.Name = parts[1] request.Name = parts[1]
config = cluster.BuildContainerConfig(dockerclient.ContainerConfig{Env: []string{"constraint:node==" + parts[0]}}) config = cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==" + parts[0]}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{})
} }
c.scheduler.Lock() c.scheduler.Lock()
@ -363,7 +365,7 @@ func (c *Cluster) RemoveImage(image *cluster.Image) ([]types.ImageDelete, error)
} }
// Pull pulls images on the cluster nodes // Pull pulls images on the cluster nodes
func (c *Cluster) Pull(name string, authConfig *dockerclient.AuthConfig, callback func(where, status string, err error)) { func (c *Cluster) Pull(name string, authConfig *types.AuthConfig, callback func(where, status string, err error)) {
} }
@ -596,7 +598,7 @@ func (c *Cluster) LaunchTask(t *task.Task) bool {
// We can use this to find the right container. // We can use this to find the right container.
inspect := []dockerclient.ContainerInfo{} inspect := []dockerclient.ContainerInfo{}
if data != nil && json.Unmarshal(data, &inspect) == nil && len(inspect) == 1 { if data != nil && json.Unmarshal(data, &inspect) == nil && len(inspect) == 1 {
container := &cluster.Container{Container: dockerclient.Container{Id: inspect[0].Id}, Engine: s.engine} container := &cluster.Container{Container: types.Container{ID: inspect[0].Id}, Engine: s.engine}
if container, err := container.Refresh(); err == nil { if container, err := container.Refresh(); err == nil {
if !t.Stopped() { if !t.Stopped() {
t.SetContainer(container) t.SetContainer(container)
@ -644,10 +646,14 @@ func (c *Cluster) BuildImage(buildImage *types.ImageBuildOptions, out io.Writer)
c.scheduler.Lock() c.scheduler.Lock()
// get an engine // get an engine
config := &cluster.ContainerConfig{dockerclient.ContainerConfig{ config := &cluster.ContainerConfig{
CpuShares: buildImage.CPUShares, HostConfig: containertypes.HostConfig{
Memory: buildImage.Memory, Resources: containertypes.Resources{
}} CPUShares: buildImage.CPUShares,
Memory: buildImage.Memory,
},
},
}
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config) nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
c.scheduler.Unlock() c.scheduler.Unlock()
if err != nil { if err != nil {

View File

@ -15,6 +15,8 @@ import (
"github.com/docker/docker/pkg/discovery" "github.com/docker/docker/pkg/discovery"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
containertypes "github.com/docker/engine-api/types/container"
networktypes "github.com/docker/engine-api/types/network"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/docker/swarm/cluster" "github.com/docker/swarm/cluster"
"github.com/docker/swarm/scheduler" "github.com/docker/swarm/scheduler"
@ -30,12 +32,14 @@ type pendingContainer struct {
func (p *pendingContainer) ToContainer() *cluster.Container { func (p *pendingContainer) ToContainer() *cluster.Container {
container := &cluster.Container{ container := &cluster.Container{
Container: dockerclient.Container{ Container: types.Container{
Labels: p.Config.Labels, Labels: p.Config.Labels,
}, },
Config: p.Config, Config: p.Config,
Info: dockerclient.ContainerInfo{ Info: types.ContainerJSON{
HostConfig: &dockerclient.HostConfig{}, ContainerJSONBase: &types.ContainerJSONBase{
HostConfig: &containertypes.HostConfig{},
},
}, },
Engine: p.Engine, Engine: p.Engine,
} }
@ -134,7 +138,7 @@ func (c *Cluster) generateUniqueID() string {
// StartContainer starts a container // StartContainer starts a container
func (c *Cluster) StartContainer(container *cluster.Container, hostConfig *dockerclient.HostConfig) error { func (c *Cluster) StartContainer(container *cluster.Container, hostConfig *dockerclient.HostConfig) error {
return container.Engine.StartContainer(container.Id, hostConfig) return container.Engine.StartContainer(container.ID, hostConfig)
} }
// CreateContainer aka schedule a brand new container into the cluster. // CreateContainer aka schedule a brand new container into the cluster.
@ -178,11 +182,11 @@ func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string,
config.SetSwarmID(swarmID) config.SetSwarmID(swarmID)
} }
if network := c.Networks().Get(config.HostConfig.NetworkMode); network != nil && network.Scope == "local" { if network := c.Networks().Get(string(config.HostConfig.NetworkMode)); network != nil && network.Scope == "local" {
if !config.HaveNodeConstraint() { if !config.HaveNodeConstraint() {
config.AddConstraint("node==~" + network.Engine.Name) config.AddConstraint("node==~" + network.Engine.Name)
} }
config.HostConfig.NetworkMode = network.Name config.HostConfig.NetworkMode = containertypes.NetworkMode(network.Name)
} }
if withImageAffinity { if withImageAffinity {
@ -475,7 +479,7 @@ func (c *Cluster) CreateNetwork(request *types.NetworkCreate) (response *types.N
if len(parts) == 2 { if len(parts) == 2 {
// a node was specified, create the container only on this node // a node was specified, create the container only on this node
request.Name = parts[1] request.Name = parts[1]
config = cluster.BuildContainerConfig(dockerclient.ContainerConfig{Env: []string{"constraint:node==" + parts[0]}}) config = cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==" + parts[0]}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{})
} }
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config) nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
@ -536,7 +540,7 @@ func (c *Cluster) CreateVolume(request *types.VolumeCreateRequest) (*cluster.Vol
wg.Wait() wg.Wait()
} else { } else {
config := cluster.BuildContainerConfig(dockerclient.ContainerConfig{Env: []string{"constraint:node==" + parts[0]}}) config := cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==" + parts[0]}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{})
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config) nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -580,7 +584,7 @@ func (c *Cluster) RemoveVolumes(name string) (bool, error) {
} }
// Pull is exported // Pull is exported
func (c *Cluster) Pull(name string, authConfig *dockerclient.AuthConfig, callback func(where, status string, err error)) { func (c *Cluster) Pull(name string, authConfig *types.AuthConfig, callback func(where, status string, err error)) {
var wg sync.WaitGroup var wg sync.WaitGroup
c.RLock() c.RLock()
@ -908,11 +912,9 @@ func (c *Cluster) BuildImage(buildImage *types.ImageBuildOptions, out io.Writer)
c.scheduler.Lock() c.scheduler.Lock()
// get an engine // get an engine
config := cluster.BuildContainerConfig(dockerclient.ContainerConfig{ config := cluster.BuildContainerConfig(containertypes.Config{Env: convertMapToKVStrings(buildImage.BuildArgs)},
CpuShares: buildImage.CPUShares, containertypes.HostConfig{Resources: containertypes.Resources{CPUShares: buildImage.CPUShares, Memory: buildImage.Memory}},
Memory: buildImage.Memory, networktypes.NetworkingConfig{})
Env: convertMapToKVStrings(buildImage.BuildArgs),
})
buildImage.BuildArgs = convertKVStringsToMap(config.Env) buildImage.BuildArgs = convertKVStringsToMap(config.Env)
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config) nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), config)
c.scheduler.Unlock() c.scheduler.Unlock()