github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/api/types/swarm/service.go (about) 1 package swarm 2 3 import "time" 4 5 // Service represents a service. 6 type Service struct { 7 ID string 8 Meta 9 Spec ServiceSpec `json:",omitempty"` 10 PreviousSpec *ServiceSpec `json:",omitempty"` 11 Endpoint Endpoint `json:",omitempty"` 12 UpdateStatus UpdateStatus `json:",omitempty"` 13 } 14 15 // ServiceSpec represents the spec of a service. 16 type ServiceSpec struct { 17 Annotations 18 19 // TaskTemplate defines how the service should construct new tasks when 20 // orchestrating this service. 21 TaskTemplate TaskSpec `json:",omitempty"` 22 Mode ServiceMode `json:",omitempty"` 23 UpdateConfig *UpdateConfig `json:",omitempty"` 24 25 // Networks field in ServiceSpec is deprecated. The 26 // same field in TaskSpec should be used instead. 27 // This field will be removed in a future release. 28 Networks []NetworkAttachmentConfig `json:",omitempty"` 29 EndpointSpec *EndpointSpec `json:",omitempty"` 30 } 31 32 // ServiceMode represents the mode of a service. 33 type ServiceMode struct { 34 Replicated *ReplicatedService `json:",omitempty"` 35 Global *GlobalService `json:",omitempty"` 36 } 37 38 // UpdateState is the state of a service update. 39 type UpdateState string 40 41 const ( 42 // UpdateStateUpdating is the updating state. 43 UpdateStateUpdating UpdateState = "updating" 44 // UpdateStatePaused is the paused state. 45 UpdateStatePaused UpdateState = "paused" 46 // UpdateStateCompleted is the completed state. 47 UpdateStateCompleted UpdateState = "completed" 48 ) 49 50 // UpdateStatus reports the status of a service update. 51 type UpdateStatus struct { 52 State UpdateState `json:",omitempty"` 53 StartedAt time.Time `json:",omitempty"` 54 CompletedAt time.Time `json:",omitempty"` 55 Message string `json:",omitempty"` 56 } 57 58 // ReplicatedService is a kind of ServiceMode. 59 type ReplicatedService struct { 60 Replicas *uint64 `json:",omitempty"` 61 } 62 63 // GlobalService is a kind of ServiceMode. 64 type GlobalService struct{} 65 66 const ( 67 // UpdateFailureActionPause PAUSE 68 UpdateFailureActionPause = "pause" 69 // UpdateFailureActionContinue CONTINUE 70 UpdateFailureActionContinue = "continue" 71 ) 72 73 // UpdateConfig represents the update configuration. 74 type UpdateConfig struct { 75 // Maximum number of tasks to be updated in one iteration. 76 // 0 means unlimited parallelism. 77 Parallelism uint64 78 79 // Amount of time between updates. 80 Delay time.Duration `json:",omitempty"` 81 82 // FailureAction is the action to take when an update failures. 83 FailureAction string `json:",omitempty"` 84 85 // Monitor indicates how long to monitor a task for failure after it is 86 // created. If the task fails by ending up in one of the states 87 // REJECTED, COMPLETED, or FAILED, within Monitor from its creation, 88 // this counts as a failure. If it fails after Monitor, it does not 89 // count as a failure. If Monitor is unspecified, a default value will 90 // be used. 91 Monitor time.Duration `json:",omitempty"` 92 93 // MaxFailureRatio is the fraction of tasks that may fail during 94 // an update before the failure action is invoked. Any task created by 95 // the current update which ends up in one of the states REJECTED, 96 // COMPLETED or FAILED within Monitor from its creation counts as a 97 // failure. The number of failures is divided by the number of tasks 98 // being updated, and if this fraction is greater than 99 // MaxFailureRatio, the failure action is invoked. 100 // 101 // If the failure action is CONTINUE, there is no effect. 102 // If the failure action is PAUSE, no more tasks will be updated until 103 // another update is started. 104 MaxFailureRatio float32 105 }