Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer/config: add the role setup #634

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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