forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth.go
38 lines (30 loc) · 771 Bytes
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package filter
import (
"errors"
"github.com/docker/swarm/cluster"
"github.com/docker/swarm/scheduler/node"
)
var (
// ErrNoHealthyNodeAvailable is exported
ErrNoHealthyNodeAvailable = errors.New("No healthy node available in the cluster")
)
// HealthFilter only schedules containers on healthy nodes.
type HealthFilter struct {
}
// Name returns the name of the filter
func (f *HealthFilter) Name() string {
return "health"
}
// Filter is exported
func (f *HealthFilter) Filter(_ *cluster.ContainerConfig, nodes []*node.Node) ([]*node.Node, error) {
result := []*node.Node{}
for _, node := range nodes {
if node.IsHealthy {
result = append(result, node)
}
}
if len(result) == 0 {
return nil, ErrNoHealthyNodeAvailable
}
return result, nil
}