github.com/rumpl/bof@v23.0.0-rc.2+incompatible/api/types/swarm/task.go (about) 1 package swarm // import "github.com/docker/docker/api/types/swarm" 2 3 import ( 4 "time" 5 6 "github.com/docker/docker/api/types/swarm/runtime" 7 ) 8 9 // TaskState represents the state of a task. 10 type TaskState string 11 12 const ( 13 // TaskStateNew NEW 14 TaskStateNew TaskState = "new" 15 // TaskStateAllocated ALLOCATED 16 TaskStateAllocated TaskState = "allocated" 17 // TaskStatePending PENDING 18 TaskStatePending TaskState = "pending" 19 // TaskStateAssigned ASSIGNED 20 TaskStateAssigned TaskState = "assigned" 21 // TaskStateAccepted ACCEPTED 22 TaskStateAccepted TaskState = "accepted" 23 // TaskStatePreparing PREPARING 24 TaskStatePreparing TaskState = "preparing" 25 // TaskStateReady READY 26 TaskStateReady TaskState = "ready" 27 // TaskStateStarting STARTING 28 TaskStateStarting TaskState = "starting" 29 // TaskStateRunning RUNNING 30 TaskStateRunning TaskState = "running" 31 // TaskStateComplete COMPLETE 32 TaskStateComplete TaskState = "complete" 33 // TaskStateShutdown SHUTDOWN 34 TaskStateShutdown TaskState = "shutdown" 35 // TaskStateFailed FAILED 36 TaskStateFailed TaskState = "failed" 37 // TaskStateRejected REJECTED 38 TaskStateRejected TaskState = "rejected" 39 // TaskStateRemove REMOVE 40 TaskStateRemove TaskState = "remove" 41 // TaskStateOrphaned ORPHANED 42 TaskStateOrphaned TaskState = "orphaned" 43 ) 44 45 // Task represents a task. 46 type Task struct { 47 ID string 48 Meta 49 Annotations 50 51 Spec TaskSpec `json:",omitempty"` 52 ServiceID string `json:",omitempty"` 53 Slot int `json:",omitempty"` 54 NodeID string `json:",omitempty"` 55 Status TaskStatus `json:",omitempty"` 56 DesiredState TaskState `json:",omitempty"` 57 NetworksAttachments []NetworkAttachment `json:",omitempty"` 58 GenericResources []GenericResource `json:",omitempty"` 59 60 // JobIteration is the JobIteration of the Service that this Task was 61 // spawned from, if the Service is a ReplicatedJob or GlobalJob. This is 62 // used to determine which Tasks belong to which run of the job. This field 63 // is absent if the Service mode is Replicated or Global. 64 JobIteration *Version `json:",omitempty"` 65 66 // Volumes is the list of VolumeAttachments for this task. It specifies 67 // which particular volumes are to be used by this particular task, and 68 // fulfilling what mounts in the spec. 69 Volumes []VolumeAttachment 70 } 71 72 // TaskSpec represents the spec of a task. 73 type TaskSpec struct { 74 // ContainerSpec, NetworkAttachmentSpec, and PluginSpec are mutually exclusive. 75 // PluginSpec is only used when the `Runtime` field is set to `plugin` 76 // NetworkAttachmentSpec is used if the `Runtime` field is set to 77 // `attachment`. 78 ContainerSpec *ContainerSpec `json:",omitempty"` 79 PluginSpec *runtime.PluginSpec `json:",omitempty"` 80 NetworkAttachmentSpec *NetworkAttachmentSpec `json:",omitempty"` 81 82 Resources *ResourceRequirements `json:",omitempty"` 83 RestartPolicy *RestartPolicy `json:",omitempty"` 84 Placement *Placement `json:",omitempty"` 85 Networks []NetworkAttachmentConfig `json:",omitempty"` 86 87 // LogDriver specifies the LogDriver to use for tasks created from this 88 // spec. If not present, the one on cluster default on swarm.Spec will be 89 // used, finally falling back to the engine default if not specified. 90 LogDriver *Driver `json:",omitempty"` 91 92 // ForceUpdate is a counter that triggers an update even if no relevant 93 // parameters have been changed. 94 ForceUpdate uint64 95 96 Runtime RuntimeType `json:",omitempty"` 97 } 98 99 // Resources represents resources (CPU/Memory) which can be advertised by a 100 // node and requested to be reserved for a task. 101 type Resources struct { 102 NanoCPUs int64 `json:",omitempty"` 103 MemoryBytes int64 `json:",omitempty"` 104 GenericResources []GenericResource `json:",omitempty"` 105 } 106 107 // Limit describes limits on resources which can be requested by a task. 108 type Limit struct { 109 NanoCPUs int64 `json:",omitempty"` 110 MemoryBytes int64 `json:",omitempty"` 111 Pids int64 `json:",omitempty"` 112 } 113 114 // GenericResource represents a "user defined" resource which can 115 // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1) 116 type GenericResource struct { 117 NamedResourceSpec *NamedGenericResource `json:",omitempty"` 118 DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"` 119 } 120 121 // NamedGenericResource represents a "user defined" resource which is defined 122 // as a string. 123 // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...) 124 // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...) 125 type NamedGenericResource struct { 126 Kind string `json:",omitempty"` 127 Value string `json:",omitempty"` 128 } 129 130 // DiscreteGenericResource represents a "user defined" resource which is defined 131 // as an integer 132 // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...) 133 // Value is used to count the resource (SSD=5, HDD=3, ...) 134 type DiscreteGenericResource struct { 135 Kind string `json:",omitempty"` 136 Value int64 `json:",omitempty"` 137 } 138 139 // ResourceRequirements represents resources requirements. 140 type ResourceRequirements struct { 141 Limits *Limit `json:",omitempty"` 142 Reservations *Resources `json:",omitempty"` 143 } 144 145 // Placement represents orchestration parameters. 146 type Placement struct { 147 Constraints []string `json:",omitempty"` 148 Preferences []PlacementPreference `json:",omitempty"` 149 MaxReplicas uint64 `json:",omitempty"` 150 151 // Platforms stores all the platforms that the image can run on. 152 // This field is used in the platform filter for scheduling. If empty, 153 // then the platform filter is off, meaning there are no scheduling restrictions. 154 Platforms []Platform `json:",omitempty"` 155 } 156 157 // PlacementPreference provides a way to make the scheduler aware of factors 158 // such as topology. 159 type PlacementPreference struct { 160 Spread *SpreadOver 161 } 162 163 // SpreadOver is a scheduling preference that instructs the scheduler to spread 164 // tasks evenly over groups of nodes identified by labels. 165 type SpreadOver struct { 166 // label descriptor, such as engine.labels.az 167 SpreadDescriptor string 168 } 169 170 // RestartPolicy represents the restart policy. 171 type RestartPolicy struct { 172 Condition RestartPolicyCondition `json:",omitempty"` 173 Delay *time.Duration `json:",omitempty"` 174 MaxAttempts *uint64 `json:",omitempty"` 175 Window *time.Duration `json:",omitempty"` 176 } 177 178 // RestartPolicyCondition represents when to restart. 179 type RestartPolicyCondition string 180 181 const ( 182 // RestartPolicyConditionNone NONE 183 RestartPolicyConditionNone RestartPolicyCondition = "none" 184 // RestartPolicyConditionOnFailure ON_FAILURE 185 RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure" 186 // RestartPolicyConditionAny ANY 187 RestartPolicyConditionAny RestartPolicyCondition = "any" 188 ) 189 190 // TaskStatus represents the status of a task. 191 type TaskStatus struct { 192 Timestamp time.Time `json:",omitempty"` 193 State TaskState `json:",omitempty"` 194 Message string `json:",omitempty"` 195 Err string `json:",omitempty"` 196 ContainerStatus *ContainerStatus `json:",omitempty"` 197 PortStatus PortStatus `json:",omitempty"` 198 } 199 200 // ContainerStatus represents the status of a container. 201 type ContainerStatus struct { 202 ContainerID string 203 PID int 204 ExitCode int 205 } 206 207 // PortStatus represents the port status of a task's host ports whose 208 // service has published host ports 209 type PortStatus struct { 210 Ports []PortConfig `json:",omitempty"` 211 } 212 213 // VolumeAttachment contains the associating a Volume to a Task. 214 type VolumeAttachment struct { 215 // ID is the Swarmkit ID of the Volume. This is not the CSI VolumeId. 216 ID string `json:",omitempty"` 217 218 // Source, together with Target, indicates the Mount, as specified in the 219 // ContainerSpec, that this volume fulfills. 220 Source string `json:",omitempty"` 221 222 // Target, together with Source, indicates the Mount, as specified 223 // in the ContainerSpec, that this volume fulfills. 224 Target string `json:",omitempty"` 225 }