Add pre-flight port check before cluster creation#182
Closed
Conversation
When `obol stack up` creates a new cluster, k3d tries to bind host ports 80, 8080, 443, and 8443. If any are already in use, Docker fails with a cryptic error and rolls back the entire cluster. Add a `checkPortsAvailable()` pre-flight check that probes each required port with `net.Listen` before invoking k3d. On conflict, the error message lists the blocked port(s) and shows a `sudo lsof` command to identify the offending process.
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.
Summary
stack.Up()before callingk3d cluster createnet.Listen— if any are blocked, returns a clear error listing the conflicting port(s) and asudo lsofremediation commandPreviously, if a port was in use (e.g., nginx, Apache, another k3d cluster), Docker would fail with a cryptic error and k3d would roll back the entire cluster creation with no actionable guidance.
Test plan
go test ./internal/stack/...— all 4 new tests passgo build ./cmd/obol— compiles cleanlypython3 -c "import socket; s=socket.socket(); s.bind(('',443)); s.listen(1); input()"), runobol stack up, verify clear error messageobol stack up, verify cluster creates normally