mirror of https://github.com/docker/docs.git
Merge pull request #1586 from vieux/fix_soft_affinity_reschedule
fix soft affinity reschedule
This commit is contained in:
commit
82df09b537
|
|
@ -118,13 +118,13 @@ func (c *Cluster) generateUniqueID() string {
|
||||||
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 *dockerclient.AuthConfig) (*cluster.Container, error) {
|
||||||
container, err := c.createContainer(config, name, false, authConfig)
|
container, err := c.createContainer(config, name, false, authConfig)
|
||||||
|
|
||||||
// fails with image not found, then try to reschedule with soft-image-affinity
|
// fails with image not found, then try to reschedule with image-affinity
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bImageNotFoundError, _ := regexp.MatchString(`image \S* not found`, err.Error())
|
bImageNotFoundError, _ := regexp.MatchString(`image \S* not found`, err.Error())
|
||||||
if bImageNotFoundError && !config.HaveNodeConstraint() {
|
if bImageNotFoundError && !config.HaveNodeConstraint() {
|
||||||
// Check if the image exists in the cluster
|
// Check if the image exists in the cluster
|
||||||
// If exists, retry with a soft-image-affinity
|
// If exists, retry with a image-affinity
|
||||||
if image := c.Image(config.Image); image != nil {
|
if c.Image(config.Image) != nil {
|
||||||
container, err = c.createContainer(config, name, true, authConfig)
|
container, err = c.createContainer(config, name, true, authConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string,
|
||||||
return container, err
|
return container, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string, withSoftImageAffinity bool, authConfig *dockerclient.AuthConfig) (*cluster.Container, error) {
|
func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string, withImageAffinity bool, authConfig *dockerclient.AuthConfig) (*cluster.Container, error) {
|
||||||
c.scheduler.Lock()
|
c.scheduler.Lock()
|
||||||
|
|
||||||
// Ensure the name is available
|
// Ensure the name is available
|
||||||
|
|
@ -146,8 +146,8 @@ func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string,
|
||||||
config.SetSwarmID(swarmID)
|
config.SetSwarmID(swarmID)
|
||||||
|
|
||||||
configTemp := config
|
configTemp := config
|
||||||
if withSoftImageAffinity {
|
if withImageAffinity {
|
||||||
configTemp.AddAffinity("image==~" + config.Image)
|
configTemp.AddAffinity("image==" + config.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), configTemp)
|
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), configTemp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue