forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
placement.go
37 lines (32 loc) · 852 Bytes
/
placement.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
package flagparser
import (
"fmt"
"github.com/docker/swarmkit/api"
"github.com/spf13/pflag"
)
func parsePlacement(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("constraint") {
constraints, err := flags.GetStringSlice("constraint")
if err != nil {
return err
}
if spec.Task.Placement == nil {
spec.Task.Placement = &api.Placement{}
}
spec.Task.Placement.Constraints = constraints
}
if flags.Changed("replicas-max-per-node") {
if spec.GetReplicated() == nil {
return fmt.Errorf("--replicas-max-per-node can only be specified in --mode replicated")
}
maxReplicas, err := flags.GetUint64("replicas-max-per-node")
if err != nil {
return err
}
if spec.Task.Placement == nil {
spec.Task.Placement = &api.Placement{}
}
spec.Task.Placement.MaxReplicas = maxReplicas
}
return nil
}