Skip to content

runconfig: validateNetContainerMode: simplify validation#48554

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:runconfig_simplify_validateNetContainerMode
Sep 27, 2024
Merged

runconfig: validateNetContainerMode: simplify validation#48554
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:runconfig_simplify_validateNetContainerMode

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

  • use an early return if we're not using container-mode, instead of checking multiple times
  • use ConnectedContainer() method to check if a container is specified

@thaJeztah thaJeztah added status/2-code-review area/networking Networking kind/refactor PR's that refactor, or clean-up code labels Sep 26, 2024
@thaJeztah thaJeztah added this to the 28.0.0 milestone Sep 26, 2024
@thaJeztah thaJeztah self-assigned this Sep 26, 2024
@thaJeztah
Copy link
Copy Markdown
Member Author

Oh! Looks like failure is related; will need to check the test to see if the test is bad, or if we regressed;

=== Failed
=== FAIL: amd64.integration-cli TestDockerCLINetmodeSuite/TestNetHostname (0.75s)
    docker_cli_netmode_test.go:59: assertion failed: expression is false: strings.Contains(out, "invalid container format container:<name|id>")
    --- FAIL: TestDockerCLINetmodeSuite/TestNetHostname (0.75s)

@thaJeztah
Copy link
Copy Markdown
Member Author

Ah! So yeah, I guess the test is "correct" (but not something we clearly define). Basically the test validates that container (without a colon :) produces an error, so effectively container to be a reserved name for networks;

out = dockerCmdWithFail(c, "run", "--net=container", "busybox", "ps")
assert.Assert(c, strings.Contains(out, "invalid container format container:<name|id>"))

I can fix this validation, but we should probably look if IsContainer() and other utilities should treat the same; IsContainer() (and NetworkMode) does not have a IsValid() (I think), so it's possible there's risks that things are not considered a container mode network and then fall through to be considered "network named container" or vice-versa.

- use an early return if we're not using container-mode, instead
  of checking multiple times
- use ConnectedContainer() method to check if a container is specified

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the runconfig_simplify_validateNetContainerMode branch from 6b8d24c to e6488c9 Compare September 27, 2024 08:41
@thaJeztah thaJeztah merged commit 34950b5 into moby:master Sep 27, 2024
@thaJeztah thaJeztah deleted the runconfig_simplify_validateNetContainerMode branch September 27, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking Networking 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.

2 participants