Skip to content

runconfig/errors: split ErrConflictHostNetwork#49605

Merged
robmry merged 1 commit intomoby:masterfrom
br3ndonland:runconfig/errors/split-ErrConflictHostNetwork
Mar 11, 2025
Merged

runconfig/errors: split ErrConflictHostNetwork#49605
robmry merged 1 commit intomoby:masterfrom
br3ndonland:runconfig/errors/split-ErrConflictHostNetwork

Conversation

@br3ndonland
Copy link
Contributor

- What I did

Fixes #49604

Split the ErrConflictHostNetwork error into two distinct errors:

  1. ErrConflictConnectToHostNetwork when attempting to change the
    network mode of a running container from a different mode to host
  2. ErrConflictDisconnectFromHostNetwork when the network mode of a
    running container is host and attempting to disconnect from host

This commit clarifies error messaging by differentiating between the two
errors, making it clearer which operation failed and how to fix it.

- How I did it

  • Added the new errors to runconfig/errors.go.
  • Updated references to the old error in daemon/container_operations.go to point to the new errors.
  • Updated tests in integration-cli/docker_cli_network_unix_test.go to assert on the new errors.

- How to verify it

Run the updated tests in integration-cli/docker_cli_network_unix_test.go.

- Human readable description for the release notes

runconfig/errors: split `ErrConflictHostNetwork` into `ErrConflictConnectToHostNetwork` and `ErrConflictDisconnectFromHostNetwork`

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

@thaJeztah thaJeztah added status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Mar 10, 2025
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@robmry PTAL

Comment on lines -8 to +11
// ErrConflictHostNetwork conflict from being disconnected from host network or connected to host network.
ErrConflictHostNetwork validationError = "container cannot be disconnected from host network or connected to host network"
// ErrConflictConnectToHostNetwork error when attempting to connect a container to host network when not in host network mode
ErrConflictConnectToHostNetwork validationError = "cannot connect container to host network - container must be created in host network mode"
// ErrConflictDisconnectFromHostNetwork error when attempting to disconnect a container from host network when in host network mode
ErrConflictDisconnectFromHostNetwork validationError = "cannot disconnect container from host network - container was created in host network mode"
Copy link
Member

Choose a reason for hiding this comment

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

Not a problem with this pull request, but we really need to look at removing these exported errors; these errors are not used as special (sentinel) errors, and only defined out of convenience; looks like the only place they're used outside of this package is in some tests (for string-matching), which ideally would check for the errdefs type ("invalid parameter" or "conflict", depending on what applies).

I don't think this pull request makes the situation much worse though, so probably not a problem to add on/two more.

I've done a quick check to see if anyone outside our own codebase is using the ErrConflictHostNetwork error, but it doesn't appear to be, so removing that const shouldn't be a problem AFAICS; https://grep.app/search?q=.ErrConflictHostNetwork

@thaJeztah thaJeztah added area/go-sdk impact/go-sdk Noteworthy (compatibility changes) in the Go SDK labels Mar 10, 2025
@robmry
Copy link
Contributor

robmry commented Mar 10, 2025

The change looks good. I'm not sure what's going on with the tests though, haven't seen that failure in test / validate (vendor) before - but it's nothing to do with the changes here. Just re-starting didn't help, so will investigate tomorrow.

Separately, and not essential - it might be worth force-pushing a commit with a modified commit comment, dropping the Fixes ref ... just to avoid GitHub spamming the issue every time the change gets merged anywhere.

Split the `ErrConflictHostNetwork` error into two distinct errors:

1. `ErrConflictConnectToHostNetwork` when attempting to change the
   network mode of a running container from a different mode to `host`
2. `ErrConflictDisconnectFromHostNetwork` when the network mode of a
   running container is `host` and attempting to disconnect from `host`

This commit clarifies error messaging by differentiating between the two
errors, making it clearer which operation failed and how to fix it.

Signed-off-by: Brendon Smith <bws@bws.bio>
@br3ndonland
Copy link
Contributor Author

Thank you both for your feedback. Yes, would appreciate some help on the (possibly unrelated) test failures.

Separately, and not essential - it might be worth force-pushing a commit with a modified commit comment, dropping the Fixes ref ... just to avoid GitHub spamming the issue every time the change gets merged anywhere.

Good call - removed ref from Git commit message and force-pushed.

Copy link
Contributor

@robmry robmry left a comment

Choose a reason for hiding this comment

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

LGTM - thank you.

Pushing the new commit seems to have restarted enough things enough to sort out the tests. I'll go ahead and merge ...

@robmry robmry merged commit e0f3d89 into moby:master Mar 11, 2025
155 checks passed
@thaJeztah thaJeztah added this to the 28.0.2 milestone Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/go-sdk impact/changelog impact/go-sdk Noteworthy (compatibility changes) in the Go SDK kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runconfig/errors: split ErrConflictHostNetwork

4 participants