Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all kine schemes to be joined except the local ones #4830

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions pkg/apis/k0s/v1beta1/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,11 @@ func DefaultStorageSpec() *StorageSpec {

// IsJoinable returns true only if the storage config is such that another controller can join the cluster
func (s *StorageSpec) IsJoinable() bool {
if s.Type == EtcdStorageType {
switch s.Type {
case EtcdStorageType:
return !s.Etcd.IsExternalClusterUsed()
}

if strings.HasPrefix(s.Kine.DataSource, "sqlite:") {
return false
}

if strings.HasPrefix(s.Kine.DataSource, "mysql:") {
return true
}

if strings.HasPrefix(s.Kine.DataSource, "postgres:") {
return true
case KineStorageType:
return s.Kine.IsJoinable()
}

return false
Expand Down Expand Up @@ -189,6 +180,28 @@ func DefaultKineConfig(dataDir string) *KineConfig {
}
}

func (k *KineConfig) IsJoinable() bool {
if scheme, _, found := strings.Cut(k.DataSource, ":"); found {
switch scheme {
case "", "sqlite":
return false

case "nats":
if u, err := url.Parse(k.DataSource); err == nil {
if q, err := url.ParseQuery(u.RawQuery); err == nil {
return q.Has("noEmbed")
}
}
return false

default:
return true
}
}

return false
}

// GetEndpointsAsString returns comma-separated list of external cluster endpoints if exist
// or internal etcd address which is https://127.0.0.1:2379
func (e *EtcdConfig) GetEndpointsAsString() string {
Expand Down
44 changes: 41 additions & 3 deletions pkg/apis/k0s/v1beta1/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ func TestStorageSpec_IsJoinable(t *testing.T) {
},
want: true,
},
{
name: "kine-jetstream",
storage: StorageSpec{
Type: "kine",
Kine: &KineConfig{
DataSource: "jetstream://",
},
},
want: true,
},
{
name: "kine-nats",
storage: StorageSpec{
Type: "kine",
Kine: &KineConfig{
DataSource: "nats://",
},
},
want: false,
},
{
name: "kine-nats-noembed",
storage: StorageSpec{
Type: "kine",
Kine: &KineConfig{
DataSource: "nats://?noEmbed",
},
},
want: true,
},
{
name: "kine-unknown",
storage: StorageSpec{
Expand All @@ -92,14 +122,22 @@ func TestStorageSpec_IsJoinable(t *testing.T) {
DataSource: "unknown://foobar",
},
},
want: true,
},
{
name: "kine-none",
storage: StorageSpec{
Type: "kine",
Kine: &KineConfig{
DataSource: "",
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.storage.IsJoinable(); got != tt.want {
t.Errorf("StorageSpec.IsJoinable() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.storage.IsJoinable())
})
}
}
Expand Down
Loading