6 "github.com/docker/swarmkit/api"
7 "github.com/docker/swarmkit/api/deepcopy"
8 gogotypes "github.com/gogo/protobuf/types"
11 // Service is a ServiceSpec object with all fields filled in using default
13 var Service = api.ServiceSpec{
15 Runtime: &api.TaskSpec_Container{
16 Container: &api.ContainerSpec{
17 StopGracePeriod: gogotypes.DurationProto(10 * time.Second),
18 PullOptions: &api.ContainerSpec_PullOptions{},
19 DNSConfig: &api.ContainerSpec_DNSConfig{},
22 Resources: &api.ResourceRequirements{},
23 Restart: &api.RestartPolicy{
24 Condition: api.RestartOnAny,
25 Delay: gogotypes.DurationProto(5 * time.Second),
27 Placement: &api.Placement{},
29 Update: &api.UpdateConfig{
30 FailureAction: api.UpdateConfig_PAUSE,
31 Monitor: gogotypes.DurationProto(5 * time.Second),
33 Order: api.UpdateConfig_STOP_FIRST,
35 Rollback: &api.UpdateConfig{
36 FailureAction: api.UpdateConfig_PAUSE,
37 Monitor: gogotypes.DurationProto(5 * time.Second),
39 Order: api.UpdateConfig_STOP_FIRST,
43 // InterpolateService returns a ServiceSpec based on the provided spec, which
44 // has all unspecified values filled in with default values.
45 func InterpolateService(origSpec *api.ServiceSpec) *api.ServiceSpec {
46 spec := origSpec.Copy()
48 container := spec.Task.GetContainer()
49 defaultContainer := Service.Task.GetContainer()
51 if container.StopGracePeriod == nil {
52 container.StopGracePeriod = &gogotypes.Duration{}
53 deepcopy.Copy(container.StopGracePeriod, defaultContainer.StopGracePeriod)
55 if container.PullOptions == nil {
56 container.PullOptions = defaultContainer.PullOptions.Copy()
58 if container.DNSConfig == nil {
59 container.DNSConfig = defaultContainer.DNSConfig.Copy()
63 if spec.Task.Resources == nil {
64 spec.Task.Resources = Service.Task.Resources.Copy()
67 if spec.Task.Restart == nil {
68 spec.Task.Restart = Service.Task.Restart.Copy()
70 if spec.Task.Restart.Delay == nil {
71 spec.Task.Restart.Delay = &gogotypes.Duration{}
72 deepcopy.Copy(spec.Task.Restart.Delay, Service.Task.Restart.Delay)
76 if spec.Task.Placement == nil {
77 spec.Task.Placement = Service.Task.Placement.Copy()
80 if spec.Update == nil {
81 spec.Update = Service.Update.Copy()
83 if spec.Update.Monitor == nil {
84 spec.Update.Monitor = &gogotypes.Duration{}
85 deepcopy.Copy(spec.Update.Monitor, Service.Update.Monitor)
89 if spec.Rollback == nil {
90 spec.Rollback = Service.Rollback.Copy()
92 if spec.Rollback.Monitor == nil {
93 spec.Rollback.Monitor = &gogotypes.Duration{}
94 deepcopy.Copy(spec.Rollback.Monitor, Service.Rollback.Monitor)