|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 5 | +EXAMPLE_DIR="${ROOT_DIR}/examples/tiny-smoke" |
| 6 | +NS="${NS:-default}" |
| 7 | +IMP_NS="${IMP_NS:-imp-system}" |
| 8 | +SERVER_VM="${SERVER_VM:-tiny-server}" |
| 9 | +CLIENT_VM="${CLIENT_VM:-tiny-client}" |
| 10 | +LOCAL_AGENT_PORT="${LOCAL_AGENT_PORT:-19091}" |
| 11 | + |
| 12 | +require() { |
| 13 | + command -v "$1" >/dev/null 2>&1 || { |
| 14 | + echo "missing required command: $1" >&2 |
| 15 | + exit 1 |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +require kubectl |
| 20 | +require curl |
| 21 | + |
| 22 | +echo "[1/6] apply tiny smoke manifests" |
| 23 | +kubectl apply -f "${EXAMPLE_DIR}/impvmclass.yaml" |
| 24 | +kubectl apply -f "${EXAMPLE_DIR}/impnetwork.yaml" -n "${NS}" |
| 25 | +kubectl apply -f "${EXAMPLE_DIR}/vm-server.yaml" -n "${NS}" |
| 26 | +kubectl apply -f "${EXAMPLE_DIR}/vm-client.yaml" -n "${NS}" |
| 27 | + |
| 28 | +echo "[2/6] wait for both VMs to be Running" |
| 29 | +kubectl wait --for=jsonpath='{.status.phase}'=Running "impvm/${SERVER_VM}" -n "${NS}" --timeout=8m |
| 30 | +kubectl wait --for=jsonpath='{.status.phase}'=Running "impvm/${CLIENT_VM}" -n "${NS}" --timeout=8m |
| 31 | + |
| 32 | +SERVER_IP="$(kubectl get impvm "${SERVER_VM}" -n "${NS}" -o jsonpath='{.status.ip}')" |
| 33 | +CLIENT_NODE="$(kubectl get impvm "${CLIENT_VM}" -n "${NS}" -o jsonpath='{.spec.nodeName}')" |
| 34 | + |
| 35 | +if [[ -z "${SERVER_IP}" || -z "${CLIENT_NODE}" ]]; then |
| 36 | + echo "failed to resolve server IP or client node" >&2 |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +echo "[3/6] locate imp-agent pod on client node ${CLIENT_NODE}" |
| 41 | +AGENT_POD="$( |
| 42 | + kubectl get pods -n "${IMP_NS}" -l app.kubernetes.io/component=agent \ |
| 43 | + -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}' \ |
| 44 | + | awk -v node="${CLIENT_NODE}" '$2==node {print $1; exit}' |
| 45 | +)" |
| 46 | + |
| 47 | +if [[ -z "${AGENT_POD}" ]]; then |
| 48 | + echo "no imp-agent pod found on node ${CLIENT_NODE} in namespace ${IMP_NS}" >&2 |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +cleanup() { |
| 53 | + if [[ -n "${PF_PID:-}" ]]; then |
| 54 | + kill "${PF_PID}" >/dev/null 2>&1 || true |
| 55 | + fi |
| 56 | +} |
| 57 | +trap cleanup EXIT |
| 58 | + |
| 59 | +echo "[4/6] port-forward agent API via pod/${AGENT_POD}" |
| 60 | +kubectl -n "${IMP_NS}" port-forward "pod/${AGENT_POD}" "${LOCAL_AGENT_PORT}:9091" >/tmp/imp-tiny-smoke-portforward.log 2>&1 & |
| 61 | +PF_PID=$! |
| 62 | +sleep 2 |
| 63 | + |
| 64 | +echo "[5/6] execute connectivity check from ${CLIENT_VM} -> ${SERVER_IP}" |
| 65 | +REQ_BODY="$( |
| 66 | + cat <<EOF |
| 67 | +{"command":["/bin/sh","-lc","wget -qO- http://${SERVER_IP} | grep -qi nginx"]} |
| 68 | +EOF |
| 69 | +)" |
| 70 | +RESP="$( |
| 71 | + curl -fsS -X POST \ |
| 72 | + -H "Content-Type: application/json" \ |
| 73 | + --data "${REQ_BODY}" \ |
| 74 | + "http://127.0.0.1:${LOCAL_AGENT_PORT}/v1/exec/${NS}/${CLIENT_VM}" |
| 75 | +)" |
| 76 | + |
| 77 | +echo "${RESP}" | grep -q '"stream":"exit","code":0' || { |
| 78 | + echo "connectivity check failed; agent exec response:" >&2 |
| 79 | + echo "${RESP}" >&2 |
| 80 | + exit 1 |
| 81 | +} |
| 82 | + |
| 83 | +echo "[6/6] smoke PASS: classRef boot + VM-to-VM HTTP connectivity validated" |
0 commit comments