Commit 8fbf5ac7 authored by Guido Trotter's avatar Guido Trotter
Browse files

LUSetNodeParams: Don't break config on mc demotion.



If --force is used to demote an MC, but then there are not enough MCs in
the cluster, the configuration gets corrupted until a node is promoted.

In order to avoid that we only allow demotion with --force if the node
is offlined or drained at the same time, and we don't have any other
node available to promote.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent e623dbe3
......@@ -2970,14 +2970,21 @@ class LUSetNodeParams(LogicalUnit):
raise errors.OpPrereqError("The master role can be changed"
" only via masterfailover")
if ((self.op.master_candidate == False or self.op.offline == True or
self.op.drained == True) and node.master_candidate):
# Boolean value that tells us whether we're offlining or draining the node
offline_or_drain = self.op.offline == True or self.op.drained == True
if (node.master_candidate and
(self.op.master_candidate == False or offline_or_drain)):
cp_size = self.cfg.GetClusterInfo().candidate_pool_size
num_candidates, _, _ = self.cfg.GetMasterCandidateStats()
if num_candidates <= cp_size:
mc_now, mc_should, mc_max = self.cfg.GetMasterCandidateStats()
if mc_now <= cp_size:
msg = ("Not enough master candidates (desired"
" %d, new value will be %d)" % (cp_size, num_candidates-1))
if self.op.force:
" %d, new value will be %d)" % (cp_size, mc_now-1))
# Only allow forcing the operation if it's an offline/drain operation,
# and we could not possibly promote more nodes.
# FIXME: this can still lead to issues if in any way another node which
# could be promoted appears in the meantime.
if self.op.force and offline_or_drain and mc_should == mc_max:
self.LogWarning(msg)
else:
raise errors.OpPrereqError(msg)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment