From 155a10358d4df7aea8396dc07dfa44d13d816665 Mon Sep 17 00:00:00 2001 From: Nicklas Frahm Date: Sat, 7 May 2022 14:27:18 +0200 Subject: [PATCH] fix(engine): ensure correct server URL config download --- pkg/engine/engine.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 6f660f0..b09cf43 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -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 } @@ -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 @@ -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.