github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/api/types/swarm/task.go (about) 1 package swarm 2 3 import "time" 4 5 // TaskState represents the state of a task. 6 type TaskState string 7 8 const ( 9 // TaskStateNew NEW 10 TaskStateNew TaskState = "new" 11 // TaskStateAllocated ALLOCATED 12 TaskStateAllocated TaskState = "allocated" 13 // TaskStatePending PENDING 14 TaskStatePending TaskState = "pending" 15 // TaskStateAssigned ASSIGNED 16 TaskStateAssigned TaskState = "assigned" 17 // TaskStateAccepted ACCEPTED 18 TaskStateAccepted TaskState = "accepted" 19 // TaskStatePreparing PREPARING 20 TaskStatePreparing TaskState = "preparing" 21 // TaskStateReady READY 22 TaskStateReady TaskState = "ready" 23 // TaskStateStarting STARTING 24 TaskStateStarting TaskState = "starting" 25 // TaskStateRunning RUNNING 26 TaskStateRunning TaskState = "running" 27 // TaskStateComplete COMPLETE 28 TaskStateComplete TaskState = "complete" 29 // TaskStateShutdown SHUTDOWN 30 TaskStateShutdown TaskState = "shutdown" 31 // TaskStateFailed FAILED 32 TaskStateFailed TaskState = "failed" 33 // TaskStateRejected REJECTED 34 TaskStateRejected TaskState = "rejected" 35 ) 36 37 // Task represents a task. 38 type Task struct { 39 ID string 40 Meta 41 Annotations 42 43 Spec TaskSpec `json:",omitempty"` 44 ServiceID string `json:",omitempty"` 45 Slot int `json:",omitempty"` 46 NodeID string `json:",omitempty"` 47 Status TaskStatus `json:",omitempty"` 48 DesiredState TaskState `json:",omitempty"` 49 NetworksAttachments []NetworkAttachment `json:",omitempty"` 50 } 51 52 // TaskSpec represents the spec of a task. 53 type TaskSpec struct { 54 ContainerSpec ContainerSpec `json:",omitempty"` 55 Resources *ResourceRequirements `json:",omitempty"` 56 RestartPolicy *RestartPolicy `json:",omitempty"` 57 Placement *Placement `json:",omitempty"` 58 Networks []NetworkAttachmentConfig `json:",omitempty"` 59 60 // LogDriver specifies the LogDriver to use for tasks created from this 61 // spec. If not present, the one on cluster default on swarm.Spec will be 62 // used, finally falling back to the engine default if not specified. 63 LogDriver *Driver `json:",omitempty"` 64 65 // ForceUpdate is a counter that triggers an update even if no relevant 66 // parameters have been changed. 67 ForceUpdate uint64 68 } 69 70 // Resources represents resources (CPU/Memory). 71 type Resources struct { 72 NanoCPUs int64 `json:",omitempty"` 73 MemoryBytes int64 `json:",omitempty"` 74 } 75 76 // ResourceRequirements represents resources requirements. 77 type ResourceRequirements struct { 78 Limits *Resources `json:",omitempty"` 79 Reservations *Resources `json:",omitempty"` 80 } 81 82 // Placement represents orchestration parameters. 83 type Placement struct { 84 Constraints []string `json:",omitempty"` 85 } 86 87 // RestartPolicy represents the restart policy. 88 type RestartPolicy struct { 89 Condition RestartPolicyCondition `json:",omitempty"` 90 Delay *time.Duration `json:",omitempty"` 91 MaxAttempts *uint64 `json:",omitempty"` 92 Window *time.Duration `json:",omitempty"` 93 } 94 95 // RestartPolicyCondition represents when to restart. 96 type RestartPolicyCondition string 97 98 const ( 99 // RestartPolicyConditionNone NONE 100 RestartPolicyConditionNone RestartPolicyCondition = "none" 101 // RestartPolicyConditionOnFailure ON_FAILURE 102 RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure" 103 // RestartPolicyConditionAny ANY 104 RestartPolicyConditionAny RestartPolicyCondition = "any" 105 ) 106 107 // TaskStatus represents the status of a task. 108 type TaskStatus struct { 109 Timestamp time.Time `json:",omitempty"` 110 State TaskState `json:",omitempty"` 111 Message string `json:",omitempty"` 112 Err string `json:",omitempty"` 113 ContainerStatus ContainerStatus `json:",omitempty"` 114 PortStatus PortStatus `json:",omitempty"` 115 } 116 117 // ContainerStatus represents the status of a container. 118 type ContainerStatus struct { 119 ContainerID string `json:",omitempty"` 120 PID int `json:",omitempty"` 121 ExitCode int `json:",omitempty"` 122 } 123 124 // PortStatus represents the port status of a task's host ports whose 125 // service has published host ports 126 type PortStatus struct { 127 Ports []PortConfig `json:",omitempty"` 128 }