Docker Swarm manage
命令的flStrategy
选项用来指定scheduler
调度的strategy
的过滤项,其变量定义如下(cli/flags.go
):
flStrategy = cli.StringFlag{
Name: "strategy",
Usage: "placement strategy to use [" + strings.Join(strategy.List(), ", ") + "]",
Value: strategy.List()[0],
}
strategy
的默认值是SpreadPlacementStrategy
。
strategy
在代码中的实际定义是PlacementStrategy
,一个interface
:
// PlacementStrategy is the interface for a container placement strategy.
type PlacementStrategy interface {
// Name of the strategy
Name() string
// Initialize performs any initial configuration required by the strategy and returns
// an error if one is encountered.
// If no initial configuration is needed, this may be a no-op and return a nil error.
Initialize() error
// RankAndSort applies the strategy to a list of nodes and ranks them based
// on the best fit given the container configuration. It returns a sorted
// list of nodes (based on their ranks) or an error if there is no
// available node on which to schedule the container.
RankAndSort(config *cluster.ContainerConfig, nodes []*node.Node) ([]*node.Node, error)
}
其中RankAndSort
返回一个符合条件node
(也就是Docker Engine
)列表,列表中元素按匹配度排序。
有疑问加站长微信联系(非本文作者)