swarm.go 6.6 KB

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