Skip to content

Commit

Permalink
Do not set etcd peerAddress when cluster storage type is kine (#816)
Browse files Browse the repository at this point in the history
* fix(phase/configure_k0s): do not add etcd peerAddress for localhost

* keep current logic and ignore for 'single'

* Add cluster.StorageType()

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

---------

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Co-authored-by: Kimmo Lehto <klehto@mirantis.com>
  • Loading branch information
secustor and kke authored Jan 16, 2025
1 parent 63ef8eb commit a3795b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions phase/configure_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 p.Config.StorageType() == "etcd" {
if cfg.Dig("spec", "storage", "etcd", "peerAddress") != nil || h.PrivateAddress != "" {
cfg.DigMapping("spec", "storage", "etcd")["peerAddress"] = addr
}
}

if _, ok := cfg["apiVersion"]; !ok {
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit a3795b7

Please sign in to comment.