Skip to content

Commit

Permalink
Updates based on discussion with Gaurav
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed May 13, 2024
1 parent 43ae32f commit 1ffc748
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
2 changes: 2 additions & 0 deletions pkg/console/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ const (
persistentSizeNote = "Note: persistent partition stores data like system package and container images, not the VM data. \nYou can specify a size like 200Gi or 153600Mi. \nLeave it blank to use the default value."

authorizedFile = "/home/rancher/.ssh/authorized_keys"

defaultHostname = "rancher"
)
62 changes: 36 additions & 26 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,13 +1182,6 @@ func showHostnamePage(c *Console) error {
return showNext(c, hostnamePanel)
}

func setupNetwork(c *Console) ([]byte, error) {
return applyNetworks(
mgmtNetwork,
c.config.Hostname,
)
}

func addHostnamePanel(c *Console) error {
hostnameV, err := widgets.NewInput(c.Gui, hostnamePanel, hostNameLabel, false)
if err != nil {
Expand All @@ -1211,10 +1204,6 @@ func addHostnamePanel(c *Console) error {
}

next := func() error {
output, err := setupNetwork(c)
if err != nil {
return fmt.Errorf("Configure network failed: %s %s", string(output), err)
}
c.CloseElements(hostnamePanel, hostnameValidatorPanel)
return showNext(c, getNextPagePanel()...)
}
Expand Down Expand Up @@ -1243,16 +1232,10 @@ func addHostnamePanel(c *Console) error {

hostnameV.PreShow = func() error {
c.Gui.Cursor = true
if c.config.Hostname == "" {
// On the first run through the interactive installer, the hostname is
// not yet set in the harvester config, but we might have been given a
// new hostname via DHCP...
currentHostname, err := os.Hostname()
if currentHostname != "rancher" && err == nil {
// ...if so, let's take that as the default.
c.config.Hostname = currentHostname
}
}
// On the first run through the interactive installer, the hostname is
// not yet set in the harvester config, but we might have been given
// a new hostname via DHCP...
checkDHCPHostname(c.config)
hostnameV.Value = c.config.Hostname
return c.setContentByName(titlePanel, hostnameTitle)
}
Expand Down Expand Up @@ -1379,8 +1362,15 @@ func addNetworkPanel(c *Console) error {
)
}

setupNetwork := func() ([]byte, error) {
return applyNetworks(
mgmtNetwork,
c.config.Hostname,
)
}

preGotoNextPage := func() (string, error) {
output, err := setupNetwork(c)
output, err := setupNetwork()
if err != nil {
return fmt.Sprintf("Configure network failed: %s %s", string(output), err), nil
}
Expand Down Expand Up @@ -2046,12 +2036,15 @@ func addInstallPanel(c *Console) error {
}
logrus.Info("Local config (merged): ", c.config)

if needToGetVIPFromDHCP(c.config.VipMode, c.config.Vip, c.config.VipHwAddr) {
if c.config.Install.ManagementInterface.Method == config.NetworkMethodDHCP {
printToPanel(c.Gui, "Configuring network...", installPanel)
if _, err := applyNetworks(c.config.ManagementInterface, c.config.Hostname); err != nil {
printToPanel(c.Gui, fmt.Sprintf("can't apply networks: %s", err), installPanel)
return
}
}

if needToGetVIPFromDHCP(c.config.VipMode, c.config.Vip, c.config.VipHwAddr) {
mgmtName := getManagementInterfaceName(c.config.ManagementInterface)
vip, err := getVipThroughDHCP(mgmtName)
if err != nil {
Expand All @@ -2064,9 +2057,11 @@ func addInstallPanel(c *Console) error {
}
c.config.VipMode = strings.ToLower(c.config.VipMode)

if c.config.Hostname == "" {
c.config.Hostname = generateHostName()
}
// If no hostname was provided in the config, this function will
// default the hostname to either what's supplied by the DHCP sever,
// or a randomly generated name.
checkDHCPHostname(c.config)

if c.config.TTY == "" {
c.config.TTY = getFirstConsoleTTY()
}
Expand Down Expand Up @@ -2574,6 +2569,21 @@ func configureInstallModeDHCP(c *Console) {

}

func checkDHCPHostname(c *config.HarvesterConfig) {
if c.Hostname == "" {
hostname, err := os.Hostname()
if err != nil {
logrus.Errorf("error fetching hostname from underlying OS: %v", err)
}

if hostname != defaultHostname && hostname != "" {
c.Hostname = hostname
} else {
c.Hostname = generateHostName()
}
}
}

func mergeCloudInit(c *config.HarvesterConfig) error {
cloudConfig, err := config.ReadUserDataConfig()
if err != nil {
Expand Down
10 changes: 1 addition & 9 deletions pkg/console/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ func applyNetworks(network config.Network, hostname string) ([]byte, error) {
// the system hostname will be set to the one provided by the server.
// Later, on the hostname page, we can default the hostname field to
// the current system hostname.
//
// Note that this change means we need to apply the network config
// *again* after the hostname page, so that the hostname will be
// written to /etc/hostname.
//
// I really need to refactor this function a bit so we can just apply
// the network config first, then apply only the hostname change once we
// leave the hostname screen, rather than reapplying all the network
// interface config twice, but this works as-is for a proof of concept.

dhclientSetHostname := "no"
if hostname == "" {
dhclientSetHostname = "yes"
Expand Down

0 comments on commit 1ffc748

Please sign in to comment.