From e01386089a9e00ff2dc6c99c1789c21449d9ae7f Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 5 Nov 2024 13:45:15 +0100 Subject: [PATCH] Fix etcd peer URL to support ipv6 IPv6 URL need to have brackets [] around the ipv6 to separate it from the port. Eg https://[xx:yy:zz]:2380 Fix this by using net/url's String() formatter. Signed-off-by: Natanael Copa (cherry picked from commit 1469e0c5142b49d2be6abd79e56eb9580f716537) (cherry picked from commit 312a8c333e05d4f659e281c9c327ba20ac19c571) --- pkg/apis/k0s/v1beta1/storage.go | 10 ++++++++++ pkg/backup/etcd.go | 8 +++++++- pkg/component/controller/etcd.go | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/apis/k0s/v1beta1/storage.go b/pkg/apis/k0s/v1beta1/storage.go index c5e80c6bb6af..0f67e7c715b9 100644 --- a/pkg/apis/k0s/v1beta1/storage.go +++ b/pkg/apis/k0s/v1beta1/storage.go @@ -19,6 +19,7 @@ package v1beta1 import ( "encoding/json" "fmt" + "net" "net/url" "path/filepath" "strings" @@ -161,6 +162,15 @@ func DefaultEtcdConfig() *EtcdConfig { } } +// GetPeerURL returns the URL of PeerAddress +func (e *EtcdConfig) GetPeerURL() string { + u := &url.URL{ + Scheme: "https", + Host: net.JoinHostPort(e.PeerAddress, "2380"), + } + return u.String() +} + // DefaultKineConfig creates KineConfig with sane defaults func DefaultKineConfig(dataDir string) *KineConfig { // https://www.sqlite.org/c3ref/open.html#urifilenamesinsqlite3open diff --git a/pkg/backup/etcd.go b/pkg/backup/etcd.go index edec244ea78c..27348d6670d3 100644 --- a/pkg/backup/etcd.go +++ b/pkg/backup/etcd.go @@ -21,6 +21,8 @@ package backup import ( "context" "fmt" + "net" + "net/url" "os" "path/filepath" @@ -84,7 +86,11 @@ func (e etcdStep) Restore(restoreFrom, _ string) error { if err != nil { return err } - peerURL := fmt.Sprintf("https://%s:2380", e.peerAddress) + u := &url.URL{ + Scheme: "https", + Host: net.JoinHostPort(e.peerAddress, "2380"), + } + peerURL := u.String() restoreConfig := utilsnapshot.RestoreConfig{ SnapshotPath: snapshotPath, OutputDataDir: e.etcdDataDir, diff --git a/pkg/component/controller/etcd.go b/pkg/component/controller/etcd.go index 0c532650ebe1..6aef53863e1f 100644 --- a/pkg/component/controller/etcd.go +++ b/pkg/component/controller/etcd.go @@ -155,7 +155,7 @@ func (e *Etcd) Start(ctx context.Context) error { return err } - peerURL := fmt.Sprintf("https://%s:2380", e.Config.PeerAddress) + peerURL := e.Config.GetPeerURL() args := stringmap.StringMap{ "--data-dir": e.K0sVars.EtcdDataDir,