github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/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  
    67  // TaskSpec represents the spec of a task.
    68  type TaskSpec struct {
    69  	// ContainerSpec, NetworkAttachmentSpec, and PluginSpec are mutually exclusive.
    70  	// PluginSpec is only used when the `Runtime` field is set to `plugin`
    71  	// NetworkAttachmentSpec is used if the `Runtime` field is set to
    72  	// `attachment`.
    73  	ContainerSpec         *ContainerSpec         `json:",omitempty"`
    74  	PluginSpec            *runtime.PluginSpec    `json:",omitempty"`
    75  	NetworkAttachmentSpec *NetworkAttachmentSpec `json:",omitempty"`
    76  
    77  	Resources     *ResourceRequirements     `json:",omitempty"`
    78  	RestartPolicy *RestartPolicy            `json:",omitempty"`
    79  	Placement     *Placement                `json:",omitempty"`
    80  	Networks      []NetworkAttachmentConfig `json:",omitempty"`
    81  
    82  	// LogDriver specifies the LogDriver to use for tasks created from this
    83  	// spec. If not present, the one on cluster default on swarm.Spec will be
    84  	// used, finally falling back to the engine default if not specified.
    85  	LogDriver *Driver `json:",omitempty"`
    86  
    87  	// ForceUpdate is a counter that triggers an update even if no relevant
    88  	// parameters have been changed.
    89  	ForceUpdate uint64
    90  
    91  	Runtime RuntimeType `json:",omitempty"`
    92  }
    93  
    94  // Resources represents resources (CPU/Memory) which can be advertised by a
    95  // node and requested to be reserved for a task.
    96  type Resources struct {
    97  	NanoCPUs         int64             `json:",omitempty"`
    98  	MemoryBytes      int64             `json:",omitempty"`
    99  	GenericResources []GenericResource `json:",omitempty"`
   100  }
   101  
   102  // Limit describes limits on resources which can be requested by a task.
   103  type Limit struct {
   104  	NanoCPUs    int64 `json:",omitempty"`
   105  	MemoryBytes int64 `json:",omitempty"`
   106  	Pids        int64 `json:",omitempty"`
   107  }
   108  
   109  // GenericResource represents a "user defined" resource which can
   110  // be either an integer (e.g: SSD=3) or a string (e.g: SSD=sda1)
   111  type GenericResource struct {
   112  	NamedResourceSpec    *NamedGenericResource    `json:",omitempty"`
   113  	DiscreteResourceSpec *DiscreteGenericResource `json:",omitempty"`
   114  }
   115  
   116  // NamedGenericResource represents a "user defined" resource which is defined
   117  // as a string.
   118  // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
   119  // Value is used to identify the resource (GPU="UUID-1", FPGA="/dev/sdb5", ...)
   120  type NamedGenericResource struct {
   121  	Kind  string `json:",omitempty"`
   122  	Value string `json:",omitempty"`
   123  }
   124  
   125  // DiscreteGenericResource represents a "user defined" resource which is defined
   126  // as an integer
   127  // "Kind" is used to describe the Kind of a resource (e.g: "GPU", "FPGA", "SSD", ...)
   128  // Value is used to count the resource (SSD=5, HDD=3, ...)
   129  type DiscreteGenericResource struct {
   130  	Kind  string `json:",omitempty"`
   131  	Value int64  `json:",omitempty"`
   132  }
   133  
   134  // ResourceRequirements represents resources requirements.
   135  type ResourceRequirements struct {
   136  	Limits       *Limit     `json:",omitempty"`
   137  	Reservations *Resources `json:",omitempty"`
   138  }
   139  
   140  // Placement represents orchestration parameters.
   141  type Placement struct {
   142  	Constraints []string              `json:",omitempty"`
   143  	Preferences []PlacementPreference `json:",omitempty"`
   144  	MaxReplicas uint64                `json:",omitempty"`
   145  
   146  	// Platforms stores all the platforms that the image can run on.
   147  	// This field is used in the platform filter for scheduling. If empty,
   148  	// then the platform filter is off, meaning there are no scheduling restrictions.
   149  	Platforms []Platform `json:",omitempty"`
   150  }
   151  
   152  // PlacementPreference provides a way to make the scheduler aware of factors
   153  // such as topology.
   154  type PlacementPreference struct {
   155  	Spread *SpreadOver
   156  }
   157  
   158  // SpreadOver is a scheduling preference that instructs the scheduler to spread
   159  // tasks evenly over groups of nodes identified by labels.
   160  type SpreadOver struct {
   161  	// label descriptor, such as engine.labels.az
   162  	SpreadDescriptor string
   163  }
   164  
   165  // RestartPolicy represents the restart policy.
   166  type RestartPolicy struct {
   167  	Condition   RestartPolicyCondition `json:",omitempty"`
   168  	Delay       *time.Duration         `json:",omitempty"`
   169  	MaxAttempts *uint64                `json:",omitempty"`
   170  	Window      *time.Duration         `json:",omitempty"`
   171  }
   172  
   173  // RestartPolicyCondition represents when to restart.
   174  type RestartPolicyCondition string
   175  
   176  const (
   177  	// RestartPolicyConditionNone NONE
   178  	RestartPolicyConditionNone RestartPolicyCondition = "none"
   179  	// RestartPolicyConditionOnFailure ON_FAILURE
   180  	RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure"
   181  	// RestartPolicyConditionAny ANY
   182  	RestartPolicyConditionAny RestartPolicyCondition = "any"
   183  )
   184  
   185  // TaskStatus represents the status of a task.
   186  type TaskStatus struct {
   187  	Timestamp       time.Time        `json:",omitempty"`
   188  	State           TaskState        `json:",omitempty"`
   189  	Message         string           `json:",omitempty"`
   190  	Err             string           `json:",omitempty"`
   191  	ContainerStatus *ContainerStatus `json:",omitempty"`
   192  	PortStatus      PortStatus       `json:",omitempty"`
   193  }
   194  
   195  // ContainerStatus represents the status of a container.
   196  type ContainerStatus struct {
   197  	ContainerID string
   198  	PID         int
   199  	ExitCode    int
   200  }
   201  
   202  // PortStatus represents the port status of a task's host ports whose
   203  // service has published host ports
   204  type PortStatus struct {
   205  	Ports []PortConfig `json:",omitempty"`
   206  }