fix soft affinity reschedule

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-01-05 04:56:34 -08:00
parent b2739245ce
commit 97f3767618
1 changed files with 6 additions and 6 deletions

View File

@ -118,13 +118,13 @@ func (c *Cluster) generateUniqueID() string {
func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (*cluster.Container, error) {
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 {
bImageNotFoundError, _ := regexp.MatchString(`image \S* not found`, err.Error())
if bImageNotFoundError && !config.HaveNodeConstraint() {
// Check if the image exists in the cluster
// If exists, retry with a soft-image-affinity
if image := c.Image(config.Image); image != nil {
// If exists, retry with a image-affinity
if c.Image(config.Image) != nil {
container, err = c.createContainer(config, name, true, authConfig)
}
}
@ -132,7 +132,7 @@ func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string,
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()
// Ensure the name is available
@ -146,8 +146,8 @@ func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string,
config.SetSwarmID(swarmID)
configTemp := config
if withSoftImageAffinity {
configTemp.AddAffinity("image==~" + config.Image)
if withImageAffinity {
configTemp.AddAffinity("image==" + config.Image)
}
nodes, err := c.scheduler.SelectNodesForContainer(c.listNodes(), configTemp)