Skip to content

Commit 2943a66

Browse files
authored
Detects k0sApiPort from the config (#1142)
Signed-off-by: Alexey Makhov <[email protected]> Signed-off-by: makhov <[email protected]>
1 parent b83a028 commit 2943a66

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

internal/controller/bootstrap/controlplane_bootstrap_controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/http"
2525
"net/netip"
2626
"sort"
27+
"strconv"
2728
"strings"
2829
"time"
2930

@@ -635,11 +636,17 @@ func (c *ControlPlaneController) detectJoinHost(ctx context.Context, scope *Cont
635636
Timeout: time.Second,
636637
}
637638

638-
// TODO: fix hardcoded port
639639
port := "9443"
640+
k0sAPIPort, found, err := unstructured.NestedInt64(scope.Config.Spec.K0sConfigSpec.K0s.Object, "spec", "api", "k0sApiPort")
641+
if err != nil {
642+
return "", fmt.Errorf("error retrieving k0sAPIPort: %w", err)
643+
}
644+
if found && k0sAPIPort > 0 {
645+
port = strconv.Itoa(int(k0sAPIPort))
646+
}
640647
host := fmt.Sprintf("https://%s:%s", scope.Cluster.Spec.ControlPlaneEndpoint.Host, port)
641648

642-
_, err := httpClient.Get(fmt.Sprintf("%s/v1beta1/ca", host))
649+
_, err = httpClient.Get(fmt.Sprintf("%s/v1beta1/ca", host))
643650
if err == nil {
644651
return host, nil
645652
}

inttest/capi-controlplane-docker/capi_controlplane_docker_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ spec:
307307
name: k0s
308308
spec:
309309
api:
310+
k0sApiPort: 14443
310311
extraArgs:
311312
anonymous-auth: "true"
312313
telemetry:

0 commit comments

Comments
 (0)