Skip to content

Commit

Permalink
fix(engine): ensure correct server URL config download
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasfrahm committed May 7, 2022
1 parent b287691 commit 155a103
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ func (e *Engine) SetSpec(config *Config) error {

e.Spec = config

// If TLS SANs are configured, the first one will be used as the server URL.
// If not, the host address of the first controlplane will be used.
firstControlplane := e.FilterNodes(RoleServer)[0]
e.serverURL = fmt.Sprintf("https://%s:6443", firstControlplane.SSH.Host)
if len(e.Spec.Cluster.TLSSAN) > 0 {
e.serverURL = fmt.Sprintf("https://%s:6443", e.Spec.Cluster.TLSSAN[0])
}

return nil
}

Expand Down Expand Up @@ -148,9 +156,7 @@ func (e *Engine) ConfigureNode(node *Node) error {

// Install runs the installation script on the node.
func (e *Engine) Install() error {
if err := e.configureServerURL(); err != nil {
return err
}
e.Logger.Info().Str("server_url", e.serverURL).Msg("Detecting server URL")

if err := e.installControlPlanes(); err != nil {
return err
Expand Down Expand Up @@ -326,20 +332,6 @@ func (e *Engine) KubeConfig(outputPath string) error {
return clientcmd.WriteToFile(*oldConfig, outputPath)
}

// configureServerURL assembles the server URL based on the given spec.
func (e *Engine) configureServerURL() error {
// If TLS SANs are configured, the first one will be used as the server URL.
// If not, the host address of the first controlplane will be used.
firstControlplane := e.FilterNodes(RoleServer)[0]
e.serverURL = fmt.Sprintf("https://%s:6443", firstControlplane.SSH.Host)
if len(e.Spec.Cluster.TLSSAN) > 0 {
e.serverURL = fmt.Sprintf("https://%s:6443", e.Spec.Cluster.TLSSAN[0])
}
e.Logger.Info().Str("server_url", e.serverURL).Msg("Configuring server URL")

return nil
}

// fetchInstallationScript returns the downloaded the k3s installer.
func (e *Engine) fetchInstallationScript() ([]byte, error) {
// Lock engine to prevent concurrent access to installer cache.
Expand Down

0 comments on commit 155a103

Please sign in to comment.