swarm.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package swarm // import "github.com/docker/docker/api/types/swarm"
  2. import (
  3. "time"
  4. )
  5. // ClusterInfo represents info about the cluster for outputting in "info"
  6. // it contains the same information as "Swarm", but without the JoinTokens
  7. type ClusterInfo struct {
  8. ID string
  9. Meta
  10. Spec Spec
  11. TLSInfo TLSInfo
  12. RootRotationInProgress bool
  13. DefaultAddrPool []string
  14. SubnetSize uint32
  15. DataPathPort uint32
  16. }
  17. // Swarm represents a swarm.
  18. type Swarm struct {
  19. ClusterInfo
  20. JoinTokens JoinTokens
  21. }
  22. // JoinTokens contains the tokens workers and managers need to join the swarm.
  23. type JoinTokens struct {
  24. // Worker is the join token workers may use to join the swarm.
  25. Worker string
  26. // Manager is the join token managers may use to join the swarm.
  27. Manager string
  28. }
  29. // Spec represents the spec of a swarm.
  30. type Spec struct {
  31. Annotations
  32. Orchestration OrchestrationConfig `json:",omitempty"`
  33. Raft RaftConfig `json:",omitempty"`
  34. Dispatcher DispatcherConfig `json:",omitempty"`
  35. CAConfig CAConfig `json:",omitempty"`
  36. TaskDefaults TaskDefaults `json:",omitempty"`
  37. EncryptionConfig EncryptionConfig `json:",omitempty"`
  38. }
  39. // OrchestrationConfig represents orchestration configuration.
  40. type OrchestrationConfig struct {
  41. // TaskHistoryRetentionLimit is the number of historic tasks to keep per instance or
  42. // node. If negative, never remove completed or failed tasks.
  43. TaskHistoryRetentionLimit *int64 `json:",omitempty"`
  44. }
  45. // TaskDefaults parameterizes cluster-level task creation with default values.
  46. type TaskDefaults struct {
  47. // LogDriver selects the log driver to use for tasks created in the
  48. // orchestrator if unspecified by a service.
  49. //
  50. // Updating this value will only have an affect on new tasks. Old tasks
  51. // will continue use their previously configured log driver until
  52. // recreated.
  53. LogDriver *Driver `json:",omitempty"`
  54. }
  55. // EncryptionConfig controls at-rest encryption of data and keys.
  56. type EncryptionConfig struct {
  57. // AutoLockManagers specifies whether or not managers TLS keys and raft data
  58. // should be encrypted at rest in such a way that they must be unlocked
  59. // before the manager node starts up again.
  60. AutoLockManagers bool
  61. }
  62. // RaftConfig represents raft configuration.
  63. type RaftConfig struct {
  64. // SnapshotInterval is the number of log entries between snapshots.
  65. SnapshotInterval uint64 `json:",omitempty"`
  66. // KeepOldSnapshots is the number of snapshots to keep beyond the
  67. // current snapshot.
  68. KeepOldSnapshots *uint64 `json:",omitempty"`
  69. // LogEntriesForSlowFollowers is the number of log entries to keep
  70. // around to sync up slow followers after a snapshot is created.
  71. LogEntriesForSlowFollowers uint64 `json:",omitempty"`
  72. // ElectionTick is the number of ticks that a follower will wait for a message
  73. // from the leader before becoming a candidate and starting an election.
  74. // ElectionTick must be greater than HeartbeatTick.
  75. //
  76. // A tick currently defaults to one second, so these translate directly to
  77. // seconds currently, but this is NOT guaranteed.
  78. ElectionTick int
  79. // HeartbeatTick is the number of ticks between heartbeats. Every
  80. // HeartbeatTick ticks, the leader will send a heartbeat to the
  81. // followers.
  82. //
  83. // A tick currently defaults to one second, so these translate directly to
  84. // seconds currently, but this is NOT guaranteed.
  85. HeartbeatTick int
  86. }
  87. // DispatcherConfig represents dispatcher configuration.
  88. type DispatcherConfig struct {
  89. // HeartbeatPeriod defines how often agent should send heartbeats to
  90. // dispatcher.
  91. HeartbeatPeriod time.Duration `json:",omitempty"`
  92. }
  93. // CAConfig represents CA configuration.
  94. type CAConfig struct {
  95. // NodeCertExpiry is the duration certificates should be issued for
  96. NodeCertExpiry time.Duration `json:",omitempty"`
  97. // ExternalCAs is a list of CAs to which a manager node will make
  98. // certificate signing requests for node certificates.
  99. ExternalCAs []*ExternalCA `json:",omitempty"`
  100. // SigningCACert and SigningCAKey specify the desired signing root CA and
  101. // root CA key for the swarm. When inspecting the cluster, the key will
  102. // be redacted.
  103. SigningCACert string `json:",omitempty"`
  104. SigningCAKey string `json:",omitempty"`
  105. // If this value changes, and there is no specified signing cert and key,
  106. // then the swarm is forced to generate a new root certificate ane key.
  107. ForceRotate uint64 `json:",omitempty"`
  108. }
  109. // ExternalCAProtocol represents type of external CA.
  110. type ExternalCAProtocol string
  111. // ExternalCAProtocolCFSSL CFSSL
  112. const ExternalCAProtocolCFSSL ExternalCAProtocol = "cfssl"
  113. // ExternalCA defines external CA to be used by the cluster.
  114. type ExternalCA struct {
  115. // Protocol is the protocol used by this external CA.
  116. Protocol ExternalCAProtocol
  117. // URL is the URL where the external CA can be reached.
  118. URL string
  119. // Options is a set of additional key/value pairs whose interpretation
  120. // depends on the specified CA type.
  121. Options map[string]string `json:",omitempty"`
  122. // CACert specifies which root CA is used by this external CA. This certificate must
  123. // be in PEM format.
  124. CACert string
  125. }
  126. // InitRequest is the request used to init a swarm.
  127. type InitRequest struct {
  128. ListenAddr string
  129. AdvertiseAddr string
  130. DataPathAddr string
  131. DataPathPort uint32
  132. ForceNewCluster bool
  133. Spec Spec
  134. AutoLockManagers bool
  135. Availability NodeAvailability
  136. DefaultAddrPool []string
  137. SubnetSize uint32
  138. }
  139. // JoinRequest is the request used to join a swarm.
  140. type JoinRequest struct {
  141. ListenAddr string
  142. AdvertiseAddr string
  143. DataPathAddr string
  144. RemoteAddrs []string
  145. JoinToken string // accept by secret
  146. Availability NodeAvailability
  147. }
  148. // UnlockRequest is the request used to unlock a swarm.
  149. type UnlockRequest struct {
  150. // UnlockKey is the unlock key in ASCII-armored format.
  151. UnlockKey string
  152. }
  153. // LocalNodeState represents the state of the local node.
  154. type LocalNodeState string
  155. const (
  156. // LocalNodeStateInactive INACTIVE
  157. LocalNodeStateInactive LocalNodeState = "inactive"
  158. // LocalNodeStatePending PENDING
  159. LocalNodeStatePending LocalNodeState = "pending"
  160. // LocalNodeStateActive ACTIVE
  161. LocalNodeStateActive LocalNodeState = "active"
  162. // LocalNodeStateError ERROR
  163. LocalNodeStateError LocalNodeState = "error"
  164. // LocalNodeStateLocked LOCKED
  165. LocalNodeStateLocked LocalNodeState = "locked"
  166. )
  167. // Info represents generic information about swarm.
  168. type Info struct {
  169. NodeID string
  170. NodeAddr string
  171. LocalNodeState LocalNodeState
  172. ControlAvailable bool
  173. Error string
  174. RemoteManagers []Peer
  175. Nodes int `json:",omitempty"`
  176. Managers int `json:",omitempty"`
  177. Cluster *ClusterInfo `json:",omitempty"`
  178. Warnings []string `json:",omitempty"`
  179. }
  180. // Status provides information about the current swarm status and role,
  181. // obtained from the "Swarm" header in the API response.
  182. type Status struct {
  183. // NodeState represents the state of the node.
  184. NodeState LocalNodeState
  185. // ControlAvailable indicates if the node is a swarm manager.
  186. ControlAvailable bool
  187. }
  188. // Peer represents a peer.
  189. type Peer struct {
  190. NodeID string
  191. Addr string
  192. }
  193. // UpdateFlags contains flags for SwarmUpdate.
  194. type UpdateFlags struct {
  195. RotateWorkerToken bool
  196. RotateManagerToken bool
  197. RotateManagerUnlockKey bool
  198. }