feat: add host-network mode for Redis templates#259
Merged
Conversation
Add network_mode(mode) and host_network() builder methods to RedisTemplate and RedisClusterTemplate so containers can run with --network host. On the basic template, host mode skips published port mappings (Docker ignores -p when sharing the host namespace) and the Redis port is reachable directly on the host. On the cluster template, host mode: - skips creating and removing the private bridge network, - runs every node with --network host and no -p mappings, - gives each node a distinct listening port (port_base + index) so they do not collide in the shared host namespace, - skips the --cluster-announce-ip ceremony entirely (host ports are real ports), and - wires cluster create, readiness polling, role queries, and cluster info to reach nodes on 127.0.0.1 at their distinct ports. Host networking is a Linux-only Docker feature; on Docker Desktop for macOS/Windows it is a no-op. This is documented loudly in the rustdoc, and the methods do not error on non-Linux (the CLI accepts the flag regardless of backend). The Docker integration smoke test is gated to Linux via a runtime skip and the CI Docker Integration job (Ubuntu) exercises the host path. Closes #247
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds host networking mode to the Redis templates, exposing
network_mode(mode)andhost_network()builder methods on bothRedisTemplateandRedisClusterTemplate.Why
RunCommandalready supportsnetwork, but templates did not expose host mode.RedisClusterTemplatealways created its own bridge network and therefore needed the--cluster-announce-ipceremony for host-side clients. On Linux,--network hosteliminates that ceremony entirely because container ports are real host ports.How
RedisTemplate(single container):host_network()/network_mode("host")set--network host.-pwhen sharing the host namespace); the Redis port is reachable directly on the host (6379 by default).RedisClusterTemplate(multi-node):host_network()/network_mode("host")enable host mode (network_modeonly special-cases"host"; any other value keeps the default managed bridge).--network hostand no-pmappings,port_base + index) so nodes do not collide in the shared host namespace,--cluster-announce-ipceremony, andredis-cli --cluster create, node readiness polling,node_role, andcluster_infoto reach nodes on127.0.0.1at their distinct ports.RedisClusterConnection::from_templateandnode(i).host_portalready reportport_base + index, which equals the real host port in host mode, so external clients connect tolocalhost:<port_base+index>with no changes.Failure behavior on non-Linux
Host networking is a Linux-only Docker feature. On Docker Desktop for macOS/Windows the daemon runs in a Linux VM, so
--network hostbinds inside that VM and is effectively a no-op. The methods do not return an error on non-Linux (the Docker CLI accepts the flag regardless of backend); this is documented loudly in the rustdoc, and the choice (no hard error, document the no-op) is stated explicitly.Evidence / test plan
--network hostwiring + no--publish; clusteruses_host_network,node_internal_port,node_cluster_address, andbuild_ping_argsfor both bridge and host modes, including with a password.test_redis_cluster_host_network_wiring_apiasserts host-mode wiring through the public API (distinct host ports,host_portaccessor,network_mode("host")==host_network()); runs without Docker.test_redis_cluster_host_network_smoke_testis#[ignore]and gated to Linux via a runtime skip; the CI Docker Integration job (Ubuntu) exercises the Linux host path. It starts a real host-mode cluster, asserts it converges with no bridge network and no announce-ip, and cleans up.Validation gate run locally (macOS):
cargo fmt --allcargo clippy --all-targets --all-features -- -D warningscargo clippy --all-targets --no-default-features -- -D warningscargo test --lib --all-features(819 passed)cargo doc --no-deps --all-featurescargo test --doc --all-features(416 passed)Closes #247.