Skip to content

Commit 827c669

Browse files
committed
fix: properly format IPv6 addresses in server URLs
When provisioning nodes with IPv6 control plane endpoints, the bootstrap provider was generating invalid server URLs in the RKE2 configuration. Invalid format: https://fd12:3456:890b::250:6443 Correct format: https://[fd12:3456:890b::250]:6443 This fix uses the standard library net.JoinHostPort function which properly handles IPv6 bracket notation per RFC 3986. The function automatically wraps IPv6 addresses in brackets while leaving IPv4 addresses and hostnames unchanged. The fix is applied to all three server URL generation points: - Init control plane config - Join control plane config - Worker node config This eliminates the need for sed workarounds in user manifests. Fixes: Invalid IPv6 URL parsing in RKE2 bootstrap config Signed-off-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent ff6401d commit 827c669

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

bootstrap/internal/controllers/rke2config_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"context"
2323
"errors"
2424
"fmt"
25+
"net"
26+
"strconv"
2527
"time"
2628

2729
"github.com/go-logr/logr"
@@ -62,7 +64,6 @@ import (
6264
const (
6365
filePermissions string = "0640"
6466
registrationPort int = 9345
65-
serverURLFormat string = "https://%v:%v"
6667
tokenPrefix string = "-token"
6768
)
6869

@@ -469,7 +470,7 @@ func (r *RKE2ConfigReconciler) handleClusterNotInitialized(ctx context.Context,
469470
Cluster: *scope.Cluster,
470471
ControlPlaneEndpoint: scope.Cluster.Spec.ControlPlaneEndpoint.Host,
471472
Token: token,
472-
ServerURL: fmt.Sprintf(serverURLFormat, registrationAddress, registrationPort),
473+
ServerURL: fmt.Sprintf("https://%s", net.JoinHostPort(registrationAddress, strconv.Itoa(registrationPort))),
473474
ServerConfig: scope.ControlPlane.Spec.ServerConfig,
474475
AgentConfig: scope.Config.Spec.AgentConfig,
475476
Ctx: ctx,
@@ -713,7 +714,7 @@ func (r *RKE2ConfigReconciler) joinControlplane(ctx context.Context, scope *Scop
713714
Cluster: *scope.Cluster,
714715
Token: token,
715716
ControlPlaneEndpoint: scope.Cluster.Spec.ControlPlaneEndpoint.Host,
716-
ServerURL: fmt.Sprintf(serverURLFormat, scope.ControlPlane.Status.AvailableServerIPs[0], registrationPort),
717+
ServerURL: fmt.Sprintf("https://%s", net.JoinHostPort(scope.ControlPlane.Status.AvailableServerIPs[0], strconv.Itoa(registrationPort))),
717718
ServerConfig: scope.ControlPlane.Spec.ServerConfig,
718719
AgentConfig: scope.Config.Spec.AgentConfig,
719720
Ctx: ctx,
@@ -863,7 +864,7 @@ func (r *RKE2ConfigReconciler) joinWorker(ctx context.Context, scope *Scope) (re
863864

864865
configStruct, configFiles, err := rke2.GenerateWorkerConfig(
865866
rke2.AgentConfigOpts{
866-
ServerURL: fmt.Sprintf(serverURLFormat, scope.ControlPlane.Status.AvailableServerIPs[0], registrationPort),
867+
ServerURL: fmt.Sprintf("https://%s", net.JoinHostPort(scope.ControlPlane.Status.AvailableServerIPs[0], strconv.Itoa(registrationPort))),
867868
Token: token,
868869
AgentConfig: scope.Config.Spec.AgentConfig,
869870
Ctx: ctx,

0 commit comments

Comments
 (0)