Skip to content

Commit

Permalink
fix(engine): allow usage of custom API server port
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasfrahm committed Sep 21, 2022
1 parent 4ad0c68 commit e4b27c1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ func (e *Engine) SetSpec(config *Config) error {

e.Spec = config

port := 6443
if e.Spec.Cluster.Server.HTTPSListenPort != 0 {
port = e.Spec.Cluster.Server.HTTPSListenPort
}
if e.Spec.Cluster.Server.AdvertisePort != 0 {
port = e.Spec.Cluster.Server.AdvertisePort
}

// 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)
e.serverURL = fmt.Sprintf("https://%s:%d", firstControlplane.SSH.Host, port)
if len(e.Spec.Cluster.Server.TLSSAN) > 0 {
e.serverURL = fmt.Sprintf("https://%s:6443", e.Spec.Cluster.Server.TLSSAN[0])
e.serverURL = fmt.Sprintf("https://%s:%d", e.Spec.Cluster.Server.TLSSAN[0], port)
}

return nil
Expand Down Expand Up @@ -283,8 +291,13 @@ func (e *Engine) KubeConfig(outputPath string) error {
return err
}

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

newConfig.Clusters[cluster] = newConfig.Clusters["default"]
Expand Down

0 comments on commit e4b27c1

Please sign in to comment.