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