From 59aaef8d9c6f9e9eff90a4b80e78f9af0c5cb77c Mon Sep 17 00:00:00 2001 From: Kevin Nisbet Date: Tue, 10 Sep 2019 15:19:23 -0400 Subject: [PATCH] Kevin/5.5.x/max master nodes (#636) * remove hard requirement that prevents more than 3 masters (#560) * fix typos --- lib/install/planbuilder.go | 26 ++++++++++++++++++++++---- lib/ops/opsservice/install.go | 20 +++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib/install/planbuilder.go b/lib/install/planbuilder.go index 6512505d0b..5927f7aa42 100644 --- a/lib/install/planbuilder.go +++ b/lib/install/planbuilder.go @@ -627,22 +627,40 @@ func (i *Installer) getInstallerTrustedCluster() (storage.TrustedCluster, error) // splitServers splits the provided servers into masters and nodes func splitServers(servers []storage.Server, app app.Application) (masters []storage.Server, nodes []storage.Server, err error) { - count := 0 + numMasters := 0 + + // count the number of servers designated as master by the node profile + for _, server := range servers { + profile, err := app.Manifest.NodeProfiles.ByName(server.Role) + if err != nil { + return nil, nil, trace.Wrap(err) + } + + if profile.ServiceRole == schema.ServiceRoleMaster { + numMasters++ + } + } + + // assign the servers to their roles for _, server := range servers { profile, err := app.Manifest.NodeProfiles.ByName(server.Role) if err != nil { return nil, nil, trace.Wrap(err) } switch profile.ServiceRole { - case schema.ServiceRoleMaster, "": - if count < defaults.MaxMasterNodes { + case "": + if numMasters < defaults.MaxMasterNodes { server.ClusterRole = string(schema.ServiceRoleMaster) masters = append(masters, server) - count++ + numMasters++ } else { server.ClusterRole = string(schema.ServiceRoleNode) nodes = append(nodes, server) } + case schema.ServiceRoleMaster: + server.ClusterRole = string(schema.ServiceRoleMaster) + masters = append(masters, server) + // don't increment numMasters as this server has already been counted above case schema.ServiceRoleNode: server.ClusterRole = string(schema.ServiceRoleNode) nodes = append(nodes, server) diff --git a/lib/ops/opsservice/install.go b/lib/ops/opsservice/install.go index d8adc18897..b347dbf57e 100644 --- a/lib/ops/opsservice/install.go +++ b/lib/ops/opsservice/install.go @@ -873,22 +873,36 @@ func checkLicenseCPU(p licenseapi.Payload, numCPU uint) error { } // setClusterRoles assigns cluster roles to servers. -// If a server has an explicit cluster role assigned, the function will make sure that -// the maximum number of masters is not exceeded. func setClusterRoles(servers []storage.Server, app libapp.Application, masters int) error { + // count the number of servers designated as master by the node profile + for _, server := range servers { + profile, err := app.Manifest.NodeProfiles.ByName(server.Role) + if err != nil { + return trace.Wrap(err) + } + + if profile.ServiceRole == schema.ServiceRoleMaster { + masters++ + } + } + + // assign the servers to their roles for i, server := range servers { profile, err := app.Manifest.NodeProfiles.ByName(server.Role) if err != nil { return trace.Wrap(err) } switch profile.ServiceRole { - case schema.ServiceRoleMaster, "": + case "": if masters < defaults.MaxMasterNodes { servers[i].ClusterRole = string(schema.ServiceRoleMaster) masters++ } else { servers[i].ClusterRole = string(schema.ServiceRoleNode) } + case schema.ServiceRoleMaster: + servers[i].ClusterRole = string(schema.ServiceRoleMaster) + // don't increment masters as this server has already been counted above case schema.ServiceRoleNode: servers[i].ClusterRole = string(schema.ServiceRoleNode) default: