forked from moby/swarmkit
/
update.go
60 lines (52 loc) · 1.25 KB
/
update.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package flagparser
import (
"errors"
"time"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/protobuf/ptypes"
"github.com/spf13/pflag"
)
func parseUpdate(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("update-parallelism") {
parallelism, err := flags.GetUint64("update-parallelism")
if err != nil {
return err
}
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
spec.Update.Parallelism = parallelism
}
if flags.Changed("update-delay") {
delay, err := flags.GetString("update-delay")
if err != nil {
return err
}
delayDuration, err := time.ParseDuration(delay)
if err != nil {
return err
}
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
spec.Update.Delay = *ptypes.DurationProto(delayDuration)
}
if flags.Changed("update-on-failure") {
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
action, err := flags.GetString("update-on-failure")
if err != nil {
return err
}
switch action {
case "pause":
spec.Update.FailureAction = api.UpdateConfig_PAUSE
case "continue":
spec.Update.FailureAction = api.UpdateConfig_CONTINUE
default:
return errors.New("--update-on-failure value must be pause or continue")
}
}
return nil
}