swarm.go 5.1 KB

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