Skip to content

Commit

Permalink
Always treat an etcd backend as joinable
Browse files Browse the repository at this point in the history
Controllers will always be able to connect to it, either by joining as
a managed etcd node, or by simply connecting to an external cluster over
the network. Add some comments about whether a backend is considered
joinable or not to both the etcd and kine storage types.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Jan 15, 2025
1 parent 2e0eefe commit 82f48bd
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/apis/k0s/v1beta1/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ func DefaultStorageSpec() *StorageSpec {
func (s *StorageSpec) IsJoinable() bool {
switch s.Type {
case EtcdStorageType:
return !s.Etcd.IsExternalClusterUsed()
// Controllers will always be able to join. New controllers will
// automatically join the internal etcd cluster, or simply connect
// to the external one over the network.
return true

case KineStorageType:
return s.Kine.IsJoinable()
}

return false
default:
return false
}
}

// UnmarshalJSON sets in some sane defaults when unmarshaling the data from json
Expand Down Expand Up @@ -211,18 +216,24 @@ func (k *KineConfig) IsJoinable() bool {

switch backend {
case "sqlite":
// An sqlite backend is only available via the file system.
return false

case "nats":
if u, err := url.Parse(dsn); err == nil {
if q, err := url.ParseQuery(u.RawQuery); err == nil {
// If it's not an embedded NATS, other controllers may
// also be able to connect to it over the network.
return q.Has("noEmbed")
}
}
return false
}

return true
default:
// The assumption is that all other backends will
// somehow be reachable over the network.
return true
}
}

// GetEndpointsAsString returns comma-separated list of external cluster endpoints if exist
Expand Down

0 comments on commit 82f48bd

Please sign in to comment.