From 6747fec16209874919378f1d546492c921bcbf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CForest-L?= Date: Sun, 27 Sep 2020 15:24:37 +0800 Subject: [PATCH] Update eted odd check and Whether a node exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “Forest-L --- api/v1alpha1/cluster_types.go | 58 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/api/v1alpha1/cluster_types.go b/api/v1alpha1/cluster_types.go index d4cac5f3..7ed67e1a 100644 --- a/api/v1alpha1/cluster_types.go +++ b/api/v1alpha1/cluster_types.go @@ -166,26 +166,33 @@ func (cfg *ClusterSpec) GroupHosts() *HostGroups { etcdGroup, masterGroup, workerGroup := cfg.ParseRolesList() for index, host := range cfg.Hosts { host.ID = index - for _, hostName := range etcdGroup { - if host.Name == hostName { - host.IsEtcd = true - break + if len(etcdGroup) > 0 { + for _, hostName := range etcdGroup { + if host.Name == hostName { + host.IsEtcd = true + break + } } } - for _, hostName := range masterGroup { - if host.Name == hostName { - host.IsMaster = true - break + if len(masterGroup) > 0 { + for _, hostName := range masterGroup { + if host.Name == hostName { + host.IsMaster = true + break + } } } - for _, hostName := range workerGroup { - if host.Name == hostName { - host.IsWorker = true - break + if len(workerGroup) > 0 { + for _, hostName := range workerGroup { + if hostName != "" && host.Name == hostName { + host.IsWorker = true + break + } } } + if host.IsEtcd { clusterHostsGroups.Etcd = append(clusterHostsGroups.Etcd, host) } @@ -200,8 +207,22 @@ func (cfg *ClusterSpec) GroupHosts() *HostGroups { } clusterHostsGroups.All = append(clusterHostsGroups.All, host) } - clusterHostsGroups.Client = append(clusterHostsGroups.Client, clusterHostsGroups.Master[0]) + //Check that the parameters under roleGroups are incorrect + if len(masterGroup) != len(clusterHostsGroups.Master) { + fmt.Println("Incorrect nodeName under roleGroups/master in the config-sample.yaml, Please check before installing.") + os.Exit(0) + } + if len(etcdGroup) != len(clusterHostsGroups.Master) { + fmt.Println("Incorrect nodeName under roleGroups/etcd in the config-sample.yaml, Please check before installing.") + os.Exit(0) + } + if len(workerGroup) != len(clusterHostsGroups.Master) { + fmt.Println("Incorrect nodeName under roleGroups/work in the config-sample.yaml, Please check before installing.") + os.Exit(0) + } + + clusterHostsGroups.Client = append(clusterHostsGroups.Client, clusterHostsGroups.Master[0]) return &clusterHostsGroups } @@ -220,7 +241,12 @@ func (cfg *ClusterSpec) ParseRolesList() ([]string, []string, []string) { } else { etcdGroupList = append(etcdGroupList, host) } + } + //Check that the number of ETcd is odd + if len(etcdGroupList)%2 == 0 { + fmt.Println("The number of Etcd is even. Please configure it to be odd.") + os.Exit(0) } for _, host := range cfg.RoleGroups.Master { @@ -236,6 +262,12 @@ func (cfg *ClusterSpec) ParseRolesList() ([]string, []string, []string) { os.Exit(0) } + //Check whether LB should be configured + if len(masterGroupList) >= 3 && cfg.ControlPlaneEndpoint.Address == "" { + fmt.Println("When the environment has at least three masters, You must set the value of the LB address.") + os.Exit(0) + } + for _, host := range cfg.RoleGroups.Worker { if strings.Contains(host, "[") && strings.Contains(host, "]") && strings.Contains(host, ":") { workerGroupList = append(workerGroupList, getHostsRange(host)...)