mirror of
https://github.com/docker/docs.git
synced 2026-10-31 10:34:26 +03:00
Health filter: Only schedule containers on healthy nodes.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -75,7 +75,11 @@ func manage(c *cli.Context) {
|
||||
s := scheduler.NewScheduler(
|
||||
cluster,
|
||||
&strategy.BinPackingPlacementStrategy{OvercommitRatio: 0.05},
|
||||
[]filter.Filter{&filter.LabelFilter{}, &filter.PortFilter{}},
|
||||
[]filter.Filter{
|
||||
&filter.HealthFilter{},
|
||||
&filter.LabelFilter{},
|
||||
&filter.PortFilter{},
|
||||
},
|
||||
)
|
||||
|
||||
log.Fatal(api.ListenAndServe(cluster, s, c.String("addr"), c.App.Version))
|
||||
|
||||
31
scheduler/filter/health.go
Normal file
31
scheduler/filter/health.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package filter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoHealthyNodeAvailable = errors.New("No healthy node available in the cluster")
|
||||
)
|
||||
|
||||
// HealthFilter only schedules containers on healthy nodes.
|
||||
type HealthFilter struct {
|
||||
}
|
||||
|
||||
func (f *HealthFilter) Filter(config *dockerclient.ContainerConfig, nodes []*cluster.Node) ([]*cluster.Node, error) {
|
||||
result := []*cluster.Node{}
|
||||
for _, node := range nodes {
|
||||
if node.IsHealthy() {
|
||||
result = append(result, node)
|
||||
}
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return nil, ErrNoHealthyNodeAvailable
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user