diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 5e6d35141..767130b4b 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -8,6 +8,8 @@ const ( RoleDefault = "default" RoleWitness = "witness" + RoleMgmt = "management" + RoleWorker = "worker" NetworkMethodDHCP = "dhcp" NetworkMethodStatic = "static" diff --git a/pkg/console/install_panels.go b/pkg/console/install_panels.go index 030b2f357..944cb01f5 100644 --- a/pkg/console/install_panels.go +++ b/pkg/console/install_panels.go @@ -768,10 +768,16 @@ func addAskRolePanel(c *Console) error { return []widgets.Option{ { Value: config.RoleDefault, - Text: "Default Role (Master or Worker)", + Text: "Default Role (Management or Worker)", + }, { + Value: config.RoleMgmt, + Text: "Management Role", }, { Value: config.RoleWitness, Text: "Witness Role", + }, { + Value: config.RoleWorker, + Text: "Worker Role", }, }, nil } @@ -1990,9 +1996,12 @@ func addInstallPanel(c *Console) error { } if alreadyInstalled { - configureInstalledNode(c.Gui, c.config, webhooks) + err = configureInstalledNode(c.Gui, c.config, webhooks) } else { - doInstall(c.Gui, c.config, webhooks) + err = doInstall(c.Gui, c.config, webhooks) + } + if err != nil { + printToPanel(c.Gui, fmt.Sprintf("install failed: %s", err), installPanel) } }() return c.setContentByName(footerPanel, "") diff --git a/pkg/console/util.go b/pkg/console/util.go index a633678b3..d2dd633c7 100644 --- a/pkg/console/util.go +++ b/pkg/console/util.go @@ -447,6 +447,28 @@ func saveTemp(obj interface{}, prefix string) (string, error) { return tempFile.Name(), nil } +func roleSetup(c *config.HarvesterConfig) error { + if c.Role == "" { + return nil + } + if c.Labels == nil { + c.Labels = make(map[string]string) + } + switch c.Role { + case config.RoleMgmt: + c.Labels[util.HarvesterMgmtNodeLabelKey] = "true" + case config.RoleWorker: + c.Labels[util.HarvesterWorkerNodeLabelKey] = "true" + case config.RoleWitness: + c.Labels[util.HarvesterWitnessNodeLabelKey] = "true" + case config.RoleDefault: + // do not set any label + default: + return fmt.Errorf("unknown role %s, please correct it!", c.Role) + } + return nil +} + func doInstall(g *gocui.Gui, hvstConfig *config.HarvesterConfig, webhooks RendererWebhooks) error { ctx := context.TODO() webhooks.Handle(EventInstallStarted) @@ -457,11 +479,8 @@ func doInstall(g *gocui.Gui, hvstConfig *config.HarvesterConfig, webhooks Render } // specific the node label for the specific node role - if hvstConfig.Role == config.RoleWitness { - if hvstConfig.Labels == nil { - hvstConfig.Labels = make(map[string]string) - } - hvstConfig.Labels[util.HarvesterWitnessNodeLabelKey] = "true" + if err := roleSetup(hvstConfig); err != nil { + return err } env, elementalConfig, err := generateEnvAndConfig(g, hvstConfig) @@ -777,11 +796,8 @@ func configureInstalledNode(g *gocui.Gui, hvstConfig *config.HarvesterConfig, we webhooks.Handle(EventInstallStarted) // specific the node label for the specific node role - if hvstConfig.Role == config.RoleWitness { - if hvstConfig.Labels == nil { - hvstConfig.Labels = make(map[string]string) - } - hvstConfig.Labels[util.HarvesterWitnessNodeLabelKey] = "true" + if err := roleSetup(hvstConfig); err != nil { + return err } // skip rancherd and network config in the cos config diff --git a/pkg/util/common.go b/pkg/util/common.go index 8a56dd14f..aad26745f 100644 --- a/pkg/util/common.go +++ b/pkg/util/common.go @@ -7,6 +7,8 @@ import ( var ( HarvesterNodeRoleLabelPrefix = "node-role.harvesterhci.io/" HarvesterWitnessNodeLabelKey = HarvesterNodeRoleLabelPrefix + "witness" + HarvesterMgmtNodeLabelKey = HarvesterNodeRoleLabelPrefix + "management" + HarvesterWorkerNodeLabelKey = HarvesterNodeRoleLabelPrefix + "worker" sizeRegexp = regexp.MustCompile(`^(\d+)(Mi|Gi)$`) )