github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/api/types/swarm/swarm.go (about)

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