Merge pull request #9010 from visheshgubrani/8994-storage-mount-scheduler-mismatch
Reject scheduler mismatch at mount time
This commit is contained in:
7 files changed
+256
-3
No files matched your search
@@ -285,8 +285,8 @@ func ToProcessVolumes(pairs []AppMountPair) ([]ProcessVolume, error) {
|
||||
if pair.Entry == nil || pair.Attachment == nil {
|
||||
continue
|
||||
}
|
||||
if pair.Entry.Scheduler == storage.SchedulerDockerLocal {
|
||||
return nil, fmt.Errorf("storage entry %q is scheduler=docker-local but is mounted on a k3s app; recreate it with --scheduler k3s", pair.Entry.Name)
|
||||
if pair.Entry.Scheduler != storage.SchedulerK3s {
|
||||
return nil, fmt.Errorf("storage entry %q is scheduler=%s but is mounted on a k3s app; recreate it with --scheduler k3s", pair.Entry.Name, pair.Entry.Scheduler)
|
||||
}
|
||||
volumes = append(volumes, ProcessVolume{
|
||||
Name: pair.Entry.Name,
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package scheduler_k3s
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/dokku/dokku/plugins/storage"
|
||||
)
|
||||
|
||||
func TestToProcessVolumesRejectsDockerLocalEntry(t *testing.T) {
|
||||
pairs := []AppMountPair{
|
||||
{
|
||||
Entry: &storage.Entry{
|
||||
Name: "demo-data",
|
||||
Scheduler: storage.SchedulerDockerLocal,
|
||||
},
|
||||
Attachment: &storage.Attachment{
|
||||
ContainerPath: "/data",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, err := ToProcessVolumes(pairs)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for docker-local entry, got nil")
|
||||
}
|
||||
expected := `storage entry "demo-data" is scheduler=docker-local but is mounted on a k3s app; recreate it with --scheduler k3s`
|
||||
if err.Error() != expected {
|
||||
t.Fatalf("expected error %q, got %q", expected, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestToProcessVolumesRejectsNonK3sEntry(t *testing.T) {
|
||||
pairs := []AppMountPair{
|
||||
{
|
||||
Entry: &storage.Entry{
|
||||
Name: "demo-custom",
|
||||
Scheduler: "nomad",
|
||||
},
|
||||
Attachment: &storage.Attachment{
|
||||
ContainerPath: "/data",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, err := ToProcessVolumes(pairs)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for non-k3s entry, got nil")
|
||||
}
|
||||
expected := `storage entry "demo-custom" is scheduler=nomad but is mounted on a k3s app; recreate it with --scheduler k3s`
|
||||
if err.Error() != expected {
|
||||
t.Fatalf("expected error %q, got %q", expected, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestToProcessVolumesAcceptsK3sEntry(t *testing.T) {
|
||||
pairs := []AppMountPair{
|
||||
{
|
||||
Entry: &storage.Entry{
|
||||
Name: "demo-pvc",
|
||||
Scheduler: storage.SchedulerK3s,
|
||||
},
|
||||
Attachment: &storage.Attachment{
|
||||
ContainerPath: "/app/data",
|
||||
Subpath: "sub",
|
||||
Readonly: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
volumes, err := ToProcessVolumes(pairs)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(volumes) != 1 {
|
||||
t.Fatalf("expected 1 volume, got %d", len(volumes))
|
||||
}
|
||||
v := volumes[0]
|
||||
if v.Name != "demo-pvc" {
|
||||
t.Errorf("expected volume name demo-pvc, got %s", v.Name)
|
||||
}
|
||||
if v.MountPath != "/app/data" {
|
||||
t.Errorf("expected mount path /app/data, got %s", v.MountPath)
|
||||
}
|
||||
if v.SubPath != "sub" {
|
||||
t.Errorf("expected subpath sub, got %s", v.SubPath)
|
||||
}
|
||||
if !v.ReadOnly {
|
||||
t.Errorf("expected read only true, got %v", v.ReadOnly)
|
||||
}
|
||||
if v.PersistentClaim == nil || v.PersistentClaim.ClaimName != "demo-pvc" {
|
||||
t.Errorf("expected persistent claim name demo-pvc, got %+v", v.PersistentClaim)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToProcessVolumesSkipsNilPairs(t *testing.T) {
|
||||
pairs := []AppMountPair{
|
||||
{Entry: nil, Attachment: nil},
|
||||
{Entry: &storage.Entry{Name: "demo", Scheduler: storage.SchedulerK3s}, Attachment: nil},
|
||||
{Entry: nil, Attachment: &storage.Attachment{ContainerPath: "/data"}},
|
||||
}
|
||||
|
||||
volumes, err := ToProcessVolumes(pairs)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(volumes) != 0 {
|
||||
t.Fatalf("expected 0 volumes, got %d", len(volumes))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user