瀏覽代碼

Return a warning when running in a two-manager setup

Running a cluster in a two-manager configuration effectively *doubles*
the chance of loosing control over the cluster (compared to running
in a single-manager setup). Users may have the assumption that having
two managers provides fault tolerance, so it's best to warn them if
they're using this configuration.

This patch adds a warning to the `info` response if Swarm is configured
with two managers:

    WARNING: Running Swarm in a two-manager configuration. This configuration provides
             no fault tolerance, and poses a high risk to loose control over the cluster.
             Refer to https://docs.docker.com/engine/swarm/admin_guide/ to configure the
             Swarm for fault-tolerance.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 6 年之前
父節點
當前提交
81eef17e38
共有 3 個文件被更改,包括 17 次插入0 次删除
  1. 1 0
      api/server/router/system/system_routes.go
  2. 2 0
      api/types/swarm/swarm.go
  3. 14 0
      daemon/cluster/swarm.go

+ 1 - 0
api/server/router/system/system_routes.go

@@ -50,6 +50,7 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
 	}
 	}
 	if s.cluster != nil {
 	if s.cluster != nil {
 		info.Swarm = s.cluster.Info()
 		info.Swarm = s.cluster.Info()
+		info.Warnings = append(info.Warnings, info.Swarm.Warnings...)
 	}
 	}
 
 
 	if versions.LessThan(httputils.VersionFromContext(ctx), "1.25") {
 	if versions.LessThan(httputils.VersionFromContext(ctx), "1.25") {

+ 2 - 0
api/types/swarm/swarm.go

@@ -209,6 +209,8 @@ type Info struct {
 	Managers       int `json:",omitempty"`
 	Managers       int `json:",omitempty"`
 
 
 	Cluster *ClusterInfo `json:",omitempty"`
 	Cluster *ClusterInfo `json:",omitempty"`
+
+	Warnings []string `json:",omitempty"`
 }
 }
 
 
 // Peer represents a peer.
 // Peer represents a peer.

+ 14 - 0
daemon/cluster/swarm.go

@@ -459,6 +459,20 @@ func (c *Cluster) Info() types.Info {
 				}
 				}
 			}
 			}
 		}
 		}
+
+		switch info.LocalNodeState {
+		case types.LocalNodeStateInactive, types.LocalNodeStateLocked, types.LocalNodeStateError:
+			// nothing to do
+		default:
+			if info.Managers == 2 {
+				const warn string = `WARNING: Running Swarm in a two-manager configuration. This configuration provides
+         no fault tolerance, and poses a high risk to loose control over the cluster.
+         Refer to https://docs.docker.com/engine/swarm/admin_guide/ to configure the
+         Swarm for fault-tolerance.`
+
+				info.Warnings = append(info.Warnings, warn)
+			}
+		}
 	}
 	}
 
 
 	if state.swarmNode != nil {
 	if state.swarmNode != nil {