mirror of https://github.com/docker/docs.git
Adding functions to list filter constraints of all types
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
parent
2ce00c6ce9
commit
ac3a8b6ac9
|
@ -76,3 +76,16 @@ func (f *AffinityFilter) Filter(config *cluster.ContainerConfig, nodes []*node.N
|
|||
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// Get a list of the affinities found in the container config.
|
||||
func (f *AffinityFilter) GetAllFilters(config *cluster.ContainerConfig) ([]string, error) {
|
||||
allAffinities := []string{}
|
||||
affinities, err := parseExprs(config.Affinities())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, affinity := range affinities {
|
||||
allAffinities = append(allAffinities, fmt.Sprintf("%s%s%s (soft=%t)", affinity.key, OPERATORS[affinity.operator], affinity.value, affinity.isSoft))
|
||||
}
|
||||
return allAffinities, nil
|
||||
}
|
||||
|
|
|
@ -51,3 +51,16 @@ func (f *ConstraintFilter) Filter(config *cluster.ContainerConfig, nodes []*node
|
|||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// Get a list of the constraints found in the container config.
|
||||
func (f *ConstraintFilter) GetAllFilters(config *cluster.ContainerConfig) ([]string, error) {
|
||||
allConstraints := []string{}
|
||||
constraints, err := parseExprs(config.Constraints())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, constraint := range constraints {
|
||||
allConstraints = append(allConstraints, fmt.Sprintf("%s%s%s", constraint.key, OPERATORS[constraint.operator], constraint.value))
|
||||
}
|
||||
return allConstraints, nil
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ func (f *DependencyFilter) Filter(config *cluster.ContainerConfig, nodes []*node
|
|||
return candidates, nil
|
||||
}
|
||||
|
||||
// Get a string representation of the dependencies found in the container config.
|
||||
func (f *DependencyFilter) String(config *cluster.ContainerConfig) string {
|
||||
// Get a list of the dependencies found in the container config.
|
||||
func (f *DependencyFilter) GetAllFilters(config *cluster.ContainerConfig) ([]string, error) {
|
||||
dependencies := []string{}
|
||||
for _, volume := range config.HostConfig.VolumesFrom {
|
||||
dependencies = append(dependencies, fmt.Sprintf("--volumes-from=%s", volume))
|
||||
|
@ -68,6 +68,12 @@ func (f *DependencyFilter) String(config *cluster.ContainerConfig) string {
|
|||
if strings.HasPrefix(config.HostConfig.NetworkMode, "container:") {
|
||||
dependencies = append(dependencies, fmt.Sprintf("--net=%s", config.HostConfig.NetworkMode))
|
||||
}
|
||||
return dependencies, nil
|
||||
}
|
||||
|
||||
// Get a string representation of the dependencies found in the container config.
|
||||
func (f *DependencyFilter) String(config *cluster.ContainerConfig) string {
|
||||
dependencies, _ := f.GetAllFilters(config)
|
||||
return strings.Join(dependencies, " ")
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ type Filter interface {
|
|||
|
||||
// Return a subset of nodes that were accepted by the filtering policy.
|
||||
Filter(*cluster.ContainerConfig, []*node.Node, bool) ([]*node.Node, error)
|
||||
|
||||
// Return a list of constraints/filters provided
|
||||
GetAllFilters(*cluster.ContainerConfig) ([]string, error)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -36,3 +36,8 @@ func (f *HealthFilter) Filter(_ *cluster.ContainerConfig, nodes []*node.Node, _
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Implements interface function, but currently redundant since we don't have node constraints
|
||||
func (f *HealthFilter) GetAllFilters(config *cluster.ContainerConfig) ([]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -119,6 +119,24 @@ func (p *PortFilter) compare(requested dockerclient.PortBinding, bindings map[st
|
|||
return false
|
||||
}
|
||||
|
||||
// Get a list of the port constraints found in the container config.
|
||||
func (p *PortFilter) GetAllFilters(config *cluster.ContainerConfig) ([]string, error) {
|
||||
allPortConstraints := []string{}
|
||||
if config.HostConfig.NetworkMode == "host" {
|
||||
for port := range config.ExposedPorts {
|
||||
allPortConstraints = append(allPortConstraints, fmt.Sprintf("port %s (Host mode)", port))
|
||||
}
|
||||
return allPortConstraints, nil
|
||||
}
|
||||
|
||||
for _, port := range config.HostConfig.PortBindings {
|
||||
for _, binding := range port {
|
||||
allPortConstraints = append(allPortConstraints, fmt.Sprintf("port %s", binding.HostPort))
|
||||
}
|
||||
}
|
||||
return allPortConstraints, nil
|
||||
}
|
||||
|
||||
func bindsAllInterfaces(binding dockerclient.PortBinding) bool {
|
||||
return binding.HostIp == "0.0.0.0" || binding.HostIp == ""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue