This is a creation in Article, where the information may have evolved or changed.
Docker Swarm manage
The options of the command are filter
used to specify scheduler
Docker Engine
the selected filter, whose variables are defined as follows ( cli/flags.go
):
// hack for go vetflFilterValue = cli.StringSlice(filter.List())// DefaultFilterNumber is exportedDefaultFilterNumber = len(flFilterValue)flFilter = cli.StringSliceFlag{ Name: "filter, f", Usage: "filter to use [" + strings.Join(filter.List(), ", ") + "]", Value: &flFilterValue,}
filter
the code to get the value is as follows ( cli/manage.go
):
// see https://github.com/codegangsta/cli/issues/160names := c.StringSlice("filter")if c.IsSet("filter") || c.IsSet("f") { names = names[DefaultFilterNumber:]}fs, err := filter.New(names)if err != nil { log.Fatal(err)}
By default, all filter
() are obtained scheduler/filter/filter.go
:
func init() { filters = []Filter{ &HealthFilter{}, &PortFilter{}, &SlotsFilter{}, &DependencyFilter{}, &AffinityFilter{}, &ConstraintFilter{}, }}
And Filter
is a interface
( scheduler/filter/filter.go
):
// Filter is exportedtype Filter interface { Name() string // 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 GetFilters(*cluster.ContainerConfig) ([]string, error)}
Where the Filter
method is used to filter the qualifying Docker Engine
, GetFilters
A string that describes the filter condition is returned.
In scheduler/filter/filter.go
, applyfilters
to filter Docker Engine
; Listallfilters
Returns all filter conditions:
Applyfilters applies a set of filters in Batch.func applyfilters (filters []filter, config *cluster. Containerconfig, nodes []*node. Node, soft bool) ([]*node. Node, error) {var (err error candidates = nodes) for _, Filter: = Range Filters { Candidates, err = filter. Filter (config, candidates, soft) if err! = Nil {//special case for when no healthy nodes is found If filter. Name () = = "Health" {return nil, err} return nil, FMT. Errorf ("Unable to find a node that satisfies the following conditions%s", listallfilters (filters, config, filter.) Name ())}} return candidates, nil}//Listallfilters creates a string containing all applied Filtersfunc lis Tallfilters (filters []filter, config *cluster. Containerconfig, Lastfilter String) string {allfilters: = "" For _, Filter: = Range Filters {list, err: = f Ilter. Getfilters (config) if err = = Nil && lEn (list) > 0 {allfilters = fmt. Sprintf ("%s\n%v", Allfilters, List)} if filter. Name () = = Lastfilter {return allfilters}} return Allfilters}