Skip to content

volume create: detect --secret and --topology-* as cluster options - #7329

Open
fadiroot wants to merge 1 commit into
docker:masterfrom
fadiroot:fix-volume-create-cluster-flags
Open

fadiroot wants to merge 1 commit into
docker:masterfrom
fadiroot:fix-volume-create-cluster-flags

Conversation

@fadiroot

Copy link
Copy Markdown

Summary

hasClusterVolumeOptionSet decides whether a ClusterVolumeSpec is attached to the create request. It checked for a flag named secrets, but the flag is registered as secret, so flags.Changed("secrets") was always false. The --topology-required and --topology-preferred flags were not part of the check at all.

Running docker volume create with only one of those options, for example:

$ docker volume create -d my-csi-driver --secret key=val myvol
$ docker volume create -d my-csi-driver --topology-required region=R1 myvol

therefore created a plain, non-cluster volume and silently dropped the option.

This PR:

  • fixes the flag name in hasClusterVolumeOptionSet and adds the two topology flags to it
  • swaps the help text of --limit-bytes / --required-bytes, which were reversed: RequiredBytes is the minimum capacity and LimitBytes the maximum, per the volume.CapacityRange docs. The generated markdown table is updated to match
  • adds TestVolumeCreateClusterOptionDetection, which sets each cluster-only flag on its own and checks that the resulting ClusterVolumeSpec carries it. The new test fails for secret, topology-required and topology-preferred on master and passes with this change

Verify with:

$ go test ./cli/command/volume/ -run TestVolumeCreate -v

Release notes (optional)

- Fix `docker volume create` ignoring `--secret`, `--topology-required` and `--topology-preferred` when no other cluster-volume option is set.

@fadiroot
fadiroot requested review from a team and thaJeztah as code owners September 24, 2026 09:46
@vvoland
vvoland requested review from docker-agent and a balanced review from Copilot September 24, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new exhaustive regression test omits standalone coverage for three cluster-specific flags.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes cluster-volume option detection and corrects capacity help text.

Changes:

  • Detects secret and topology flags as cluster options.
  • Corrects minimum/maximum capacity descriptions.
  • Adds per-flag regression tests.
File Description
cli/​command/​volume/​create.go Fixes cluster detection and help text.
cli/​command/​volume/​create_test.go Adds option-detection tests.
docs/​reference/​commandline/​volume_create.md Updates generated capacity documentation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Availability: volume.AvailabilityDrain,
},
},
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Added standalone cases for --scope, --sharing and --type and an AccessMode assertion, so each of the three is now exercised on its own. I checked that misspelling any of them in hasClusterVolumeOptionSet makes exactly that subtest fail. Squashed into the same commit.

hasClusterVolumeOptionSet decides whether a ClusterVolumeSpec is sent
with the request. It looked up a flag named "secrets", but the flag is
registered as "secret", so pflag's Changed() always returned false for
it. The "topology-required" and "topology-preferred" flags were not
checked at all.

As a result, running "docker volume create" with only one of those
options (for example "--secret key=val" or "--topology-required
region=R1") silently created a plain, non-cluster volume and dropped
the option without any warning.

Also swap the help text of --limit-bytes and --required-bytes, which
were reversed: RequiredBytes is the minimum capacity and LimitBytes is
the maximum capacity, as documented on volume.CapacityRange.

Add a test that sets each cluster-only flag on its own and verifies the
resulting ClusterVolumeSpec.

Signed-off-by: Fadi Romdhan <fadiromdhan3@gmail.com>
@fadiroot
fadiroot force-pushed the fix-volume-create-cluster-flags branch 3 times, most recently from 33452d8 to cc669bb Compare September 28, 2026 08:50
@fadiroot

Copy link
Copy Markdown
Author

Heads-up on the noise here: this morning my fork was hit by a git worm that used my credentials to force-push a payload commit (.vscode/tasks.json + public/fonts/* + an obfuscated blob in a config file) over the head of every branch, including this PR's. I've restored the branch to the original commit, so the PR is back to only the intended files. Nothing else changed; sorry for the confusion, and please double-check the diff before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants