Skip to content

Commit

Permalink
Merge pull request #5437 from twz123/external-etcd-join
Browse files Browse the repository at this point in the history
Always treat an etcd backend as joinable
  • Loading branch information
twz123 authored Jan 24, 2025
2 parents 5d47343 + 5d4e3dc commit f3a2dcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 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 connect to an etcd backend, either
// by joining as a managed etcd node, or by simply connecting to an
// external cluster 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
2 changes: 1 addition & 1 deletion pkg/apis/k0s/v1beta1/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestStorageSpec_IsJoinable(t *testing.T) {
PeerAddress: "",
},
},
want: false,
want: true,
},
{
name: "kine-sqlite",
Expand Down

0 comments on commit f3a2dcf

Please sign in to comment.