#!/usr/bin/env bash # T79: Pod 종료 시간은 Envoy drain(terminationDrainDuration)과 app preStop이 # 직렬(합)이 아니라 병렬(max)로 진행됨을 검증. # # NOTE (from investigation): the manifest's app image (hashicorp/http-echo:0.2.3) # has NO shell, so its `sh -c "sleep 15"` preStop hook fails INSTANTLY (does not # actually sleep 15s), and the binary does not trap SIGTERM as PID 1, so it runs # to the full terminationGracePeriodSeconds and is SIGKILLed. This means the # aggregate `total_termination_seconds` metric is confounded by TGPS, not a clean # test of the max(15,20) vs sum(15+20) hypothesis. This script still reproduces # the original spec commands AND adds per-container timestamp polling, which is # what actually demonstrates the parallel behavior (istio-proxy exits cleanly at # ~20s = terminationDrainDuration, independent of the app container which is only # killed at ~60s = terminationGracePeriodSeconds). set -euo pipefail NS="istio-vt-t79" WORKDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cleanup() { echo "[cleanup] deleting namespace ${NS}" kubectl delete namespace "${NS}" --wait=false --ignore-not-found } trap cleanup EXIT echo "[setup] creating namespace ${NS}" kubectl create namespace "${NS}" kubectl label namespace "${NS}" istio-injection=enabled echo "[setup] applying manifest.yaml" kubectl apply -f "${WORKDIR}/manifest.yaml" echo "[wait] deployment available" kubectl -n "${NS}" wait --for=condition=available deploy/paralleltiming-echo --timeout=60s echo "[wait] client pod ready" kubectl -n "${NS}" wait --for=condition=Ready pod/client --timeout=60s POD=$(kubectl -n "${NS}" get pod -l app=paralleltiming-echo -o jsonpath='{.items[0].metadata.name}') echo "POD=${POD}" # background poller: sample container state ~1/s during termination ( for _ in $(seq 1 90); do TS=$(date -u +%Y-%m-%dT%H:%M:%S.%NZ) LINE=$(kubectl -n "${NS}" get pod "${POD}" -o jsonpath='{range .status.containerStatuses[*]}{.name}={.state};{end}' 2>&1) || true if echo "${LINE}" | grep -qi "not found\|NotFound"; then echo "${TS} GONE" break fi echo "${TS} ${LINE}" sleep 1 done ) > "${WORKDIR}/poll-run.log" 2>&1 & POLLER_PID=$! T0=$(date +%s) kubectl -n "${NS}" delete pod "${POD}" --wait=true T1=$(date +%s) echo "total_termination_seconds=$((T1-T0))" wait "${POLLER_PID}" 2>/dev/null || true echo "[poll log] ${WORKDIR}/poll-run.log" tail -5 "${WORKDIR}/poll-run.log" || true echo "[done] see comments at top of this script for interpretation of the result."