Skip to content

Conversation

@thaJeztah
Copy link
Member

See individual commits for details.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 90.90909% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
opts/mount_utils.go 87.69% 4 Missing and 4 partials ⚠️
opts/mount.go 97.05% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the mount option parsing and validation code to improve code organization and maintainability. The changes extract validation logic into a separate utility file and enhance error messages for better user experience.

Changes:

  • Extracts mount validation and helper functions to a new opts/mount_utils.go file
  • Improves error messages with better formatting (adding quotes around option names and more descriptive messages)
  • Optimizes data structures by not pre-allocating empty maps when unnecessary

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
opts/mount_utils.go New utility file containing validation functions (validateMountOptions, validateExclusiveOptions, parseBoolValue) and helper functions for ensuring mount options are initialized
opts/mount.go Refactored to use utility functions, improved whitespace validation, and enhanced error messages
opts/mount_test.go Updated test expectations to match new error messages and cleaner data structures (no empty maps)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This splits the validation code from parsing code, potentially allowing
us to either fully deferring it to the daemon, or to perform validation
separately.

For reference; daemon-side validation currently (docker 29.2.0) produces;

    docker run --rm --mount type=bind,src=/var/run,target=/foo,bind-recursive=writable alpine
    docker: Error response from daemon: mount options conflict: !ReadOnly && BindOptions.ReadOnlyNonRecursive

    docker run --rm --mount type=bind,src=/var/run,target=/foo,bind-recursive=readonly alpine
    docker: Error response from daemon: mount options conflict: !ReadOnly && BindOptions.ReadOnlyForceRecursive

Validation for BindOptions.Propagation is currently missing on the daemon;

    docker run --rm --mount type=bind,src=/var/run,target=/foo,bind-recursive=readonly,readonly alpine
    # no error

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// TODO: implicitly set propagation and error if the user specifies a propagation in a future refactor/UX polish pass
// https://github.com/docker/cli/pull/4316#discussion_r1341974730
default:
return fmt.Errorf(`invalid value for %s: %s (must be "enabled", "disabled", "writable", or "readonly")`, key, val)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Error message format is inconsistent with newly added error messages. The new validation code uses quotes around the key (e.g., "invalid value for '%s'"), but this existing error message doesn't use quotes. Consider updating to match the new format: "invalid value for '%s': %s"

Suggested change
return fmt.Errorf(`invalid value for %s: %s (must be "enabled", "disabled", "writable", or "readonly")`, key, val)
return fmt.Errorf(`invalid value for '%s': %s (must be "enabled", "disabled", "writable", or "readonly")`, key, val)

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Think I had some changes stashed to align these; probably fine for a follow-up

case "tmpfs-size":
sizeBytes, err := units.RAMInBytes(val)
if err != nil {
return fmt.Errorf("invalid value for %s: %s", key, val)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Error message format is inconsistent with newly added error messages. The new validation code uses quotes around the key (e.g., "invalid value for '%s'"), but this existing error message doesn't use quotes. Consider updating to match the new format: "invalid value for '%s': %s"

Copilot uses AI. Check for mistakes.
case "tmpfs-mode":
ui64, err := strconv.ParseUint(val, 8, 32)
if err != nil {
return fmt.Errorf("invalid value for %s: %s", key, val)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Error message format is inconsistent with newly added error messages. The new validation code uses quotes around the key (e.g., "invalid value for '%s'"), but this existing error message doesn't use quotes. Consider updating to match the new format: "invalid value for '%s': %s"

Copilot uses AI. Check for mistakes.
@thaJeztah thaJeztah requested a review from vvoland February 2, 2026 16:13
@vvoland vvoland merged commit 435384f into docker:master Feb 2, 2026
103 checks passed
@thaJeztah thaJeztah deleted the improve_mountopts branch February 2, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/volumes kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants