mirror of https://github.com/docker/docs.git
fix soft / resource computation
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
3c7a454a9d
commit
2b155ce8cf
|
@ -54,17 +54,7 @@ func New(names []string) ([]Filter, error) {
|
|||
}
|
||||
|
||||
// ApplyFilters applies a set of filters in batch.
|
||||
func ApplyFilters(filters []Filter, config *cluster.ContainerConfig, nodes []*node.Node) ([]*node.Node, error) {
|
||||
candidates, err := applyFilters(filters, config, nodes, true)
|
||||
|
||||
if err != nil {
|
||||
candidates, err = applyFilters(filters, config, nodes, false)
|
||||
}
|
||||
|
||||
return candidates, err
|
||||
}
|
||||
|
||||
func applyFilters(filters []Filter, config *cluster.ContainerConfig, nodes []*node.Node, soft bool) ([]*node.Node, error) {
|
||||
func ApplyFilters(filters []Filter, config *cluster.ContainerConfig, nodes []*node.Node, soft bool) ([]*node.Node, error) {
|
||||
var (
|
||||
err error
|
||||
candidates = nodes
|
||||
|
|
|
@ -63,7 +63,10 @@ func TestApplyFilters(t *testing.T) {
|
|||
|
||||
//Tests for Soft affinity, it should be considered as last
|
||||
config := cluster.BuildContainerConfig(dockerclient.ContainerConfig{Env: []string{"affinity:image==~image-0:tag3"}})
|
||||
result, err = ApplyFilters(filters, config, nodes)
|
||||
result, err = ApplyFilters(filters, config, nodes, true)
|
||||
assert.Error(t, err)
|
||||
assert.Len(t, result, 0)
|
||||
result, err = ApplyFilters(filters, config, nodes, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 1)
|
||||
|
||||
|
|
|
@ -34,7 +34,16 @@ func New(strategy strategy.PlacementStrategy, filters []filter.Filter) *Schedule
|
|||
// SelectNodesForContainer will return a list of nodes where the container can
|
||||
// be scheduled, sorted by order or preference.
|
||||
func (s *Scheduler) SelectNodesForContainer(nodes []*node.Node, config *cluster.ContainerConfig) ([]*node.Node, error) {
|
||||
accepted, err := filter.ApplyFilters(s.filters, config, nodes)
|
||||
candidates, err := s.selectNodesForContainer(nodes, config, true)
|
||||
|
||||
if err != nil {
|
||||
candidates, err = s.selectNodesForContainer(nodes, config, false)
|
||||
}
|
||||
return candidates, err
|
||||
}
|
||||
|
||||
func (s *Scheduler) selectNodesForContainer(nodes []*node.Node, config *cluster.ContainerConfig, soft bool) ([]*node.Node, error) {
|
||||
accepted, err := filter.ApplyFilters(s.filters, config, nodes, soft)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue