Merge pull request #38891 from thaJeztah/warn_manager_count

Return a warning when running in a two-manager setup
This commit is contained in:
Sebastiaan van Stijn 2019-03-19 22:54:53 +01:00 committed by GitHub
commit e7b5f7dbe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

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

View File

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

View File

@ -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 {