Skip to content

Fix sandbox hostname resolution for sub-containers#728

Merged
phinze merged 2 commits into
mainfrom
phinze/fix-sandbox-hostname
Apr 3, 2026
Merged

Fix sandbox hostname resolution for sub-containers#728
phinze merged 2 commits into
mainfrom
phinze/fix-sandbox-hostname

Conversation

@phinze
Copy link
Copy Markdown
Contributor

@phinze phinze commented Apr 3, 2026

Sub-containers in a sandbox were getting auto-generated hostnames from containerd that didn't match anything in /etc/hosts or DNS. This went unnoticed because none of the existing addon processes (valkey, postgres, mysql) resolve their own hostname at startup. Erlang's EPMD does, and it dies immediately if it can't, which surfaced this during RabbitMQ addon work.

The sandbox architecture already shares network, IPC, and time namespaces between the pause container and sub-containers, but UTS (the namespace that holds the hostname) was missing. This meant each sub-container got a random containerd-generated hostname like 250a27c3c755 while /etc/hosts mapped a different name to 127.0.0.1.

The fix aligns with how Kubernetes pods handle this: set an explicit hostname on the pause container, share the UTS namespace to sub-containers, and make sure /etc/hosts agrees.

Test plan

  • Blackbox test suite covers the general sandbox launch path (app sandboxes, addon sandboxes)
  • Manually verified RabbitMQ addon sandbox starts successfully (previously crashed with epmd_error after ~6 seconds)

Sub-containers in a sandbox were getting auto-generated hostnames from
containerd that didn't match anything in /etc/hosts or DNS. This caused
processes like Erlang's EPMD (used by RabbitMQ) to fail immediately on
startup because they couldn't resolve their own hostname.

Three changes to align hostname handling with how Kubernetes pods work:

1. Set an explicit hostname on the pause container via oci.WithHostname
   so it gets a deterministic name derived from the sandbox ID rather
   than a random containerd container ID.

2. Share the UTS namespace from the pause container to sub-containers
   so they all see the same hostname (matching the existing pattern
   for network, IPC, and time namespaces).

3. Use the same hostname string in /etc/hosts so hostname resolution
   succeeds for processes that look themselves up.
@phinze phinze requested a review from a team as a code owner April 3, 2026 17:18
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 49012dfd-6ac3-4a36-aca3-0d7672e4afa2

📥 Commits

Reviewing files that changed from the base of the PR and between e8c0839 and fb4627b.

📒 Files selected for processing (1)
  • controllers/sandbox/sandbox_frozen_test.go
✅ Files skipped from review due to trivial changes (1)
  • controllers/sandbox/sandbox_frozen_test.go

📝 Walkthrough

Walkthrough

A helper sandboxHostname was added to derive a hostname by removing the "sandbox/" prefix from sandbox IDs. The sandbox controller now uses that trimmed hostname for host resolution and sets the pause container OCI spec hostname accordingly. Subcontainers are configured to join the UTS namespace so hostname isolation is consistent with the pause container.


Comment @coderabbitai help to get the list of available commands and usage tips.

The saga path calls BuildSpec which already includes the hostname and
UTS namespace changes, so no separate saga file changes are needed.
@phinze phinze merged commit 0bc7d2b into main Apr 3, 2026
11 checks passed
@phinze phinze deleted the phinze/fix-sandbox-hostname branch April 3, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants