From 155bfde72d2d6c807377e8b04b022ae80e4a6e0b Mon Sep 17 00:00:00 2001 From: secustor Date: Tue, 7 Jan 2025 23:28:18 +0100 Subject: [PATCH 1/3] fix(phase/configure_k0s): do not add etcd peerAddress for localhost --- phase/configure_k0s.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phase/configure_k0s.go b/phase/configure_k0s.go index ac198b711..92c8c2a82 100644 --- a/phase/configure_k0s.go +++ b/phase/configure_k0s.go @@ -336,7 +336,7 @@ func (p *ConfigureK0s) configFor(h *cluster.Host) (string, error) { } } - if cfg.Dig("spec", "storage", "etcd", "peerAddress") != nil || h.PrivateAddress != "" { + if cfg.Dig("spec", "storage", "etcd", "peerAddress") != nil && h.PrivateAddress != "" { cfg.DigMapping("spec", "storage", "etcd")["peerAddress"] = addr } From 10e7d089aca13d78acba40750297bc702aabc1fc Mon Sep 17 00:00:00 2001 From: secustor Date: Mon, 13 Jan 2025 23:16:37 +0100 Subject: [PATCH 2/3] keep current logic and ignore for 'single' --- phase/configure_k0s.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phase/configure_k0s.go b/phase/configure_k0s.go index 92c8c2a82..79be01b30 100644 --- a/phase/configure_k0s.go +++ b/phase/configure_k0s.go @@ -336,8 +336,10 @@ func (p *ConfigureK0s) configFor(h *cluster.Host) (string, error) { } } - if cfg.Dig("spec", "storage", "etcd", "peerAddress") != nil && h.PrivateAddress != "" { - cfg.DigMapping("spec", "storage", "etcd")["peerAddress"] = addr + if h.Role != "single" { + if cfg.Dig("spec", "storage", "etcd", "peerAddress") != nil || h.PrivateAddress != "" { + cfg.DigMapping("spec", "storage", "etcd")["peerAddress"] = addr + } } if _, ok := cfg["apiVersion"]; !ok { From 31cc97149ab628910ce38343b7a673129b9c7ef9 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 16 Jan 2025 14:22:36 +0200 Subject: [PATCH 3/3] Add cluster.StorageType() Signed-off-by: Kimmo Lehto --- phase/configure_k0s.go | 2 +- .../k0sctl.k0sproject.io/v1beta1/cluster.go | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/phase/configure_k0s.go b/phase/configure_k0s.go index 79be01b30..03694733b 100644 --- a/phase/configure_k0s.go +++ b/phase/configure_k0s.go @@ -336,7 +336,7 @@ func (p *ConfigureK0s) configFor(h *cluster.Host) (string, error) { } } - if h.Role != "single" { + if p.Config.StorageType() == "etcd" { if cfg.Dig("spec", "storage", "etcd", "peerAddress") != nil || h.PrivateAddress != "" { cfg.DigMapping("spec", "storage", "etcd")["peerAddress"] = addr } diff --git a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.go b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.go index b2c69ce71..a2da75a64 100644 --- a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.go +++ b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.go @@ -58,3 +58,26 @@ func (c *Cluster) Validate() error { validation.Field(&c.Spec), ) } + +// StorageType returns the k0s storage type. +func (c *Cluster) StorageType() string { + if c.Spec == nil { + // default to etcd when there's no hosts or k0s spec, this should never happen. + return "etcd" + } + + if c.Spec.K0s != nil { + if t := c.Spec.K0s.Config.DigString("spec", "storage", "type"); t != "" { + // if storage type is set in k0s spec, return it + return t + } + } + + if h := c.Spec.K0sLeader(); h != nil && h.Role == "single" { + // default to "kine" on single node clusters + return "kine" + } + + // default to etcd otherwise + return "etcd" +}