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
@@ -152,11 +152,16 @@ func CommandMount(input CommandMountInput) error {
|
||||
return err
|
||||
}
|
||||
|
||||
appScheduler := common.GetAppScheduler(input.AppName)
|
||||
|
||||
// Legacy colon form: synthesize a legacy-<hash> entry plus an
|
||||
// attachment so storage:list (now attachment-only) sees the mount.
|
||||
// The storage docker-args trigger emits the corresponding -v flag at
|
||||
// deploy time, so behavior at the docker-run boundary is unchanged.
|
||||
if strings.Contains(input.NameOrPath, ":") {
|
||||
if appScheduler != SchedulerDockerLocal {
|
||||
return fmt.Errorf("colon-form mounts are only supported on docker-local apps; %s is a %s app. Create a named entry with 'dokku storage:create --scheduler %s' and mount it instead", input.AppName, appScheduler, appScheduler)
|
||||
}
|
||||
return mountLegacyColon(input.AppName, input.NameOrPath)
|
||||
}
|
||||
|
||||
@@ -173,6 +178,10 @@ func CommandMount(input CommandMountInput) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if entry.Scheduler != appScheduler {
|
||||
return fmt.Errorf("storage entry %q is scheduler=%s but cannot be mounted on a %s app; recreate it with --scheduler %s", entry.Name, entry.Scheduler, appScheduler, appScheduler)
|
||||
}
|
||||
|
||||
phases := input.Phases
|
||||
if len(phases) == 0 {
|
||||
phases = []string{PhaseDeploy, PhaseRun}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -15,3 +17,60 @@ func TestResolveChownIDRejectsOutOfBoundsValues(t *testing.T) {
|
||||
Expect(err.Error()).To(ContainSubstring("Unsupported chown permissions"))
|
||||
}
|
||||
}
|
||||
|
||||
func setupTestApp(t *testing.T, appName string) {
|
||||
t.Helper()
|
||||
libRoot := withTempLibRoot(t)
|
||||
dokkuRoot := t.TempDir()
|
||||
t.Setenv("DOKKU_ROOT", dokkuRoot)
|
||||
t.Setenv("PLUGIN_PATH", filepath.Join(libRoot, "plugins"))
|
||||
if err := os.MkdirAll(filepath.Join(dokkuRoot, appName), 0755); err != nil {
|
||||
t.Fatalf("mkdir app root: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandMountRejectsSchedulerMismatch(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
setupTestApp(t, "demo")
|
||||
|
||||
Expect(SaveEntry(&Entry{
|
||||
Name: "demo-pvc",
|
||||
Scheduler: SchedulerK3s,
|
||||
})).To(Succeed())
|
||||
|
||||
err := CommandMount(CommandMountInput{
|
||||
AppName: "demo",
|
||||
NameOrPath: "demo-pvc",
|
||||
ContainerDir: "/data",
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal(`storage entry "demo-pvc" is scheduler=k3s but cannot be mounted on a docker-local app; recreate it with --scheduler docker-local`))
|
||||
|
||||
attachments, err := LoadAttachments("demo")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(attachments).To(BeEmpty())
|
||||
}
|
||||
|
||||
func TestCommandMountAcceptsMatchingScheduler(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
setupTestApp(t, "demo")
|
||||
|
||||
Expect(SaveEntry(&Entry{
|
||||
Name: "demo-data",
|
||||
Scheduler: SchedulerDockerLocal,
|
||||
HostPath: "/data",
|
||||
})).To(Succeed())
|
||||
|
||||
err := CommandMount(CommandMountInput{
|
||||
AppName: "demo",
|
||||
NameOrPath: "demo-data",
|
||||
ContainerDir: "/data",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
attachments, err := LoadAttachments("demo")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(attachments).To(HaveLen(1))
|
||||
Expect(attachments[0].EntryName).To(Equal("demo-data"))
|
||||
Expect(attachments[0].ContainerPath).To(Equal("/data"))
|
||||
}
|
||||
@@ -252,7 +252,7 @@ func TriggerDockerArgs(appName string, phase string) error {
|
||||
return fmt.Errorf("attachment on %q references missing entry %q: %w", appName, attachment.EntryName, err)
|
||||
}
|
||||
if entry.Scheduler != SchedulerDockerLocal {
|
||||
continue
|
||||
return fmt.Errorf("storage entry %q is scheduler=%s but is mounted on a docker-local app; recreate it with --scheduler docker-local", entry.Name, entry.Scheduler)
|
||||
}
|
||||
flag := buildDockerVFlag(entry, attachment)
|
||||
if flag == "" {
|
||||
|
||||
@@ -60,3 +60,25 @@ func TestBuildDockerVFlagVolumeOptions(t *testing.T) {
|
||||
roOpts := buildDockerVFlag(entry, &Attachment{ContainerPath: "/container", Readonly: true, VolumeOptions: "noexec,nosuid"})
|
||||
Expect(roOpts).To(Equal("-v /host:/container:ro,noexec,nosuid"))
|
||||
}
|
||||
|
||||
func TestTriggerDockerArgsRejectsSchedulerMismatch(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
root := withTempLibRoot(t)
|
||||
|
||||
Expect(SaveEntry(&Entry{
|
||||
Name: "demo-pvc",
|
||||
Scheduler: SchedulerK3s,
|
||||
})).To(Succeed())
|
||||
|
||||
writeAttachmentsFile(t, root, "demo", []*Attachment{
|
||||
{
|
||||
EntryName: "demo-pvc",
|
||||
ContainerPath: "/data",
|
||||
Phases: []string{PhaseDeploy},
|
||||
},
|
||||
})
|
||||
|
||||
err := TriggerDockerArgs("demo", PhaseDeploy)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal(`storage entry "demo-pvc" is scheduler=k3s but is mounted on a docker-local app; recreate it with --scheduler docker-local`))
|
||||
}
|
||||
Reference in new issue
Block a user