Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait-for-port-listen: init, use for port forward #90

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
wait-for-port-listen: init, use for port forward
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
  • Loading branch information
katexochen committed Jan 24, 2024
commit beb10be96d4e239f26ba990ab4bc8e24e2bc45b5
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ set:
kubectl -n $ns port-forward pod/port-forwarder-coordinator 1313 &
PID=$!
trap "kill $PID" EXIT
sleep 1
nix run .#wait-for-port-listen -- 1313
t=$(date +%s)
nix run .#cli -- set \
-m ./{{ workspace_dir }}/manifest.json \
Expand All @@ -93,7 +93,7 @@ verify:
kubectl -n $ns port-forward pod/port-forwarder-coordinator 1314:1313 &
PID=$!
trap "kill $PID" EXIT
sleep 1
nix run .#wait-for-port-listen -- 1314
t=$(date +%s)
nix run .#cli -- verify \
-c localhost:1314 \
Expand Down
32 changes: 32 additions & 0 deletions packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,36 @@ rec {
pods
'';
};

wait-for-port-listen = writeShellApplication {
name = "wait-for-port-listen";
runtimeInputs = [ iproute2 ];
text = ''
port=$1

function ss-listen-on-port() {
ss \
--tcp \
--numeric \
--listening \
--no-header \
--ipv4 \
src ":$port"
}

tries=15 # 3 seconds
interval=0.2

while [[ "$tries" -gt 0 ]]; do
if [[ -n $(ss-listen-on-port) ]]; then
exit 0
fi
sleep "$interval"
tries=$((tries - 1))
done

echo "Port $port did not reach state LISTENING" >&2
exit 1
'';
};
}