Skip to content

Commit

Permalink
installer/config: add the role setup
Browse files Browse the repository at this point in the history
    Now we support three roles `management`, `worker` and `witness`.
    We need to add the related label to make promote controller
    identify.

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
  • Loading branch information
Vicente-Cheng committed Jan 23, 2024
1 parent d013772 commit 3857191
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions pkg/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const (

RoleDefault = "default"
RoleWitness = "witness"
RoleMgmt = "management"
RoleWorker = "worker"

NetworkMethodDHCP = "dhcp"
NetworkMethodStatic = "static"
Expand Down
15 changes: 12 additions & 3 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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, "")
Expand Down
36 changes: 26 additions & 10 deletions pkg/console/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)$`)
)
Expand Down

0 comments on commit 3857191

Please sign in to comment.