Skip to content

Commit e4b27c1

Browse files
committed
fix(engine): allow usage of custom API server port
1 parent 4ad0c68 commit e4b27c1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pkg/engine/engine.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,20 @@ func (e *Engine) SetSpec(config *Config) error {
7979

8080
e.Spec = config
8181

82+
port := 6443
83+
if e.Spec.Cluster.Server.HTTPSListenPort != 0 {
84+
port = e.Spec.Cluster.Server.HTTPSListenPort
85+
}
86+
if e.Spec.Cluster.Server.AdvertisePort != 0 {
87+
port = e.Spec.Cluster.Server.AdvertisePort
88+
}
89+
8290
// If TLS SANs are configured, the first one will be used as the server URL.
8391
// If not, the host address of the first controlplane will be used.
8492
firstControlplane := e.FilterNodes(RoleServer)[0]
85-
e.serverURL = fmt.Sprintf("https://%s:6443", firstControlplane.SSH.Host)
93+
e.serverURL = fmt.Sprintf("https://%s:%d", firstControlplane.SSH.Host, port)
8694
if len(e.Spec.Cluster.Server.TLSSAN) > 0 {
87-
e.serverURL = fmt.Sprintf("https://%s:6443", e.Spec.Cluster.Server.TLSSAN[0])
95+
e.serverURL = fmt.Sprintf("https://%s:%d", e.Spec.Cluster.Server.TLSSAN[0], port)
8896
}
8997

9098
return nil
@@ -283,8 +291,13 @@ func (e *Engine) KubeConfig(outputPath string) error {
283291
return err
284292
}
285293

286-
// Use the FQDN of the API server as the cluster name.
294+
// Use the FQDN of the API server, as the cluster name and append the port only if it's
295+
// not the default port for the Kubernetes API (6443). This is only done to ensure
296+
// backward compatibility with previous versions of the CLI.
287297
cluster := serverURL.Hostname()
298+
if serverURL.Port() != "6443" {
299+
cluster = fmt.Sprintf("%s:%s", cluster, serverURL.Port())
300+
}
288301
context := "admin@" + cluster
289302

290303
newConfig.Clusters[cluster] = newConfig.Clusters["default"]

0 commit comments

Comments
 (0)