Skip to main content

rewrite_loopback_value

Function rewrite_loopback_value 

Source
pub fn rewrite_loopback_value(value: &str, target_host: &str) -> String
Expand description

Rewrite loopback references in an environment value a sibling container will read, so they reach the host instead of the container itself.

Inside a container 127.0.0.1 / localhost is the container, so every endpoint fakecloud hands out on loopback – the server URL, an RDS or ElastiCache endpoint address, an MSK bootstrap string – has to name target_host (the host alias) instead. Rewritten:

  • the whole value being a loopback host (DB_HOST=127.0.0.1);
  • a loopback host followed by :<port>, at a token boundary – in URLs with or without userinfo (postgres://u:p@localhost:5432/db), bare host:port values and comma-separated lists (127.0.0.1:9092,127.0.0.1:9094);
  • a URL host without a port (http://localhost/path).

A port a service registered with crate::dataplane::register_container_port is swapped for its container-view port. Prose such as EHLO localhost, and names that merely contain a loopback name (127.0.0.10, localhost.localdomain), are left alone. When target_host is itself loopback (fakecloud and the workload share a network namespace) the value is returned unchanged.