swarm.go 5.8 KB

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