feat: allow storage:mount --replace to vary fields per mount
`storage:mount --replace` writes one process type's whole attachment set in a single call, but only part of an attachment could vary between the mounts in that call: each mount carried its own `ro` and Docker mount options while `--phase`, `--volume-subpath` and `--volume-chown` were fixed for the whole call, so an app whose mounts differ only in subpath still needed one call per mount, which is the non-atomic convergence `--replace` exists to remove. Each mount's option list now also carries `phase=`, `volume-subpath=` and `volume-chown=` tokens alongside `ro`, its new opposite `rw` and the Docker options it already passed through, and so that each attribute has exactly one spelling the five matching flags are now rejected with `--replace` - one of which, `--volume-options`, was previously accepted and silently dropped. `--process-type` still scopes the whole call, since it selects which mounts the call is authoritative over rather than describing any one of them. Every mount is parsed and validated before anything is written, so a rejected token leaves the stored mounts untouched. The documentation added for `--replace` was also marked as new in 0.38.28 in four places, but it shipped in 0.38.29.
This commit is contained in:
6 files changed
+699
-88
No files matched your search
@@ -152,8 +152,9 @@ func isUserNamespacesEnabled() (bool, error) {
|
||||
// when the second argument is a named entry rather than a colon-form path.
|
||||
//
|
||||
// Replace and Specs drive the whole-set form, where the positional arguments
|
||||
// are mount specs rather than a single entry and the remaining mount-time
|
||||
// fields scope every spec in the call.
|
||||
// are mount specs carrying their own mount-time fields. Only ProcessType
|
||||
// scopes that call; every other mount-time field is rejected with Replace so
|
||||
// each one has exactly one spelling.
|
||||
type CommandMountInput struct {
|
||||
AppName string
|
||||
NameOrPath string
|
||||
@@ -252,34 +253,6 @@ func CommandMount(input CommandMountInput) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// mountSpec is one parsed positional argument of the storage:mount --replace
|
||||
// form. It names an entry and the container path to bind it at, plus the
|
||||
// mount-time fields the colon form can express on its own.
|
||||
type mountSpec struct {
|
||||
EntryName string
|
||||
ContainerPath string
|
||||
Readonly bool
|
||||
VolumeOptions string
|
||||
}
|
||||
|
||||
// parseMountSpec splits an "<entry>:<container-dir>[:<options>]" argument.
|
||||
// ParseMountPath already implements that grammar - including hoisting the "ro"
|
||||
// token out of the options list - so the only difference here is that the first
|
||||
// field names a storage entry rather than a host path.
|
||||
func parseMountSpec(spec string) (mountSpec, error) {
|
||||
parsed := ParseMountPath(spec)
|
||||
if parsed.HostPath == "" || parsed.ContainerPath == "" {
|
||||
return mountSpec{}, fmt.Errorf("Invalid mount specified: %s", spec)
|
||||
}
|
||||
|
||||
return mountSpec{
|
||||
EntryName: parsed.HostPath,
|
||||
ContainerPath: parsed.ContainerPath,
|
||||
Readonly: parsed.Readonly,
|
||||
VolumeOptions: parsed.VolumeOptions,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// resolveMountSpecEntry maps a parsed spec onto the storage entry it names.
|
||||
//
|
||||
// The single-mount form tells a named entry from a colon-form host path by the
|
||||
@@ -329,24 +302,40 @@ func resolveMountSpecEntry(appName string, appScheduler string, spec string, par
|
||||
// spec leaves the stored set untouched. Attachments belonging to other process
|
||||
// types are kept: an omitted --process-type scopes the replacement to
|
||||
// _default_ the same way it scopes a single storage:mount.
|
||||
//
|
||||
// Every other mount-time field comes from the spec that declares it rather
|
||||
// than from a call-level flag, so one call can vary them between mounts.
|
||||
func replaceMounts(input CommandMountInput) error {
|
||||
if input.ContainerDir != "" {
|
||||
return errors.New("The --container-dir flag cannot be used with --replace")
|
||||
}
|
||||
|
||||
// Each mount-time field has exactly one spelling in this form, the token
|
||||
// in the spec that declares it, rather than a call-level default a token
|
||||
// overrides. A flag is taken as passed when it holds anything but its
|
||||
// zero value, which is what pflag leaves behind when it is absent; the
|
||||
// values that slip through - an empty string or an explicit false - ask
|
||||
// for what an omitted flag already gives.
|
||||
for _, conflict := range []struct {
|
||||
flag string
|
||||
set bool
|
||||
hint string
|
||||
}{
|
||||
{"--phase", len(input.Phases) > 0, mountSpecKeyPhase + "=" + PhaseDeploy},
|
||||
{"--volume-subpath", input.Subpath != "", mountSpecKeySubpath + "=<path>"},
|
||||
{"--volume-readonly", input.Readonly, "ro"},
|
||||
{"--volume-chown", input.VolumeChown != "", mountSpecKeyVolumeChown + "=<option>"},
|
||||
{"--volume-options", input.VolumeOptions != "", "the option as a bare token"},
|
||||
} {
|
||||
if conflict.set {
|
||||
return fmt.Errorf("The %s flag cannot be used with --replace; set %s in the mount spec instead", conflict.flag, conflict.hint)
|
||||
}
|
||||
}
|
||||
|
||||
if len(input.Specs) == 0 {
|
||||
return errors.New("Must specify at least one mount, use storage:unmount --all to remove all mounts")
|
||||
}
|
||||
|
||||
if err := ValidateChownOption(input.VolumeChown); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
phases := input.Phases
|
||||
if len(phases) == 0 {
|
||||
phases = []string{PhaseDeploy, PhaseRun}
|
||||
}
|
||||
|
||||
processType := input.ProcessType
|
||||
if processType == "" {
|
||||
processType = DefaultProcessType
|
||||
@@ -378,12 +367,12 @@ func replaceMounts(input CommandMountInput) error {
|
||||
attachment := &Attachment{
|
||||
EntryName: entry.Name,
|
||||
ContainerPath: parsed.ContainerPath,
|
||||
Phases: phases,
|
||||
Phases: parsed.Phases,
|
||||
ProcessType: processType,
|
||||
Subpath: input.Subpath,
|
||||
Readonly: input.Readonly || parsed.Readonly,
|
||||
Subpath: parsed.Subpath,
|
||||
Readonly: parsed.Readonly,
|
||||
VolumeOptions: parsed.VolumeOptions,
|
||||
VolumeChown: input.VolumeChown,
|
||||
VolumeChown: parsed.VolumeChown,
|
||||
}
|
||||
if err := attachment.Validate(); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user