feat: add a whole-set form for an app's storage mounts

The `storage` plugin mounted and unmounted one attachment at a time, so matching an app's mounts to a declared set meant reading `storage:list`, computing the difference in both directions and issuing one `storage:mount` or `storage:unmount` per addition and removal, with a failure partway through leaving the app holding a mixture of the two sets.

A `--replace` flag on `storage:mount` now writes the declared set in a single call, taking `name:container-dir` pairs whose optional third field carries the same mount options the legacy colon form accepts. Every pair is parsed and validated before anything is written, so a rejected pair leaves the stored mounts untouched. The remaining mount-time flags scope the whole call the way `--process-type` already scoped a single mount, which means an omitted `--process-type` replaces the `_default_` scope and leaves mounts scoped to a named process type in place.

An empty pair list is rejected rather than treated as a request to unmount everything, so a generated list that expands to nothing cannot silently drop an app's storage. `storage:unmount --all` handles that case instead, taking an optional `--process-type` filter and treating a scope that matches nothing as a no-op so it stays idempotent.

`storage:unmount` also accepts more than one mount at a time, naming each by entry name or by the colon form, and resolves every argument against the app's attachments before removing any of them.

The help listing now carries one entry per subcommand with its flags inline rather than a row per variant, and the command listing at the top of the storage documentation matches it line for line. Folding those rows together also surfaced `--global` on `storage:report` and `storage:migrate`, neither of which both listings had mentioned.

Finally, `--volume-chown` is now validated on mount, where a typo previously exited zero and wrote a value that only the report ever read.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-20 01:06:14 -04:00
1 parent f36512a19d
commit 1d0985428a
7 files changed
+1368 -68

No files matched your search

+6 -6
View File
@@ -19,21 +19,21 @@ Additional commands:`
helpContent = `
storage:annotations:report [<name>] [<flag>], Displays annotations for one or more storage entries
storage:annotations:set <name> <key> [<value>], Set or clear an annotation on a storage entry
storage:annotations:set <name> <key> [<value>], Set or clear a single annotation on a storage entry
storage:create <name> [<path>] [flags], Register a named storage entry
storage:destroy <name> [--force] [--destroy-host-dir], Remove a named storage entry (must be unmounted from every app first)
storage:ensure-directory [--chown option] <directory>, [DEPRECATED] use storage:create instead
storage:exec <name> [-- <cmd>...], Run a command (or shell) in a temporary container that mounts the entry
storage:info <name> [--format text|json], Show details for one storage entry
storage:labels:report [<name>] [<flag>], Displays labels for one or more storage entries
storage:labels:set <name> <key> [<value>], Set or clear a label on a storage entry
storage:list <app> [--format text|json], List bind mounts for app's container(s) (host:container)
storage:labels:set <name> <key> [<value>], Set or clear a single label on a storage entry
storage:list <app> [--format text|json], List bind mounts for an app's container(s) (legacy host:container view)
storage:list-entries [--scheduler s] [--format text|json], List registered storage entries
storage:migrate [<app>|--all], Re-run the legacy -v to attachment migration for an app
storage:mount <app> <host-dir:container-dir>, Create a new bind mount
storage:report [<app>] [<flag>], Displays a storage report for one or more apps
storage:mount [--replace] <app> <host-dir:container-dir>... [flags], Create or replace bind mounts
storage:report [<app>|--global] [<flag>], Displays a storage report for one or more apps
storage:set <name> <property> [<value>], Update a storage entry in place
storage:unmount <app> <host-dir:container-dir>, Remove an existing bind mount
storage:unmount [--all] <app> [<host-dir:container-dir>...] [flags], Remove one or all bind mounts
storage:wait <name>, Wait for a storage entry's PVC to be bound (k3s)`
)
+17 -4
View File
@@ -224,10 +224,10 @@ func main() {
readonly := args.Bool("volume-readonly", false, "--volume-readonly: mount the volume read-only")
volumeChown := args.String("volume-chown", "", "--volume-chown: chown option applied at mount time")
volumeOptions := args.String("volume-options", "", "--volume-options: comma-separated mount options (e.g. Z, noexec,nosuid)")
replace := args.Bool("replace", false, "--replace: replace the entire mount set for the process type")
args.Parse(os.Args[2:])
err = storage.CommandMount(storage.CommandMountInput{
input := storage.CommandMountInput{
AppName: args.Arg(0),
NameOrPath: args.Arg(1),
ContainerDir: *containerDir,
Phases: *phases,
ProcessType: *processType,
@@ -235,7 +235,16 @@ func main() {
Readonly: *readonly,
VolumeChown: *volumeChown,
VolumeOptions: *volumeOptions,
})
Replace: *replace,
}
if *replace {
input.Specs = common.VarArgs(args.Args(), 1)
} else {
input.NameOrPath = args.Arg(1)
}
err = storage.CommandMount(input)
case "report":
args := flag.NewFlagSet("storage:report", flag.ExitOnError)
format := args.String("format", "stdout", "format: [ stdout | json ]")
@@ -251,11 +260,15 @@ func main() {
case "unmount":
args := flag.NewFlagSet("storage:unmount", flag.ExitOnError)
containerDir := args.String("container-dir", "", "--container-dir: container path (named-entry form, disambiguates duplicates)")
all := args.Bool("all", false, "--all: remove every mount for the app or the specified process type")
processType := args.String("process-type", "", "--process-type: process type to remove mounts for (requires --all)")
args.Parse(os.Args[2:])
err = storage.CommandUnmount(storage.CommandUnmountInput{
AppName: args.Arg(0),
NameOrPath: args.Arg(1),
Mounts: common.VarArgs(args.Args(), 1),
ContainerDir: *containerDir,
All: *all,
ProcessType: *processType,
})
default:
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)