mirror of https://github.com/docker/docs.git
Updating filters
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
parent
81e1528d0f
commit
48cd1ebd69
|
@ -38,7 +38,7 @@ func (f *AffinityFilter) Filter(config *cluster.ContainerConfig, nodes []*node.N
|
|||
containers := []string{}
|
||||
for _, container := range node.Containers {
|
||||
if len(container.Names) > 0 {
|
||||
containers = append(containers, container.Id, strings.TrimPrefix(container.Names[0], "/"))
|
||||
containers = append(containers, container.ID, strings.TrimPrefix(container.Names[0], "/"))
|
||||
}
|
||||
}
|
||||
if affinity.Match(containers...) {
|
||||
|
|
|
@ -36,8 +36,8 @@ func (f *DependencyFilter) Filter(config *cluster.ContainerConfig, nodes []*node
|
|||
|
||||
// Check if --net points to a container.
|
||||
net := []string{}
|
||||
if strings.HasPrefix(config.HostConfig.NetworkMode, "container:") {
|
||||
net = append(net, strings.TrimPrefix(config.HostConfig.NetworkMode, "container:"))
|
||||
if strings.HasPrefix(string(config.HostConfig.NetworkMode), "container:") {
|
||||
net = append(net, strings.TrimPrefix(string(config.HostConfig.NetworkMode), "container:"))
|
||||
}
|
||||
|
||||
candidates := []*node.Node{}
|
||||
|
@ -65,7 +65,7 @@ func (f *DependencyFilter) GetFilters(config *cluster.ContainerConfig) ([]string
|
|||
for _, link := range config.HostConfig.Links {
|
||||
dependencies = append(dependencies, fmt.Sprintf("--link=%s", link))
|
||||
}
|
||||
if strings.HasPrefix(config.HostConfig.NetworkMode, "container:") {
|
||||
if strings.HasPrefix(string(config.HostConfig.NetworkMode), "container:") {
|
||||
dependencies = append(dependencies, fmt.Sprintf("--net=%s", config.HostConfig.NetworkMode))
|
||||
}
|
||||
return dependencies, nil
|
||||
|
|
|
@ -3,9 +3,9 @@ package filter
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/docker/swarm/scheduler/node"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
// PortFilter guarantees that, when scheduling a container binding a public
|
||||
|
@ -32,7 +32,7 @@ func (p *PortFilter) filterHost(config *cluster.ContainerConfig, nodes []*node.N
|
|||
for port := range config.ExposedPorts {
|
||||
candidates := []*node.Node{}
|
||||
for _, node := range nodes {
|
||||
if !p.portAlreadyExposed(node, port) {
|
||||
if !p.portAlreadyExposed(node, string(port)) {
|
||||
candidates = append(candidates, node)
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (p *PortFilter) portAlreadyExposed(node *node.Node, requestedPort string) b
|
|||
for _, c := range node.Containers {
|
||||
if c.Info.HostConfig.NetworkMode == "host" {
|
||||
for port := range c.Info.Config.ExposedPorts {
|
||||
if port == requestedPort {
|
||||
if string(port) == requestedPort {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func (p *PortFilter) portAlreadyExposed(node *node.Node, requestedPort string) b
|
|||
return false
|
||||
}
|
||||
|
||||
func (p *PortFilter) portAlreadyInUse(node *node.Node, requested dockerclient.PortBinding) bool {
|
||||
func (p *PortFilter) portAlreadyInUse(node *node.Node, requested nat.PortBinding) bool {
|
||||
for _, c := range node.Containers {
|
||||
// HostConfig.PortBindings contains the requested ports.
|
||||
// NetworkSettings.Ports contains the actual ports.
|
||||
|
@ -96,7 +96,7 @@ func (p *PortFilter) portAlreadyInUse(node *node.Node, requested dockerclient.Po
|
|||
return false
|
||||
}
|
||||
|
||||
func (p *PortFilter) compare(requested dockerclient.PortBinding, bindings map[string][]dockerclient.PortBinding) bool {
|
||||
func (p *PortFilter) compare(requested nat.PortBinding, bindings nat.PortMap) bool {
|
||||
for _, binding := range bindings {
|
||||
for _, b := range binding {
|
||||
if b.HostPort == "" {
|
||||
|
@ -110,7 +110,7 @@ func (p *PortFilter) compare(requested dockerclient.PortBinding, bindings map[st
|
|||
// port/protocol. Verify if they are requesting the same
|
||||
// binding IP, or if the other container is already binding on
|
||||
// every interface.
|
||||
if requested.HostIp == b.HostIp || bindsAllInterfaces(requested) || bindsAllInterfaces(b) {
|
||||
if requested.HostIP == b.HostIP || bindsAllInterfaces(requested) || bindsAllInterfaces(b) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +137,6 @@ func (p *PortFilter) GetFilters(config *cluster.ContainerConfig) ([]string, erro
|
|||
return allPortConstraints, nil
|
||||
}
|
||||
|
||||
func bindsAllInterfaces(binding dockerclient.PortBinding) bool {
|
||||
return binding.HostIp == "0.0.0.0" || binding.HostIp == ""
|
||||
func bindsAllInterfaces(binding nat.PortBinding) bool {
|
||||
return binding.HostIP == "0.0.0.0" || binding.HostIP == ""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue