Signed-off-by: yangchenliang <yangchenliang@huawei.com>
When worker executor `docker swarm init
--force-new-cluster`,docker would hang.So only manager can process it.
Signed-off-by: yangchenliang <yangchenliang@huawei.com>
| ... | ... |
@@ -15,6 +15,9 @@ const ( |
| 15 | 15 |
|
| 16 | 16 |
// errSwarmCertificatesExpired is returned if docker was not started for the whole validity period and they had no chance to renew automatically. |
| 17 | 17 |
errSwarmCertificatesExpired notAvailableError = "Swarm certificates have expired. To replace them, leave the swarm and join again." |
| 18 |
+ |
|
| 19 |
+ // errSwarmNotManager is returned if the node is not a swarm manager. |
|
| 20 |
+ errSwarmNotManager notAvailableError = "This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager." |
|
| 18 | 21 |
) |
| 19 | 22 |
|
| 20 | 23 |
type notFoundError struct {
|
| ... | ... |
@@ -26,9 +26,13 @@ func (c *Cluster) Init(req types.InitRequest) (string, error) {
|
| 26 | 26 |
defer c.controlMutex.Unlock() |
| 27 | 27 |
if c.nr != nil {
|
| 28 | 28 |
if req.ForceNewCluster {
|
| 29 |
+ |
|
| 29 | 30 |
// Take c.mu temporarily to wait for presently running |
| 30 | 31 |
// API handlers to finish before shutting down the node. |
| 31 | 32 |
c.mu.Lock() |
| 33 |
+ if !c.nr.nodeState.IsManager() {
|
|
| 34 |
+ return "", errSwarmNotManager |
|
| 35 |
+ } |
|
| 32 | 36 |
c.mu.Unlock() |
| 33 | 37 |
|
| 34 | 38 |
if err := c.nr.Stop(); err != nil {
|