Skip to content

Commit

Permalink
Add cluster.StorageType()
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Jan 16, 2025
1 parent 10e7d08 commit 31cc971
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion phase/configure_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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 31cc971

Please sign in to comment.