Skip to content

Commit 155a103

Browse files
committed
fix(engine): ensure correct server URL config download
1 parent b287691 commit 155a103

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

pkg/engine/engine.go

+9-17
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ func (e *Engine) SetSpec(config *Config) error {
7878

7979
e.Spec = config
8080

81+
// If TLS SANs are configured, the first one will be used as the server URL.
82+
// If not, the host address of the first controlplane will be used.
83+
firstControlplane := e.FilterNodes(RoleServer)[0]
84+
e.serverURL = fmt.Sprintf("https://%s:6443", firstControlplane.SSH.Host)
85+
if len(e.Spec.Cluster.TLSSAN) > 0 {
86+
e.serverURL = fmt.Sprintf("https://%s:6443", e.Spec.Cluster.TLSSAN[0])
87+
}
88+
8189
return nil
8290
}
8391

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

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

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

329-
// configureServerURL assembles the server URL based on the given spec.
330-
func (e *Engine) configureServerURL() error {
331-
// If TLS SANs are configured, the first one will be used as the server URL.
332-
// If not, the host address of the first controlplane will be used.
333-
firstControlplane := e.FilterNodes(RoleServer)[0]
334-
e.serverURL = fmt.Sprintf("https://%s:6443", firstControlplane.SSH.Host)
335-
if len(e.Spec.Cluster.TLSSAN) > 0 {
336-
e.serverURL = fmt.Sprintf("https://%s:6443", e.Spec.Cluster.TLSSAN[0])
337-
}
338-
e.Logger.Info().Str("server_url", e.serverURL).Msg("Configuring server URL")
339-
340-
return nil
341-
}
342-
343335
// fetchInstallationScript returns the downloaded the k3s installer.
344336
func (e *Engine) fetchInstallationScript() ([]byte, error) {
345337
// Lock engine to prevent concurrent access to installer cache.

0 commit comments

Comments
 (0)